a little bit of cleanup, still some edge cases but took care of the big stuff
This commit is contained in:
+7
-5
@@ -47,6 +47,11 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public List<Vector2I> GetEnemyPath(Enemy ENEMY, Vector2I PATH)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
public Vector2I GetBestGoal(Enemy ENEMY, Vector2I GOAL)
|
public Vector2I GetBestGoal(Enemy ENEMY, Vector2I GOAL)
|
||||||
{
|
{
|
||||||
Vector2I goal = GOAL;
|
Vector2I goal = GOAL;
|
||||||
@@ -96,6 +101,7 @@ public partial class EnemyController : TurnController
|
|||||||
{
|
{
|
||||||
Enemy enemy = _enemies[i];
|
Enemy enemy = _enemies[i];
|
||||||
enemy._speedRemaining = enemy._address.Y <= _playArea._map._minY ? 0 : enemy._speed;
|
enemy._speedRemaining = enemy._address.Y <= _playArea._map._minY ? 0 : enemy._speed;
|
||||||
|
|
||||||
if (enemy._speedRemaining > 0)
|
if (enemy._speedRemaining > 0)
|
||||||
{
|
{
|
||||||
Vector2I goal = GetBestGoal(enemy, new(enemy._address.X, Math.Max(enemy._address.Y - enemy._visibilityRange, _playArea._map._minY)));
|
Vector2I goal = GetBestGoal(enemy, new(enemy._address.X, Math.Max(enemy._address.Y - enemy._visibilityRange, _playArea._map._minY)));
|
||||||
@@ -127,10 +133,6 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
List<Vector2I> path = _playArea._map.GetPath(enemy._address, goal);
|
List<Vector2I> path = _playArea._map.GetPath(enemy._address, goal);
|
||||||
Vector2I cell = path[0];
|
Vector2I cell = path[0];
|
||||||
if (enemy._track)
|
|
||||||
{
|
|
||||||
GD.Print(cell, _playArea._map._astar.IsPointSolid(cell));
|
|
||||||
}
|
|
||||||
_playArea._map.SetCellEnemy(cell, enemy);
|
_playArea._map.SetCellEnemy(cell, enemy);
|
||||||
enemy._path.Add(cell);
|
enemy._path.Add(cell);
|
||||||
enemy._speedRemaining--;
|
enemy._speedRemaining--;
|
||||||
@@ -189,7 +191,7 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
public void SetEnemy(Enemy ENEMY, Vector2I CELL)
|
public void SetEnemy(Enemy ENEMY, Vector2I CELL)
|
||||||
{
|
{
|
||||||
if (CELL == new Vector2I(8, 13))
|
if (CELL == new Vector2I(5, 7))
|
||||||
{
|
{
|
||||||
ENEMY._track = true;
|
ENEMY._track = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,16 +94,10 @@ public partial class Map : TileMapLayer
|
|||||||
|
|
||||||
public bool IsCellSolid(Vector2I CELL_TO_CHECK)
|
public bool IsCellSolid(Vector2I CELL_TO_CHECK)
|
||||||
{
|
{
|
||||||
bool hasOccupant = GetOccupant(CELL_TO_CHECK) != null;
|
bool hasOccupant = HasOccupant(CELL_TO_CHECK);
|
||||||
if (hasOccupant)
|
|
||||||
{
|
|
||||||
// GD.Print(CELL_TO_CHECK, " has occupant");
|
|
||||||
}
|
|
||||||
bool isSolid = (bool)GetCellTileData(CELL_TO_CHECK).GetCustomData(_isSolidString);
|
bool isSolid = (bool)GetCellTileData(CELL_TO_CHECK).GetCustomData(_isSolidString);
|
||||||
if (isSolid)
|
|
||||||
{
|
|
||||||
// GD.Print(CELL_TO_CHECK, " is solid");
|
|
||||||
}
|
|
||||||
return hasOccupant || isSolid;
|
return hasOccupant || isSolid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +105,7 @@ public partial class Map : TileMapLayer
|
|||||||
{
|
{
|
||||||
List<Vector2I> rowCells = [.. _cells.Where(c => c.Y == ROW_TO_CHECK)];
|
List<Vector2I> rowCells = [.. _cells.Where(c => c.Y == ROW_TO_CHECK)];
|
||||||
|
|
||||||
return rowCells.All(c => GetOccupant(c) != null);
|
return rowCells.All(c => HasOccupant(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCellEnemy(Vector2I ADDRESS, Enemy ENEMY)
|
public void SetCellEnemy(Vector2I ADDRESS, Enemy ENEMY)
|
||||||
@@ -119,7 +113,6 @@ public partial class Map : TileMapLayer
|
|||||||
_addressOccupants[ENEMY._address] = null;
|
_addressOccupants[ENEMY._address] = null;
|
||||||
SetCellSolid(ENEMY._address);
|
SetCellSolid(ENEMY._address);
|
||||||
|
|
||||||
|
|
||||||
ENEMY._address = ADDRESS;
|
ENEMY._address = ADDRESS;
|
||||||
|
|
||||||
_addressOccupants[ADDRESS] = ENEMY;
|
_addressOccupants[ADDRESS] = ENEMY;
|
||||||
@@ -146,6 +139,8 @@ public partial class Map : TileMapLayer
|
|||||||
{
|
{
|
||||||
_astar.SetPointSolid(FROM, false);
|
_astar.SetPointSolid(FROM, false);
|
||||||
List<Vector2I> pathTaken = [.. _astar.GetIdPath(FROM, TO, true)];
|
List<Vector2I> pathTaken = [.. _astar.GetIdPath(FROM, TO, true)];
|
||||||
|
|
||||||
|
_astar.SetPointSolid(FROM, true);
|
||||||
// if (SHOW_PATH)
|
// if (SHOW_PATH)
|
||||||
// {
|
// {
|
||||||
// for (int i = 0; i < pathTaken.Count; i++)
|
// for (int i = 0; i < pathTaken.Count; i++)
|
||||||
|
|||||||
Reference in New Issue
Block a user