finished reowrking grid maps, polished astar pathfinding, started work on aiming functions --todo: change launch speed to constant, change aim function to take into account the angle it would need to launch at to hit mouse position like in peggle, add raycasting
This commit is contained in:
@@ -8,9 +8,8 @@ public partial class Enemy : StaticBody2D
|
||||
[Signal]
|
||||
public delegate void DeathEventHandler(Enemy THIS);
|
||||
public int _damage = 1, _health = 2, _speed, _visibilityRange = 10;
|
||||
public Vector2I _range = Vector2I.Up;
|
||||
public Vector2I _address, _range = Vector2I.Up;
|
||||
public float _movement = 0;
|
||||
public GridMarker _gridMarker;
|
||||
public EnemyController _enemyController;
|
||||
|
||||
public override void _Ready()
|
||||
@@ -32,64 +31,6 @@ public partial class Enemy : StaticBody2D
|
||||
|
||||
}
|
||||
|
||||
public List<GridMarker> Pathfinding(GridMarker DESTINATION, bool INCLUDE_SELF = false)
|
||||
{
|
||||
PriorityQueue<GridMarker, float> queue = new();
|
||||
queue.Enqueue(_gridMarker, 0f);
|
||||
Dictionary<GridMarker, GridMarker> cameFrom = new();
|
||||
Dictionary<GridMarker, float> costSoFar = new();
|
||||
cameFrom[_gridMarker] = null;
|
||||
costSoFar[_gridMarker] = 0f;
|
||||
GridMarker current;
|
||||
float newCost, priority;
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
current = queue.Dequeue();
|
||||
|
||||
if (current == DESTINATION)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
List<GridMarker> neighbors = current.GetMarkersInRange(1.5f);
|
||||
for (int j = 0; j < neighbors.Count; j++)
|
||||
{
|
||||
GridMarker next = neighbors[j];
|
||||
if (next._occupant != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
newCost = costSoFar[current] + 1;
|
||||
if (!costSoFar.TryGetValue(next, out float value) || newCost < value)
|
||||
{
|
||||
costSoFar[next] = newCost;
|
||||
priority = newCost;
|
||||
queue.Enqueue(next, priority);
|
||||
cameFrom[next] = current;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<GridMarker> path = new();
|
||||
GridMarker pathMarker = DESTINATION;
|
||||
if (cameFrom.ContainsKey(pathMarker))
|
||||
{
|
||||
while (pathMarker != null)
|
||||
{
|
||||
path.Add(pathMarker);
|
||||
pathMarker = cameFrom[pathMarker];
|
||||
}
|
||||
path.Reverse();
|
||||
if (!INCLUDE_SELF)
|
||||
{
|
||||
path.Remove(_gridMarker);
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public void TakeDamage(int DAMAGE, Commander ATTACKER)
|
||||
{
|
||||
_health -= DAMAGE;
|
||||
|
||||
Reference in New Issue
Block a user