Gave Get best path to enemy, enemy controller hands it a map
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user