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:
Binary file not shown.
|
Before Width: | Height: | Size: 735 B After Width: | Height: | Size: 3.0 KiB |
@@ -7,6 +7,8 @@ public partial class Enemy : StaticBody2D
|
|||||||
{
|
{
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void DeathEventHandler(Enemy THIS);
|
public delegate void DeathEventHandler(Enemy THIS);
|
||||||
|
[Signal]
|
||||||
|
public delegate void ClickedEventHandler(Enemy THIS);
|
||||||
public bool _hovered = false, _track = false;
|
public bool _hovered = false, _track = false;
|
||||||
public int _damage = 1, _health = 2, _speed, _speedRemaining, _visibilityRange = 4;
|
public int _damage = 1, _health = 2, _speed, _speedRemaining, _visibilityRange = 4;
|
||||||
public Vector2I _address, _range = Vector2I.Up;
|
public Vector2I _address, _range = Vector2I.Up;
|
||||||
@@ -18,6 +20,18 @@ public partial class Enemy : StaticBody2D
|
|||||||
{
|
{
|
||||||
base._Ready();
|
base._Ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
base._Process(delta);
|
||||||
|
if (_hovered)
|
||||||
|
{
|
||||||
|
if (Input.IsActionJustPressed("leftClick"))
|
||||||
|
{
|
||||||
|
EmitSignal(SignalName.Clicked, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
base._PhysicsProcess(delta);
|
base._PhysicsProcess(delta);
|
||||||
@@ -47,6 +61,6 @@ public partial class Enemy : StaticBody2D
|
|||||||
_hovered = true;
|
_hovered = true;
|
||||||
}
|
}
|
||||||
public void OnMouseExited(){
|
public void OnMouseExited(){
|
||||||
_hovered = true;
|
_hovered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-9
@@ -17,6 +17,7 @@ public partial class EnemyController : TurnController
|
|||||||
{
|
{
|
||||||
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
|
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
|
||||||
newEnemy.Death += RemoveEnemy;
|
newEnemy.Death += RemoveEnemy;
|
||||||
|
newEnemy.Clicked += HandleEnemyClick;
|
||||||
|
|
||||||
newEnemy._speed = Globals._rng.Next(2,4+1);
|
newEnemy._speed = Globals._rng.Next(2,4+1);
|
||||||
newEnemy.Modulate = new Color(newEnemy._speed == 2 ? "#FF0000" : newEnemy._speed == 3 ? "#00FF00" : "#0000FF");
|
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>();
|
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
|
||||||
newEnemy.Death += RemoveEnemy;
|
newEnemy.Death += RemoveEnemy;
|
||||||
|
newEnemy.Clicked += HandleEnemyClick;
|
||||||
|
|
||||||
newEnemy._speed = Globals._rng.Next(2,4+1);
|
newEnemy._speed = Globals._rng.Next(2,4+1);
|
||||||
newEnemy._speed = 3;
|
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)
|
public Vector2I GetBestGoal(Enemy ENEMY, Vector2I GOAL)
|
||||||
{
|
{
|
||||||
Vector2I goal = GOAL;
|
Vector2I goal = GOAL;
|
||||||
@@ -88,6 +85,27 @@ public partial class EnemyController : TurnController
|
|||||||
return goal;
|
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()
|
public void Initiate()
|
||||||
{
|
{
|
||||||
List<Vector2I> positions = [.. _playArea.GetNode<TileMapLayer>("InitialPositions").GetUsedCells()];
|
List<Vector2I> positions = [.. _playArea.GetNode<TileMapLayer>("InitialPositions").GetUsedCells()];
|
||||||
@@ -105,7 +123,15 @@ public partial class EnemyController : TurnController
|
|||||||
if (enemy._speedRemaining > 0)
|
if (enemy._speedRemaining > 0)
|
||||||
{
|
{
|
||||||
Vector2I goal = GetBestGoal(enemy, new(enemy._address.X, Math.Max(enemy._address.Y - enemy._visibilityRange, _playArea._map._minY)));
|
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);
|
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)
|
if (enemy._address.Y <= _playArea._map._minY)
|
||||||
{
|
{
|
||||||
|
enemy._speedRemaining = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Vector2I goal = GetBestGoal(enemy, new(enemy._address.X, Math.Max(enemy._address.Y - enemy._visibilityRange, _playArea._map._minY)));
|
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);
|
List<Vector2I> path = _playArea._map.GetPath(enemy._address, goal);
|
||||||
|
if (path.Count == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Vector2I cell = path[0];
|
Vector2I cell = path[0];
|
||||||
|
if (enemy._address == Vector2I.Zero)
|
||||||
|
{
|
||||||
|
GD.Print(3, enemy._address);
|
||||||
|
}
|
||||||
_playArea._map.SetCellEnemy(cell, enemy);
|
_playArea._map.SetCellEnemy(cell, enemy);
|
||||||
enemy._path.Add(cell);
|
enemy._path.Add(cell);
|
||||||
enemy._speedRemaining--;
|
enemy._speedRemaining--;
|
||||||
@@ -166,7 +204,7 @@ public partial class EnemyController : TurnController
|
|||||||
}
|
}
|
||||||
|
|
||||||
tween.TweenCallback(Callable.From(() => EmitSignal(SignalName.TurnDone)));
|
tween.TweenCallback(Callable.From(() => EmitSignal(SignalName.TurnDone)));
|
||||||
_playArea._map.HighlightCells();
|
_playArea.HighlightCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
||||||
@@ -178,7 +216,7 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
public List<Enemy> SortEnemies(List<Enemy> ENEMIES)
|
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()
|
public override void StartTurn()
|
||||||
@@ -191,7 +229,7 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
public void SetEnemy(Enemy ENEMY, Vector2I CELL)
|
public void SetEnemy(Enemy ENEMY, Vector2I CELL)
|
||||||
{
|
{
|
||||||
if (CELL == new Vector2I(5, 7))
|
if (CELL == new Vector2I(16, 14))
|
||||||
{
|
{
|
||||||
ENEMY._track = true;
|
ENEMY._track = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,25 +73,6 @@ public partial class Map : TileMapLayer
|
|||||||
return GetOccupant(CELL_TO_CHECK) != null;
|
return GetOccupant(CELL_TO_CHECK) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HighlightCells()
|
|
||||||
{
|
|
||||||
_cells.ForEach(c =>
|
|
||||||
{
|
|
||||||
if (HasOccupant(c))
|
|
||||||
{
|
|
||||||
SetCell(c, 0, new Vector2I(4,1));
|
|
||||||
}
|
|
||||||
else if (_astar.IsPointSolid(c))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetCell(c, 0, new Vector2I(0, (c.X + c.Y) % 2 == 0 ? 0 : 1));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsCellSolid(Vector2I CELL_TO_CHECK)
|
public bool IsCellSolid(Vector2I CELL_TO_CHECK)
|
||||||
{
|
{
|
||||||
bool hasOccupant = HasOccupant(CELL_TO_CHECK);
|
bool hasOccupant = HasOccupant(CELL_TO_CHECK);
|
||||||
@@ -105,7 +86,7 @@ public partial class Map : TileMapLayer
|
|||||||
{
|
{
|
||||||
List<Vector2I> rowCells = [.. _cells.Where(c => c.Y == ROW_TO_CHECK)];
|
List<Vector2I> rowCells = [.. _cells.Where(c => c.Y == ROW_TO_CHECK)];
|
||||||
|
|
||||||
return rowCells.All(c => HasOccupant(c));
|
return rowCells.All(c => _astar.IsPointSolid(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCellEnemy(Vector2I ADDRESS, Enemy ENEMY)
|
public void SetCellEnemy(Vector2I ADDRESS, Enemy ENEMY)
|
||||||
@@ -135,20 +116,28 @@ public partial class Map : TileMapLayer
|
|||||||
EvaluateSolidCells();
|
EvaluateSolidCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Vector2I> GetPath(Vector2I FROM, Vector2I TO, bool INCLUDE_FROM = false, bool SHOW_PATH = false)
|
public List<Vector2I> GetPath(Vector2I FROM, Vector2I TO, bool INCLUDE_FROM = false)
|
||||||
{
|
{
|
||||||
_astar.SetPointSolid(FROM, false);
|
_astar.SetPointSolid(FROM, false);
|
||||||
|
if (FROM == Vector2I.Zero)
|
||||||
|
{
|
||||||
|
GD.Print(4,_astar.IsPointSolid(FROM));
|
||||||
|
}
|
||||||
|
if (TO == Vector2I.Zero)
|
||||||
|
{
|
||||||
|
GD.Print(5,_astar.IsPointSolid(FROM));
|
||||||
|
}
|
||||||
List<Vector2I> pathTaken = [.. _astar.GetIdPath(FROM, TO, true)];
|
List<Vector2I> pathTaken = [.. _astar.GetIdPath(FROM, TO, true)];
|
||||||
|
|
||||||
_astar.SetPointSolid(FROM, true);
|
_astar.SetPointSolid(FROM, true);
|
||||||
// if (SHOW_PATH)
|
if (FROM == Vector2I.Zero)
|
||||||
// {
|
{
|
||||||
// for (int i = 0; i < pathTaken.Count; i++)
|
GD.Print(6,_astar.IsPointSolid(FROM));
|
||||||
// {
|
}
|
||||||
// Vector2I cell = pathTaken[i];
|
if (TO == Vector2I.Zero)
|
||||||
// SetCell(cell, _mainSource, _pathTakenAtlasCoordinates);
|
{
|
||||||
// }
|
GD.Print(7,_astar.IsPointSolid(FROM));
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (!INCLUDE_FROM)
|
if (!INCLUDE_FROM)
|
||||||
{
|
{
|
||||||
pathTaken.Remove(FROM);
|
pathTaken.Remove(FROM);
|
||||||
|
|||||||
+20
@@ -30,4 +30,24 @@ public partial class PlayArea : Node2D
|
|||||||
_bucket.Move();
|
_bucket.Move();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void HighlightCells()
|
||||||
|
{
|
||||||
|
TileMapLayer occupiedSpaces = GetNode<TileMapLayer>("OccupiedSpaces");
|
||||||
|
_map._cells.ForEach(c =>
|
||||||
|
{
|
||||||
|
if (_map.HasOccupant(c))
|
||||||
|
{
|
||||||
|
occupiedSpaces.SetCell(c, 0, new Vector2I(4,0));
|
||||||
|
}
|
||||||
|
else if (_map._astar.IsPointSolid(c))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
occupiedSpaces.SetCell(c, 0, Vector2I.Down*4);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ bounce = 0.5
|
|||||||
radius = 12.5
|
radius = 12.5
|
||||||
|
|
||||||
[node name="Enemy" type="StaticBody2D" unique_id=1417697759]
|
[node name="Enemy" type="StaticBody2D" unique_id=1417697759]
|
||||||
|
input_pickable = true
|
||||||
physics_material_override = SubResource("PhysicsMaterial_7k104")
|
physics_material_override = SubResource("PhysicsMaterial_7k104")
|
||||||
script = ExtResource("1_4gyqm")
|
script = ExtResource("1_4gyqm")
|
||||||
|
|
||||||
@@ -19,3 +20,6 @@ shape = SubResource("CircleShape2D_4gyqm")
|
|||||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605]
|
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605]
|
||||||
scale = Vector2(0.5, 0.5)
|
scale = Vector2(0.5, 0.5)
|
||||||
texture = ExtResource("1_7k104")
|
texture = ExtResource("1_7k104")
|
||||||
|
|
||||||
|
[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"]
|
||||||
|
[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user