From 556f97184deb707a3b02f5d38ceae06f2ea9c230 Mon Sep 17 00:00:00 2001 From: Conor Edmonds Date: Tue, 23 Jun 2026 17:54:37 -0400 Subject: [PATCH 1/3] starting to implement the enemy performing tweens --- Enemy.cs | 34 ++++++++++++---------- EnemyController.cs | 70 ++++++++++++++++++++++------------------------ TurnController.cs | 1 + 3 files changed, 54 insertions(+), 51 deletions(-) diff --git a/Enemy.cs b/Enemy.cs index 70bfe91..46d0c5c 100644 --- a/Enemy.cs +++ b/Enemy.cs @@ -14,7 +14,7 @@ public partial class Enemy : StaticBody2D public bool _hovered = false, _track = false, _warp = false; public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _priority = 1; public Vector2I _address = -Vector2I.One, _range = Vector2I.Up; - public List _path = new(); + public List _path = new(), _pathStored = new(); public float _movement = 0; public EnemyController _enemyController; @@ -42,6 +42,22 @@ public partial class Enemy : StaticBody2D { base._PhysicsProcess(delta); } + + public void AnimateMovement(EnemyController CONTROLLER) + { + for (int i = 0; i < _path.Count; i++) + { + Tween subtween = CreateTween(); + subtween.TweenProperty(this, "global_position", CONTROLLER._playArea._map.GetCellPositionFromAddress(_path[i]), 0.25f); + float key = _priority + i/1000; + if (!CONTROLLER._tweenStages.ContainsKey(key)) + { + CONTROLLER._tweenStages[key] = new(); + } + CONTROLLER._tweenStages[key].Add(subtween); + } + + } public void Attack(PlayerController PLAYER) { @@ -77,21 +93,9 @@ public partial class Enemy : StaticBody2D return bestPath; } - public void GetRemainingStamina(Map MAP) + public void GetRemainingStamina(EnemyController CONTROLLER) { - _staminaRemaining = _address.Y <= MAP.GetFirstOpenRow() ? 0 : _stamina; - } - - public void RemainInPlace() - { - if (_path.Count <= 0) - { - _path.Add(_address); - } - else - { - _path.Add(_path.LastOrDefault()); - } + _staminaRemaining = _address.Y <= CONTROLLER._playArea._map.GetFirstOpenRow() ? 0 : _staminaRemaining; } public void TakeDamage(int DAMAGE, Commander ATTACKER) diff --git a/EnemyController.cs b/EnemyController.cs index 5098515..54c1025 100644 --- a/EnemyController.cs +++ b/EnemyController.cs @@ -11,8 +11,8 @@ public partial class EnemyController : TurnController public PackedScene _enemyScene = GD.Load("res://Enemy.tscn"); public List _enemies = new(); public PlayerController _playerController; - - public Tween _movementTween; + public Dictionary> _tweenStages = new(); + public Tween _tween; public void AddEnemies(int ENEMY_COUNT = 1) { @@ -72,7 +72,7 @@ public partial class EnemyController : TurnController for (int i = 0; i < _enemies.Count; i++) { Enemy enemy = _enemies[i]; - enemy.GetRemainingStamina(map); + enemy.GetRemainingStamina(this); } _enemies.ForEach(e => e._path.Clear()); @@ -87,15 +87,9 @@ public partial class EnemyController : TurnController for (int i = 0; i < _enemies.Count; i++) { Enemy enemy = _enemies[i]; - if (enemy._staminaRemaining <= 0) + if (enemy._staminaRemaining <= 0 || enemy._address.Y <= map.GetFirstOpenRow()) { - enemy.RemainInPlace(); - continue; - } - if (enemy._address.Y <= map.GetFirstOpenRow()) - { - enemy.RemainInPlace(); - enemy._staminaRemaining = 0; + enemy._path.Add(enemy._path.LastOrDefault(enemy._address)); continue; } @@ -103,20 +97,14 @@ public partial class EnemyController : TurnController if (path.Count == 0) { - enemy.RemainInPlace(); + enemy._path.Add(enemy._path.LastOrDefault(enemy._address)); continue; } Vector2I cell = path[0]; - if (cell.Y <= enemy._address.Y) // if path would move enemy forward - { - map.SetCellEnemy(cell, enemy); - enemy._path.Add(cell); - } - else - { - enemy.RemainInPlace(); - } + + map.SetCellEnemy(cell, enemy); + enemy._path.Add(cell); enemy._staminaRemaining--; } @@ -151,28 +139,38 @@ public partial class EnemyController : TurnController AddEnemies(positions); } + public void ProcessTween() + { + if (_tween != null) + { + _tween.Kill(); + } + _tween = CreateTween(); + _tween.TweenInterval(0.5f); + + List tweenPriorities = [.. _tweenStages.Keys]; + for (int i = 0; i < tweenPriorities.Count; i++) + { + float stage = tweenPriorities[i]; + List stageTweens = _tweenStages[stage]; + _tween.Chain().TweenSubtween(stageTweens[0]); + for (int j = 1; j < stageTweens.Count; j++) + { + Tween step = stageTweens[j]; + _tween.Parallel().TweenSubtween(step); + } + } + _tween.TweenCallback(Callable.From(() => EndTurn())); + } + public void StepEnemies(int STEP) { Map map = _playArea._map; - if (_movementTween != null) - { - _movementTween.Kill(); - } - _movementTween = CreateTween(); - _movementTween.TweenInterval(0.5f); for (int i= 0; i < _enemies.Count; i++) { Enemy enemy = _enemies[i]; - _movementTween.Parallel().TweenProperty(enemy, "global_position", map.GetCellPositionFromAddress(enemy._path[STEP]), 0.25f); - } - if (STEP < _enemies[0]._path.Count - 1) - { - _movementTween.TweenCallback(Callable.From(() => StepEnemies(STEP + 1))); - } - else - { - _movementTween.TweenCallback(Callable.From(() => EndTurn())); + enemy.AnimateMovement(this); } } diff --git a/TurnController.cs b/TurnController.cs index 9a55a7b..9adc554 100644 --- a/TurnController.cs +++ b/TurnController.cs @@ -10,6 +10,7 @@ public partial class TurnController : Node2D public virtual async Task StartTurn() { + } public virtual void EndTurn() { From 4a9143780f6df0793e2eb2fad51f254d10741317 Mon Sep 17 00:00:00 2001 From: cojoedmo Date: Tue, 23 Jun 2026 23:28:57 -0400 Subject: [PATCH 2/3] reverting to prior change --- EnemyController.cs | 154 +++++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 76 deletions(-) diff --git a/EnemyController.cs b/EnemyController.cs index 5098515..2e572d3 100644 --- a/EnemyController.cs +++ b/EnemyController.cs @@ -11,8 +11,8 @@ public partial class EnemyController : TurnController public PackedScene _enemyScene = GD.Load("res://Enemy.tscn"); public List _enemies = new(); public PlayerController _playerController; - - public Tween _movementTween; + public Dictionary> _tweenStages = new(); + public Tween _tween; public void AddEnemies(int ENEMY_COUNT = 1) { @@ -54,6 +54,52 @@ public partial class EnemyController : TurnController } + public async Task BuildAnimationTween() + { + _tweenStages.Clear(); + for (int i= 0; i < _enemies.Count; i++) + { + Enemy enemy = _enemies[i]; + await enemy.AnimateMovement(this); + } + _tweenStages.OrderBy(s => s.Key); + } + + public async Task BuildEnemyPaths() + { + Map map = _playArea._map; + + _enemies.ForEach(e => e._path.Clear()); + + while (_enemies.Any(e => e._staminaRemaining > 0) && _enemies.Any(e => e._address.Y > map.GetFirstOpenRow())) + { + for (int i = 0; i < _enemies.Count; i++) + { + Enemy enemy = _enemies[i]; + if (enemy._staminaRemaining <= 0 || enemy._address.Y <= map.GetFirstOpenRow()) + { + enemy._path.Add(enemy._path.LastOrDefault(enemy._address)); + continue; + } + + List path = enemy.GetBestPath(map); + + if (path.Count == 0) + { + enemy._path.Add(enemy._path.LastOrDefault(enemy._address)); + continue; + } + + Vector2I cell = path[0]; + GD.Print(cell); + map.SetCellEnemy(cell, enemy); + enemy._path.Add(cell); + + enemy._staminaRemaining--; + } + } + } + public void EnemyAttacks() { List attackingEnemies = [.. _enemies.Where(e => e.CanAttack())]; @@ -65,64 +111,7 @@ public partial class EnemyController : TurnController } } - public async Task BuildEnemyPaths() - { - Map map = _playArea._map; - - for (int i = 0; i < _enemies.Count; i++) - { - Enemy enemy = _enemies[i]; - enemy.GetRemainingStamina(map); - } - - _enemies.ForEach(e => e._path.Clear()); - - if (_enemies.All(e => e._staminaRemaining <= 0)) - { - return; - } - - while (_enemies.Any(e => e._staminaRemaining > 0)) - { - for (int i = 0; i < _enemies.Count; i++) - { - Enemy enemy = _enemies[i]; - if (enemy._staminaRemaining <= 0) - { - enemy.RemainInPlace(); - continue; - } - if (enemy._address.Y <= map.GetFirstOpenRow()) - { - enemy.RemainInPlace(); - enemy._staminaRemaining = 0; - continue; - } - - List path = enemy.GetBestPath(map); - - if (path.Count == 0) - { - enemy.RemainInPlace(); - continue; - } - - Vector2I cell = path[0]; - if (cell.Y <= enemy._address.Y) // if path would move enemy forward - { - map.SetCellEnemy(cell, enemy); - enemy._path.Add(cell); - } - else - { - enemy.RemainInPlace(); - } - - enemy._staminaRemaining--; - } - } - } - + public void HandleEnemyClick(Enemy ENEMY) { if (ENEMY._staminaRemaining <= 0){ @@ -151,29 +140,35 @@ public partial class EnemyController : TurnController AddEnemies(positions); } - public void StepEnemies(int STEP) + public void ProcessTweenStep(int STEP = 0) { - Map map = _playArea._map; - if (_movementTween != null) + if (_tweenStages.Count <= 0) { - _movementTween.Kill(); + return; + } + if (STEP >= _tweenStages.Count) + { + EndTurn(); + return; } - _movementTween = CreateTween(); - _movementTween.TweenInterval(0.5f); - for (int i= 0; i < _enemies.Count; i++) + if (_tween != null) { - Enemy enemy = _enemies[i]; - _movementTween.Parallel().TweenProperty(enemy, "global_position", map.GetCellPositionFromAddress(enemy._path[STEP]), 0.25f); + _tween.Kill(); } - if (STEP < _enemies[0]._path.Count - 1) + + _tween = CreateTween(); + _tween.TweenInterval(0.5f); + + float stage = _tweenStages.Keys.ElementAt(STEP); + List stageTweens = _tweenStages[stage]; + for (int i = 0; i < stageTweens.Count; i++) { - _movementTween.TweenCallback(Callable.From(() => StepEnemies(STEP + 1))); - } - else - { - _movementTween.TweenCallback(Callable.From(() => EndTurn())); + Tween step = stageTweens[i]; + _tween.Parallel().TweenSubtween(step); } + + _tween.TweenCallback(Callable.From(() => ProcessTweenStep(STEP + 1))); } public void RemoveEnemy(Enemy ENEMY_TO_REMOVE) @@ -192,13 +187,20 @@ public partial class EnemyController : TurnController { AddEnemies(1); + for (int i = 0; i < _enemies.Count; i++) + { + _enemies[i].StartTurn(); + } + SortEnemies(); EnemyAttacks(); await BuildEnemyPaths(); - StepEnemies(0); + await BuildAnimationTween(); + + ProcessTweenStep(); } public void SetEnemy(Enemy ENEMY, Vector2I CELL) From f022333c9b378e5a77d8d2727f2a9cb16dd1b8f8 Mon Sep 17 00:00:00 2001 From: cojoedmo Date: Tue, 23 Jun 2026 23:41:20 -0400 Subject: [PATCH 3/3] merge --- TurnController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TurnController.cs b/TurnController.cs index 9a55a7b..9adc554 100644 --- a/TurnController.cs +++ b/TurnController.cs @@ -10,6 +10,7 @@ public partial class TurnController : Node2D public virtual async Task StartTurn() { + } public virtual void EndTurn() {