reposition tanks on map switch, rework map logic

This commit is contained in:
Vinzenz Schroeter 2024-05-03 15:47:33 +02:00 committed by RobbersDaughter
parent 3d65c81b8b
commit 97144ae3b8
13 changed files with 208 additions and 117 deletions

View file

@ -0,0 +1,32 @@
namespace TanksServer.GameLogic;
internal sealed class Map(string name, bool[,] walls)
{
public string Name => name;
public bool IsWall(int x, int y) => walls[x, y];
public bool IsWall(PixelPosition position) => walls[position.X, position.Y];
public bool IsWall(TilePosition position)
{
var pixel = position.ToPixelPosition();
for (short dx = 0; dx < MapService.TileSize; dx++)
for (short dy = 0; dy < MapService.TileSize; dy++)
{
if (IsWall(pixel.GetPixelRelative(dx, dy)))
return true;
}
return false;
}
public bool TryDestroyWallAt(PixelPosition pixel)
{
var result = walls[pixel.X, pixel.Y];
if (result)
walls[pixel.X, pixel.Y] = false;
return result;
}
}