socket fixes, fix tank jumping
This commit is contained in:
parent
9620703efc
commit
b3dacbd6f6
13 changed files with 44 additions and 46 deletions
|
@ -1,9 +1,11 @@
|
|||
using System.Diagnostics;
|
||||
using TanksServer.GameLogic;
|
||||
|
||||
namespace TanksServer.Models;
|
||||
|
||||
[DebuggerDisplay("({X} | {Y})")]
|
||||
internal readonly struct FloatPosition(double x, double y)
|
||||
{
|
||||
public double X { get; } = (x + MapService.PixelsPerRow) % MapService.PixelsPerRow;
|
||||
public double Y { get; } = (y + MapService.PixelsPerColumn) % MapService.PixelsPerColumn;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
using System.Diagnostics;
|
||||
|
||||
namespace TanksServer.Models;
|
||||
|
||||
[DebuggerDisplay("{TopLeft}, {BottomRight}")]
|
||||
internal record struct PixelBounds(PixelPosition TopLeft, PixelPosition BottomRight);
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
using System.Diagnostics;
|
||||
using TanksServer.GameLogic;
|
||||
|
||||
namespace TanksServer.Models;
|
||||
|
||||
internal readonly struct PixelPosition(ushort x, ushort y)
|
||||
[DebuggerDisplay("({X} | {Y})")]
|
||||
internal readonly struct PixelPosition(int x, int y)
|
||||
{
|
||||
public ushort X { get; } = (ushort)((x + MapService.PixelsPerRow) % MapService.PixelsPerRow);
|
||||
public ushort Y { get; } = (ushort)((y + MapService.PixelsPerColumn) % MapService.PixelsPerColumn);
|
||||
}
|
||||
public int X { get; } = (x + MapService.PixelsPerRow) % MapService.PixelsPerRow;
|
||||
public int Y { get; } = (y + MapService.PixelsPerColumn) % MapService.PixelsPerColumn;
|
||||
|
||||
public void Deconstruct(out int x, out int y)
|
||||
{
|
||||
x = X;
|
||||
y = Y;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,14 @@
|
|||
using System.Diagnostics;
|
||||
using TanksServer.GameLogic;
|
||||
|
||||
namespace TanksServer.Models;
|
||||
|
||||
internal static class PositionHelpers
|
||||
{
|
||||
public static PixelPosition GetPixelRelative(this TilePosition position, byte subX, byte subY)
|
||||
{
|
||||
Debug.Assert(subX < 8);
|
||||
Debug.Assert(subY < 8);
|
||||
return new PixelPosition(
|
||||
(ushort)(position.X * MapService.TileSize + subX),
|
||||
(ushort)(position.Y * MapService.TileSize + subY)
|
||||
);
|
||||
}
|
||||
public static PixelPosition GetPixelRelative(this PixelPosition position, short subX, short subY)
|
||||
=> new(position.X + subX, position.Y + subY);
|
||||
|
||||
public static PixelPosition GetPixelRelative(this PixelPosition position, byte subX, byte subY)
|
||||
{
|
||||
Debug.Assert(subX < 8);
|
||||
Debug.Assert(subY < 8);
|
||||
return new PixelPosition((ushort)(position.X + subX), (ushort)(position.Y + subY));
|
||||
}
|
||||
|
||||
public static PixelPosition ToPixelPosition(this FloatPosition position) => new(
|
||||
(ushort)((int)position.X % MapService.PixelsPerRow),
|
||||
(ushort)((int)position.Y % MapService.PixelsPerRow)
|
||||
);
|
||||
public static PixelPosition ToPixelPosition(this FloatPosition position)
|
||||
=> new((int)position.X, (int)position.Y);
|
||||
|
||||
public static PixelPosition ToPixelPosition(this TilePosition position) => new(
|
||||
(ushort)(position.X * MapService.TileSize),
|
||||
|
|
|
@ -28,13 +28,12 @@ internal sealed class Tank(Player player, FloatPosition spawnPosition) : IMapEnt
|
|||
|
||||
public PixelBounds Bounds => GetBoundsForCenter(Position);
|
||||
|
||||
public static PixelBounds GetBoundsForCenter(FloatPosition position) => new(
|
||||
new PixelPosition(
|
||||
(ushort)(position.X - MapService.TileSize / 2d),
|
||||
(ushort)(position.Y - MapService.TileSize / 2d)
|
||||
), new PixelPosition(
|
||||
(ushort)(position.X + MapService.TileSize / 2d - 1d),
|
||||
(ushort)(position.Y + MapService.TileSize / 2d - 1d)
|
||||
)
|
||||
);
|
||||
public static PixelBounds GetBoundsForCenter(FloatPosition position)
|
||||
{
|
||||
var pixelPosition = position.ToPixelPosition();
|
||||
return new PixelBounds(
|
||||
pixelPosition.GetPixelRelative(-3, -3),
|
||||
pixelPosition.GetPixelRelative(4, 4)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
using System.Diagnostics;
|
||||
using TanksServer.GameLogic;
|
||||
|
||||
namespace TanksServer.Models;
|
||||
|
||||
[DebuggerDisplay("({X} | {Y})")]
|
||||
internal readonly struct TilePosition(ushort x, ushort y)
|
||||
{
|
||||
public ushort X { get; } = (ushort)((x + MapService.TilesPerRow) % MapService.TilesPerRow);
|
||||
public ushort Y { get; } = (ushort)((y + MapService.TilesPerColumn) % MapService.TilesPerColumn);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue