reposition tanks on map switch, rework map logic
This commit is contained in:
parent
3d65c81b8b
commit
97144ae3b8
13 changed files with 208 additions and 117 deletions
32
tanks-backend/TanksServer/GameLogic/Map.cs
Normal file
32
tanks-backend/TanksServer/GameLogic/Map.cs
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue