bullets collide with walls

This commit is contained in:
Vinzenz Schroeter 2024-04-07 19:19:11 +02:00
parent b10ccf2da8
commit 898a9cedc1
6 changed files with 50 additions and 28 deletions

View file

@ -0,0 +1,35 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using TanksServer.Models;
using TanksServer.Services;
namespace TanksServer.Helpers;
internal static class PositionHelpers
{
public static int ToPixelIndex(this PixelPosition position)
{
return position.Y * MapService.PixelsPerRow + position.X;
}
public static PixelPosition GetPixelRelative(this TilePosition position, byte subX, byte subY)
{
Debug.Assert(subX < 8);
Debug.Assert(subY < 8);
return new PixelPosition(
X: position.X * MapService.TileSize + subX,
Y: position.Y * MapService.TileSize + subY
);
}
public static PixelPosition ToPixelPosition(this FloatPosition position) => new(
X: (int)position.X % MapService.PixelsPerRow,
Y: (int)position.Y % MapService.PixelsPerRow
);
public static TilePosition ToTilePosition(this PixelPosition position) => new(
X: position.X / MapService.TileSize,
Y: position.Y / MapService.TileSize
);
}