starting to rework grid maps to be tile map layers
This commit is contained in:
@@ -7,11 +7,11 @@ public partial class Enemy : StaticBody2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void DeathEventHandler(Enemy THIS);
|
||||
public int _damage = 1, _health = 2, _speed;
|
||||
public int _damage = 1, _health = 2, _speed, _visibilityRange = 10;
|
||||
public Vector2I _range = Vector2I.Up;
|
||||
public float _movement = 0;
|
||||
public GridMarker _gridMarker;
|
||||
public Commander _commander;
|
||||
public EnemyController _enemyController;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -32,65 +32,54 @@ public partial class Enemy : StaticBody2D
|
||||
|
||||
}
|
||||
|
||||
public List<GridMarker> Pathfinding(List<GridMarker> DESTINATIONS, bool INCLUDE_SELF = false)
|
||||
public List<GridMarker> Pathfinding(GridMarker DESTINATION, bool INCLUDE_SELF = false)
|
||||
{
|
||||
PriorityQueue<GridMarker, float> queue = new();
|
||||
queue.Enqueue(_gridMarker, 0f);
|
||||
Dictionary<GridMarker, GridMarker> cameFrom = new(), best = new();
|
||||
Dictionary<GridMarker, GridMarker> cameFrom = new();
|
||||
Dictionary<GridMarker, float> costSoFar = new();
|
||||
cameFrom[_gridMarker] = null;
|
||||
costSoFar[_gridMarker] = 0f;
|
||||
GridMarker current;
|
||||
float newCost, priority;
|
||||
|
||||
for (int i = 0; i < DESTINATIONS.Count; i++)
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
GridMarker destination = DESTINATIONS[i];
|
||||
while (queue.Count > 0)
|
||||
current = queue.Dequeue();
|
||||
|
||||
if (current == DESTINATION)
|
||||
{
|
||||
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)
|
||||
{
|
||||
best = cameFrom;
|
||||
GD.Print("breaking at line 56");
|
||||
continue;
|
||||
}
|
||||
|
||||
List<GridMarker> neighbors = current.GetMarkersInRange(1.5f);
|
||||
for (int j = 0; j < neighbors.Count; j++)
|
||||
newCost = costSoFar[current] + 1;
|
||||
if (!costSoFar.TryGetValue(next, out float value) || newCost < value)
|
||||
{
|
||||
GridMarker next = neighbors[j];
|
||||
if (next._occupant != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
newCost = costSoFar[current] + 1;
|
||||
if (best.Count > 0 && newCost >= best.Count)
|
||||
{
|
||||
GD.Print("breaking at line 70");
|
||||
break;
|
||||
}
|
||||
if (!costSoFar.TryGetValue(next, out float value) || newCost < value)
|
||||
{
|
||||
costSoFar[next] = newCost;
|
||||
priority = newCost;
|
||||
queue.Enqueue(next, priority);
|
||||
cameFrom[next] = current;
|
||||
}
|
||||
costSoFar[next] = newCost;
|
||||
priority = newCost;
|
||||
queue.Enqueue(next, priority);
|
||||
cameFrom[next] = current;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GD.Print(best.Last().Value._address);
|
||||
|
||||
List<GridMarker> path = new();
|
||||
GridMarker pathMarker = best.Last().Value;
|
||||
|
||||
if (best.TryGetValue(pathMarker, out GridMarker marker))
|
||||
GridMarker pathMarker = DESTINATION;
|
||||
if (cameFrom.ContainsKey(pathMarker))
|
||||
{
|
||||
while (pathMarker != null)
|
||||
{
|
||||
path.Add(pathMarker);
|
||||
pathMarker = marker;
|
||||
pathMarker = cameFrom[pathMarker];
|
||||
}
|
||||
path.Reverse();
|
||||
if (!INCLUDE_SELF)
|
||||
@@ -98,13 +87,11 @@ public partial class Enemy : StaticBody2D
|
||||
path.Remove(_gridMarker);
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public void TakeDamage(int DAMAGE, Commander ATTACKER)
|
||||
{
|
||||
GD.Print(_health, _health - DAMAGE);
|
||||
_health -= DAMAGE;
|
||||
CounterAttack(ATTACKER);
|
||||
if (_health <= 0)
|
||||
|
||||
Reference in New Issue
Block a user