Compare commits

..

2 Commits

Author SHA1 Message Date
admin e244572402 merge 2026-06-23 23:40:19 -04:00
admin 4a9143780f reverting to prior change 2026-06-23 23:28:57 -04:00
3 changed files with 62 additions and 63 deletions
+15 -19
View File
@@ -14,7 +14,7 @@ public partial class Enemy : StaticBody2D
public bool _hovered = false, _track = false, _warp = false; public bool _hovered = false, _track = false, _warp = false;
public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _priority = 1; public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _priority = 1;
public Vector2I _address = -Vector2I.One, _range = Vector2I.Up; public Vector2I _address = -Vector2I.One, _range = Vector2I.Up;
public List<Vector2I> _path = new(), _pathStored = new(); public List<Vector2I> _path = new();
public float _movement = 0; public float _movement = 0;
public EnemyController _enemyController; public EnemyController _enemyController;
@@ -43,22 +43,6 @@ public partial class Enemy : StaticBody2D
base._PhysicsProcess(delta); 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) public void Attack(PlayerController PLAYER)
{ {
PLAYER.ChangeHealth(-1, this); PLAYER.ChangeHealth(-1, this);
@@ -93,9 +77,21 @@ public partial class Enemy : StaticBody2D
return bestPath; return bestPath;
} }
public void GetRemainingStamina(EnemyController CONTROLLER) public void GetRemainingStamina(Map MAP)
{ {
_staminaRemaining = _address.Y <= CONTROLLER._playArea._map.GetFirstOpenRow() ? 0 : _staminaRemaining; _staminaRemaining = _address.Y <= MAP.GetFirstOpenRow() ? 0 : _stamina;
}
public void RemainInPlace()
{
if (_path.Count <= 0)
{
_path.Add(_address);
}
else
{
_path.Add(_path.LastOrDefault());
}
} }
public void TakeDamage(int DAMAGE, Commander ATTACKER) public void TakeDamage(int DAMAGE, Commander ATTACKER)
+46 -42
View File
@@ -54,35 +54,24 @@ public partial class EnemyController : TurnController
} }
public void EnemyAttacks() public async Task BuildAnimationTween()
{ {
List<Enemy> attackingEnemies = [.. _enemies.Where(e => e.CanAttack())]; _tweenStages.Clear();
for (int i = 0; i < attackingEnemies.Count; i++) for (int i= 0; i < _enemies.Count; i++)
{ {
Enemy enemy = attackingEnemies[i]; Enemy enemy = _enemies[i];
enemy.Attack(_playerController); await enemy.AnimateMovement(this);
enemy._staminaRemaining = Math.Max(enemy._staminaRemaining - 2, 0);
} }
_tweenStages.OrderBy(s => s.Key);
} }
public async Task BuildEnemyPaths() public async Task BuildEnemyPaths()
{ {
Map map = _playArea._map; Map map = _playArea._map;
for (int i = 0; i < _enemies.Count; i++)
{
Enemy enemy = _enemies[i];
enemy.GetRemainingStamina(this);
}
_enemies.ForEach(e => e._path.Clear()); _enemies.ForEach(e => e._path.Clear());
if (_enemies.All(e => e._staminaRemaining <= 0)) while (_enemies.Any(e => e._staminaRemaining > 0) && _enemies.Any(e => e._address.Y > map.GetFirstOpenRow()))
{
return;
}
while (_enemies.Any(e => e._staminaRemaining > 0))
{ {
for (int i = 0; i < _enemies.Count; i++) for (int i = 0; i < _enemies.Count; i++)
{ {
@@ -102,7 +91,7 @@ public partial class EnemyController : TurnController
} }
Vector2I cell = path[0]; Vector2I cell = path[0];
GD.Print(cell);
map.SetCellEnemy(cell, enemy); map.SetCellEnemy(cell, enemy);
enemy._path.Add(cell); enemy._path.Add(cell);
@@ -111,6 +100,18 @@ public partial class EnemyController : TurnController
} }
} }
public void EnemyAttacks()
{
List<Enemy> attackingEnemies = [.. _enemies.Where(e => e.CanAttack())];
for (int i = 0; i < attackingEnemies.Count; i++)
{
Enemy enemy = attackingEnemies[i];
enemy.Attack(_playerController);
enemy._staminaRemaining = Math.Max(enemy._staminaRemaining - 2, 0);
}
}
public void HandleEnemyClick(Enemy ENEMY) public void HandleEnemyClick(Enemy ENEMY)
{ {
if (ENEMY._staminaRemaining <= 0){ if (ENEMY._staminaRemaining <= 0){
@@ -139,39 +140,35 @@ public partial class EnemyController : TurnController
AddEnemies(positions); AddEnemies(positions);
} }
public void ProcessTween() public void ProcessTweenStep(int STEP = 0)
{ {
if (_tweenStages.Count <= 0)
{
return;
}
if (STEP >= _tweenStages.Count)
{
EndTurn();
return;
}
if (_tween != null) if (_tween != null)
{ {
_tween.Kill(); _tween.Kill();
} }
_tween = CreateTween(); _tween = CreateTween();
_tween.TweenInterval(0.5f); _tween.TweenInterval(0.5f);
List<float> tweenPriorities = [.. _tweenStages.Keys]; float stage = _tweenStages.Keys.ElementAt(STEP);
for (int i = 0; i < tweenPriorities.Count; i++) List<Tween> stageTweens = _tweenStages[stage];
for (int i = 0; i < stageTweens.Count; i++)
{ {
float stage = tweenPriorities[i]; Tween step = stageTweens[i];
List<Tween> stageTweens = _tweenStages[stage]; _tween.Parallel().TweenSubtween(step);
_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) _tween.TweenCallback(Callable.From(() => ProcessTweenStep(STEP + 1)));
{
Map map = _playArea._map;
for (int i= 0; i < _enemies.Count; i++)
{
Enemy enemy = _enemies[i];
enemy.AnimateMovement(this);
}
} }
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE) public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
@@ -190,13 +187,20 @@ public partial class EnemyController : TurnController
{ {
AddEnemies(1); AddEnemies(1);
for (int i = 0; i < _enemies.Count; i++)
{
_enemies[i].StartTurn();
}
SortEnemies(); SortEnemies();
EnemyAttacks(); EnemyAttacks();
await BuildEnemyPaths(); await BuildEnemyPaths();
StepEnemies(0); await BuildAnimationTween();
ProcessTweenStep();
} }
public void SetEnemy(Enemy ENEMY, Vector2I CELL) public void SetEnemy(Enemy ENEMY, Vector2I CELL)
-1
View File
@@ -10,7 +10,6 @@ public partial class TurnController : Node2D
public virtual async Task StartTurn() public virtual async Task StartTurn()
{ {
} }
public virtual void EndTurn() public virtual void EndTurn()
{ {