still attempting to allow enemies to handle their own animations. still a matter of improving performance and there's some issue when enemies reach rank 0?
This commit is contained in:
+50
-50
@@ -11,7 +11,7 @@ public partial class EnemyController : TurnController
|
||||
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
||||
public List<Enemy> _enemies = new();
|
||||
public PlayerController _playerController;
|
||||
public Dictionary<float, List<Tween>> _tweenStages = new();
|
||||
public Dictionary<int, List<Tween>> _tweenStages = new();
|
||||
public Tween _tween;
|
||||
|
||||
public void AddEnemies(int ENEMY_COUNT = 1)
|
||||
@@ -54,41 +54,30 @@ public partial class EnemyController : TurnController
|
||||
|
||||
}
|
||||
|
||||
public void EnemyAttacks()
|
||||
public void BuildAnimationTween()
|
||||
{
|
||||
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 async Task BuildEnemyPaths()
|
||||
{
|
||||
Map map = _playArea._map;
|
||||
|
||||
for (int i = 0; i < _enemies.Count; i++)
|
||||
_tweenStages.Clear();
|
||||
for (int i= 0; i < _enemies.Count; i++)
|
||||
{
|
||||
Enemy enemy = _enemies[i];
|
||||
enemy.GetRemainingStamina(this);
|
||||
enemy.AnimateMovement(this);
|
||||
}
|
||||
_tweenStages.OrderBy(s => s.Key);
|
||||
}
|
||||
|
||||
public void BuildEnemyPaths()
|
||||
{
|
||||
Map map = _playArea._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._address.Y <= map.GetFirstOpenRow())
|
||||
if (enemy._staminaRemaining <= 0 || enemy._address.Y <= map._firstOpenRow)
|
||||
{
|
||||
GD.Print(enemy._staminaRemaining <= 0, enemy._address.Y <= map._firstOpenRow);
|
||||
enemy._path.Add(enemy._path.LastOrDefault(enemy._address));
|
||||
continue;
|
||||
}
|
||||
@@ -100,9 +89,7 @@ public partial class EnemyController : TurnController
|
||||
enemy._path.Add(enemy._path.LastOrDefault(enemy._address));
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector2I cell = path[0];
|
||||
|
||||
map.SetCellEnemy(cell, enemy);
|
||||
enemy._path.Add(cell);
|
||||
|
||||
@@ -111,6 +98,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)
|
||||
{
|
||||
if (ENEMY._staminaRemaining <= 0){
|
||||
@@ -141,37 +140,31 @@ public partial class EnemyController : TurnController
|
||||
|
||||
public void ProcessTween()
|
||||
{
|
||||
|
||||
if (_tweenStages.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_tween != null)
|
||||
{
|
||||
_tween.Kill();
|
||||
}
|
||||
_tween = CreateTween();
|
||||
_tween.TweenInterval(0.5f);
|
||||
|
||||
List<float> tweenPriorities = [.. _tweenStages.Keys];
|
||||
for (int i = 0; i < tweenPriorities.Count; i++)
|
||||
_tween = CreateTween();
|
||||
|
||||
for (int i = 0; i < _tweenStages.Count; i++)
|
||||
{
|
||||
float stage = tweenPriorities[i];
|
||||
List<Tween> stageTweens = _tweenStages[stage];
|
||||
_tween.Chain().TweenSubtween(stageTweens[0]);
|
||||
for (int j = 1; j < stageTweens.Count; j++)
|
||||
_tween.Chain().TweenInterval(0.5f);
|
||||
List<Tween> tweenSteps = _tweenStages.Values.ElementAt(i);
|
||||
for (int j = 0; j < tweenSteps.Count; j++)
|
||||
{
|
||||
Tween step = stageTweens[j];
|
||||
Tween step = tweenSteps[j];
|
||||
_tween.Parallel().TweenSubtween(step);
|
||||
}
|
||||
}
|
||||
_tween.TweenCallback(Callable.From(() => EndTurn()));
|
||||
}
|
||||
_tween.TweenCallback(Callable.From(EndTurn));
|
||||
|
||||
public void StepEnemies(int STEP)
|
||||
{
|
||||
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)
|
||||
@@ -183,20 +176,27 @@ public partial class EnemyController : TurnController
|
||||
|
||||
public void SortEnemies()
|
||||
{
|
||||
_enemies = [.. _enemies.OrderByDescending(e => e._priority).ThenBy(e => e._address.Y).ThenBy(e => e._path.Count).ThenBy(e => Math.Abs(e._address.X - _playArea._map._maxX / 2))];
|
||||
_enemies = [.. _enemies.OrderBy(e => e._address.Y).ThenBy(e => e._path.Count).ThenBy(e => Math.Abs(e._address.X - _playArea._map._maxX / 2))];
|
||||
}
|
||||
|
||||
public override async Task StartTurn()
|
||||
public override void StartTurn()
|
||||
{
|
||||
AddEnemies(1);
|
||||
|
||||
for (int i = 0; i < _enemies.Count; i++)
|
||||
{
|
||||
_enemies[i].StartTurn();
|
||||
}
|
||||
|
||||
SortEnemies();
|
||||
|
||||
EnemyAttacks();
|
||||
|
||||
await BuildEnemyPaths();
|
||||
BuildEnemyPaths();
|
||||
|
||||
StepEnemies(0);
|
||||
BuildAnimationTween();
|
||||
|
||||
ProcessTween();
|
||||
}
|
||||
|
||||
public void SetEnemy(Enemy ENEMY, Vector2I CELL)
|
||||
|
||||
Reference in New Issue
Block a user