mostly fixed movement but there's still a problem with enemies in the top left cell (0,0) being set to not solid

This commit is contained in:
2026-06-09 18:11:06 -04:00
parent e209861cb3
commit 4722cf882b
7 changed files with 114 additions and 40 deletions
+47 -9
View File
@@ -17,6 +17,7 @@ public partial class EnemyController : TurnController
{
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
newEnemy.Death += RemoveEnemy;
newEnemy.Clicked += HandleEnemyClick;
newEnemy._speed = Globals._rng.Next(2,4+1);
newEnemy.Modulate = new Color(newEnemy._speed == 2 ? "#FF0000" : newEnemy._speed == 3 ? "#00FF00" : "#0000FF");
@@ -34,6 +35,7 @@ public partial class EnemyController : TurnController
{
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
newEnemy.Death += RemoveEnemy;
newEnemy.Clicked += HandleEnemyClick;
newEnemy._speed = Globals._rng.Next(2,4+1);
newEnemy._speed = 3;
@@ -47,11 +49,6 @@ public partial class EnemyController : TurnController
}
// public List<Vector2I> GetEnemyPath(Enemy ENEMY, Vector2I PATH)
// {
// }
public Vector2I GetBestGoal(Enemy ENEMY, Vector2I GOAL)
{
Vector2I goal = GOAL;
@@ -88,6 +85,27 @@ public partial class EnemyController : TurnController
return goal;
}
public void HandleEnemyClick(Enemy ENEMY)
{
GD.Print(ENEMY._address, _playArea._map._astar.IsPointSolid(ENEMY._address));
if (ENEMY._speedRemaining <= 0){
return;
}
TileMapLayer pathLayer = _playArea.GetNode<TileMapLayer>("PathLayer");
Vector2I goal = GetBestGoal(ENEMY, new(ENEMY._address.X, Math.Max(ENEMY._address.Y - ENEMY._visibilityRange, _playArea._map._minY)));
if (ENEMY._address == Vector2I.Zero)
{
GD.Print(0,goal);
}
List<Vector2I> newPath = [.. _playArea._map.GetPath(ENEMY._address, goal)];
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(c,0,Vector2I.Down*4));
for (int i = 0; i < newPath.Count; i++)
{
pathLayer.SetCell(newPath[i],0,Vector2I.One);
}
}
public void Initiate()
{
List<Vector2I> positions = [.. _playArea.GetNode<TileMapLayer>("InitialPositions").GetUsedCells()];
@@ -105,7 +123,15 @@ public partial class EnemyController : TurnController
if (enemy._speedRemaining > 0)
{
Vector2I goal = GetBestGoal(enemy, new(enemy._address.X, Math.Max(enemy._address.Y - enemy._visibilityRange, _playArea._map._minY)));
if (enemy._address == Vector2I.Zero)
{
GD.Print(1,goal);
}
enemy._path = _playArea._map.GetPath(enemy._address, goal);
if (enemy._path.Count <= 0)
{
enemy._speedRemaining = 0;
}
}
}
@@ -127,12 +153,24 @@ public partial class EnemyController : TurnController
}
if (enemy._address.Y <= _playArea._map._minY)
{
enemy._speedRemaining = 0;
continue;
}
Vector2I goal = GetBestGoal(enemy, new(enemy._address.X, Math.Max(enemy._address.Y - enemy._visibilityRange, _playArea._map._minY)));
if (enemy._address == Vector2I.Zero)
{
GD.Print(2,goal);
}
List<Vector2I> path = _playArea._map.GetPath(enemy._address, goal);
if (path.Count == 0)
{
continue;
}
Vector2I cell = path[0];
if (enemy._address == Vector2I.Zero)
{
GD.Print(3, enemy._address);
}
_playArea._map.SetCellEnemy(cell, enemy);
enemy._path.Add(cell);
enemy._speedRemaining--;
@@ -166,7 +204,7 @@ public partial class EnemyController : TurnController
}
tween.TweenCallback(Callable.From(() => EmitSignal(SignalName.TurnDone)));
_playArea._map.HighlightCells();
_playArea.HighlightCells();
}
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
@@ -178,7 +216,7 @@ public partial class EnemyController : TurnController
public List<Enemy> SortEnemies(List<Enemy> ENEMIES)
{
return [.. ENEMIES.Where(e => e._speedRemaining > 0 && _playArea._map.GetPath(e._address, new Vector2I(e._address.X, Math.Max(e._address.Y - e._visibilityRange, _playArea._map._minY))).Count > 0).OrderByDescending(e => e._path.Count).ThenBy(e => e._address.Y).ThenBy(e => Math.Abs(e._address.X - _playArea._map._maxX / 2))];
return [.. ENEMIES.Where(e => e._speedRemaining > 0).OrderByDescending(e => e._path.Count).ThenBy(e => e._address.Y).ThenBy(e => Math.Abs(e._address.X - _playArea._map._maxX / 2))];
}
public override void StartTurn()
@@ -191,7 +229,7 @@ public partial class EnemyController : TurnController
public void SetEnemy(Enemy ENEMY, Vector2I CELL)
{
if (CELL == new Vector2I(5, 7))
if (CELL == new Vector2I(16, 14))
{
ENEMY._track = true;
}