updating movement and added a bucket, still some clean up to do on movement. TODO: if enemy becomes stuck, reclculate path.
This commit is contained in:
@@ -11,6 +11,7 @@ public partial class Map : TileMapLayer
|
||||
public Vector2I _pathTakenAtlasCoordinates = new Vector2I(4, 0);
|
||||
public List<Vector2I> _leftmostColumn, _rightmostColumn, _topRow, _bottomRow;
|
||||
public AStarGrid2D _astar = new();
|
||||
public Dictionary<Vector2I, Enemy> _addressOccupants = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -25,21 +26,35 @@ public partial class Map : TileMapLayer
|
||||
_rightmostColumn = [.. cells.Where(c => c.X == _maxX)];
|
||||
_topRow = [.. cells.Where(c => c.Y == _minY)];
|
||||
_bottomRow = [.. cells.Where(c => c.Y == _maxY)];
|
||||
|
||||
cells.ForEach(c => SetCellEnemy(c, null));
|
||||
_sizeInCells = new Vector2(_topRow.Count, _leftmostColumn.Count);
|
||||
_sizeInPixels = _sizeInCells * _cellSize;
|
||||
|
||||
SetupAstar();
|
||||
}
|
||||
|
||||
|
||||
public Vector2 GetCellPositionFromAddress(Vector2I CELL_ADDRESS)
|
||||
{
|
||||
return GlobalPosition + CELL_ADDRESS * _cellSize + _cellSize / 2;
|
||||
}
|
||||
|
||||
public Enemy GetOccupant(Vector2I CELL_TO_CHECK)
|
||||
{
|
||||
return _addressOccupants[CELL_TO_CHECK];
|
||||
}
|
||||
|
||||
public bool IsCellSolid(Vector2I CELL_TO_CHECK)
|
||||
{
|
||||
return (bool)GetCellTileData(CELL_TO_CHECK).GetCustomData(_isSolidString);
|
||||
bool hasOccupant = GetOccupant(CELL_TO_CHECK) != null;
|
||||
bool isSolid = (bool)GetCellTileData(CELL_TO_CHECK).GetCustomData(_isSolidString);
|
||||
return hasOccupant || isSolid;
|
||||
}
|
||||
|
||||
public void SetCellEnemy(Vector2I ADDRESS, Enemy ENEMY)
|
||||
{
|
||||
_addressOccupants[ADDRESS] = ENEMY;
|
||||
IsCellSolid(ADDRESS);
|
||||
}
|
||||
|
||||
public void SetupAstar()
|
||||
|
||||
Reference in New Issue
Block a user