2024-04-07 19:19:11 +02:00
|
|
|
using System.Diagnostics;
|
2024-04-10 19:25:45 +02:00
|
|
|
using TanksServer.GameLogic;
|
2024-04-07 19:19:11 +02:00
|
|
|
|
2024-04-10 19:25:45 +02:00
|
|
|
namespace TanksServer.Models;
|
2024-04-07 19:19:11 +02:00
|
|
|
|
|
|
|
internal static class PositionHelpers
|
|
|
|
{
|
2024-04-10 19:25:45 +02:00
|
|
|
public static int ToPixelIndex(this PixelPosition position) => position.Y * MapService.PixelsPerRow + position.X;
|
2024-04-07 19:19:11 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
);
|
2024-04-10 19:25:45 +02:00
|
|
|
}
|