Finishing up basic pathfinding? later down the line will want to implement warping
This commit is contained in:
@@ -11,8 +11,8 @@ public partial class Enemy : StaticBody2D
|
||||
public delegate void ClickedEventHandler(Enemy THIS);
|
||||
[Signal]
|
||||
public delegate void RightClickedEventHandler(Enemy THIS);
|
||||
public bool _hovered = false, _track = false;
|
||||
public int _damage = 1, _health = 2, _speed, _speedRemaining, _visibilityRange = 4, _hitRange;
|
||||
public bool _hovered = false, _track = false, _warp = false;
|
||||
public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _priority = 1;
|
||||
public Vector2I _address = -Vector2I.One, _range = Vector2I.Up;
|
||||
public List<Vector2I> _path = new();
|
||||
public float _movement = 0;
|
||||
@@ -48,44 +48,52 @@ public partial class Enemy : StaticBody2D
|
||||
PLAYER.ChangeHealth(-1, this);
|
||||
}
|
||||
|
||||
public bool CanAttack()
|
||||
{
|
||||
return _address.Y <= _hitRange;
|
||||
}
|
||||
|
||||
public void CounterAttack(Commander COMMANDER)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetGoals(Map MAP)
|
||||
{
|
||||
List<Vector2I> firstOpenRow = [.. MAP._cells.Where(c => c.Y == MAP.GetFirstOpenRow() && !MAP._astar.IsPointSolid(c))];
|
||||
return firstOpenRow;
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetBestPath(Map MAP)
|
||||
{
|
||||
Vector2I goal = Vector2I.One * -1000;
|
||||
List<Vector2I> goals = GetGoals(MAP);
|
||||
List<List<Vector2I>> paths = new();
|
||||
|
||||
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++)
|
||||
for (int i = 0; i < goals.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];
|
||||
}
|
||||
}
|
||||
paths.Add(MAP.GetPath(_address, goals[i]));
|
||||
}
|
||||
List<Vector2I> bestPath = paths.OrderBy(p => p.Count).ThenBy(p => p.Last().X % 2).ToList()[0];
|
||||
return bestPath;
|
||||
}
|
||||
|
||||
public void GetRemainingStamina(Map MAP)
|
||||
{
|
||||
_staminaRemaining = _address.Y <= MAP.GetFirstOpenRow() ? 0 : _stamina;
|
||||
}
|
||||
|
||||
public void RemainInPlace()
|
||||
{
|
||||
if (_path.Count <= 0)
|
||||
{
|
||||
_path.Add(_address);
|
||||
}
|
||||
else
|
||||
{
|
||||
_path.Add(_path.LastOrDefault());
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(int DAMAGE, Commander ATTACKER)
|
||||
{
|
||||
_health -= DAMAGE;
|
||||
|
||||
Reference in New Issue
Block a user