Gave Get best path to enemy, enemy controller hands it a map

This commit is contained in:
2026-06-12 01:02:00 -04:00
parent a96d935ad4
commit 9f75ec525c
2 changed files with 37 additions and 37 deletions
+33
View File
@@ -53,6 +53,39 @@ public partial class Enemy : StaticBody2D
}
public virtual List<Vector2I> GetBestPath(Map MAP)
{
Vector2I goal = Vector2I.One * -1000;
goal.Y = MAP.GetFirstOpenRow();
List<Vector2I> openCells = [.. MAP._cells.Where(c => c.Y == goal.Y && !MAP._astar.IsPointSolid(c))];
List<Vector2I> testPath, bestPath = [];
int bestLength = 999999;
for (int i = 0; i < openCells.Count; i++)
{
testPath = MAP.GetPath(_address, openCells[i]);
int testLength = testPath.Count;
if (testLength < bestLength)
{
bestPath = testPath;
bestLength = testLength;
goal = openCells[i];
}
else if (testLength == bestLength)
{
if (Math.Abs(openCells[i].X - _address.X) < Math.Abs(goal.X - _address.X))
{
bestPath = testPath;
bestLength = testLength;
goal = openCells[i];
}
}
}
return bestPath;
}
public void TakeDamage(int DAMAGE, Commander ATTACKER)
{
_health -= DAMAGE;