working some more on enemy movement, they stilldon't always want to move to the sides when they reach the front so still some more work to do. also updated the aiming a bit to clamp the arc for firing and drawing, rewrote the draw arc function
This commit is contained in:
+59
-19
@@ -35,6 +35,7 @@ public partial class EnemyController : TurnController
|
||||
newEnemy.Death += RemoveEnemy;
|
||||
|
||||
newEnemy._speed = Globals._rng.Next(2,4+1);
|
||||
newEnemy._speed = 3;
|
||||
newEnemy.Modulate = new Color(newEnemy._speed == 2 ? "#FF0000" : newEnemy._speed == 3 ? "#00FF00" : "#0000FF");
|
||||
newEnemy._enemyController = this;
|
||||
|
||||
@@ -56,33 +57,69 @@ public partial class EnemyController : TurnController
|
||||
{
|
||||
Tween tween = CreateTween();
|
||||
tween.SetParallel();
|
||||
Dictionary<Enemy, List<Vector2I>> enemyPaths = new();
|
||||
Dictionary<Enemy, int> enemyOffsets = new();
|
||||
_enemies = [.. _enemies.OrderBy(e => e._address.Y).ThenBy(e => e._address.X)];
|
||||
|
||||
for (int i = 0; i < _enemies.Count; i++)
|
||||
{
|
||||
Enemy enemy = _enemies[i];
|
||||
List<Vector2I> path = _playArea._map.GetPath(enemy._address, new Vector2I(enemy._address.X, _playArea._map._minY));
|
||||
enemyPaths[enemy] = path;
|
||||
enemyOffsets[enemy] = 0;
|
||||
Vector2I goal = new(enemy._address.X, _playArea._map._minY);
|
||||
if (Math.Abs(goal.Y - enemy._address.Y) <= enemy._visibilityRange)
|
||||
{
|
||||
// GD.Print(goal.Y, enemy._address.Y,enemy._visibilityRange);
|
||||
while(_playArea._map.IsRowFull(goal.Y))
|
||||
{
|
||||
goal.Y++;
|
||||
}
|
||||
// if (_playArea._map.GetOccupant(goal) != null)
|
||||
// {
|
||||
// goal.X = Math.Clamp(goal.X+1, _playArea._map._minX+1, _playArea._map._maxX-1);
|
||||
// }
|
||||
int loop = 0;
|
||||
while (_playArea._map.GetOccupant(goal) != null)
|
||||
{
|
||||
goal.X = Math.Clamp(enemy._address.X + ((int)MathF.Floor(loop / 2) + 1) * (loop % 2 == 0 ? 1 : -1), _playArea._map._minX, _playArea._map._maxX);
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
List<Vector2I> path = _playArea._map.GetPath(enemy._address, goal);
|
||||
enemy._path = path;
|
||||
enemy._speedRemaining = enemy._address.Y <= _playArea._map._minY ? 0 : enemy._speed;
|
||||
}
|
||||
_enemies = [.. _enemies.OrderByDescending(e => e._path.Count).ThenBy(e => e._address.Y).ThenBy(e => Math.Abs(e._address.X))];
|
||||
int maxSpeed = _enemies.Max(e => e._speedRemaining);
|
||||
|
||||
int maxSpeed = _enemies.Max(e => e._speed);
|
||||
List<Enemy> remainingEnemies = [.. _enemies];
|
||||
|
||||
for (int i = 0; i < maxSpeed; i++)
|
||||
{
|
||||
for (int j = 0; j < _enemies.Count; j++)
|
||||
for (int j = 0; j < remainingEnemies.Count; j++)
|
||||
{
|
||||
Enemy enemy = _enemies[j];
|
||||
int offset = enemyOffsets[enemy];
|
||||
if (i >= enemy._speed - offset)
|
||||
Enemy enemy = remainingEnemies[j];
|
||||
if (enemy._speedRemaining <= 0)
|
||||
{
|
||||
remainingEnemies.Remove(enemy);
|
||||
continue;
|
||||
}
|
||||
List<Vector2I> path = enemyPaths[enemy];
|
||||
Vector2I cell = path[i - offset];
|
||||
List<Vector2I> path = enemy._path;
|
||||
int pathIndex = enemy._speed - enemy._speedRemaining;
|
||||
Vector2I cell = path[pathIndex];
|
||||
Enemy obstacle = _playArea._map.GetOccupant(cell);
|
||||
if (obstacle != null)
|
||||
{
|
||||
int obstacleRemainingMoves = obstacle._speedRemaining;
|
||||
if (obstacleRemainingMoves <= 0)
|
||||
{
|
||||
_playArea._map.EvaluateSolidCells();
|
||||
List<Vector2I> newPath = _playArea._map.GetPath(enemy._address, new Vector2I(enemy._address.X, _playArea._map._minY));
|
||||
enemy._path = newPath;
|
||||
|
||||
if (_playArea._map.GetOccupant(cell) == null)
|
||||
newPath.InsertRange(0, [.. Enumerable.Repeat(newPath[0], pathIndex)]);
|
||||
|
||||
cell = enemy._path[pathIndex];
|
||||
obstacle = _playArea._map.GetOccupant(cell);
|
||||
}
|
||||
}
|
||||
|
||||
if (obstacle == null)
|
||||
{
|
||||
_playArea._map.SetCellEnemy(enemy._address, null);
|
||||
enemy._address = cell;
|
||||
@@ -96,12 +133,14 @@ public partial class EnemyController : TurnController
|
||||
tween.Parallel();
|
||||
}
|
||||
tween.TweenProperty(enemy, "global_position", _playArea._map.GetCellPositionFromAddress(enemy._address), .2f);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemyOffsets[enemy]++;
|
||||
}
|
||||
|
||||
if (enemy._address.Y <= _playArea._map._minY)
|
||||
{
|
||||
remainingEnemies.Remove(enemy);
|
||||
continue;
|
||||
}
|
||||
enemy._speedRemaining--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +150,7 @@ public partial class EnemyController : TurnController
|
||||
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
||||
{
|
||||
_enemies.Remove(ENEMY_TO_REMOVE);
|
||||
_playArea._map.SetCellEnemy(ENEMY_TO_REMOVE._address, null);
|
||||
ENEMY_TO_REMOVE.QueueFree();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user