Compare commits
2 Commits
556f97184d
...
e244572402
| Author | SHA1 | Date | |
|---|---|---|---|
| e244572402 | |||
| 4a9143780f |
@@ -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<Vector2I> _path = new(), _pathStored = new();
|
||||
public List<Vector2I> _path = new();
|
||||
public float _movement = 0;
|
||||
public EnemyController _enemyController;
|
||||
|
||||
@@ -42,22 +42,6 @@ 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)
|
||||
{
|
||||
@@ -93,9 +77,21 @@ public partial class Enemy : StaticBody2D
|
||||
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)
|
||||
|
||||
+47
-43
@@ -54,35 +54,24 @@ public partial class EnemyController : TurnController
|
||||
|
||||
}
|
||||
|
||||
public void EnemyAttacks()
|
||||
public async Task BuildAnimationTween()
|
||||
{
|
||||
List<Enemy> attackingEnemies = [.. _enemies.Where(e => e.CanAttack())];
|
||||
for (int i = 0; i < attackingEnemies.Count; i++)
|
||||
_tweenStages.Clear();
|
||||
for (int i= 0; i < _enemies.Count; i++)
|
||||
{
|
||||
Enemy enemy = attackingEnemies[i];
|
||||
enemy.Attack(_playerController);
|
||||
enemy._staminaRemaining = Math.Max(enemy._staminaRemaining - 2, 0);
|
||||
Enemy enemy = _enemies[i];
|
||||
await enemy.AnimateMovement(this);
|
||||
}
|
||||
_tweenStages.OrderBy(s => s.Key);
|
||||
}
|
||||
|
||||
|
||||
public async Task BuildEnemyPaths()
|
||||
{
|
||||
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());
|
||||
|
||||
if (_enemies.All(e => e._staminaRemaining <= 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (_enemies.Any(e => e._staminaRemaining > 0))
|
||||
while (_enemies.Any(e => e._staminaRemaining > 0) && _enemies.Any(e => e._address.Y > map.GetFirstOpenRow()))
|
||||
{
|
||||
for (int i = 0; i < _enemies.Count; i++)
|
||||
{
|
||||
@@ -102,7 +91,7 @@ public partial class EnemyController : TurnController
|
||||
}
|
||||
|
||||
Vector2I cell = path[0];
|
||||
|
||||
GD.Print(cell);
|
||||
map.SetCellEnemy(cell, enemy);
|
||||
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)
|
||||
{
|
||||
if (ENEMY._staminaRemaining <= 0){
|
||||
@@ -139,39 +140,35 @@ public partial class EnemyController : TurnController
|
||||
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)
|
||||
{
|
||||
_tween.Kill();
|
||||
}
|
||||
|
||||
_tween = CreateTween();
|
||||
_tween.TweenInterval(0.5f);
|
||||
|
||||
List<float> tweenPriorities = [.. _tweenStages.Keys];
|
||||
for (int i = 0; i < tweenPriorities.Count; i++)
|
||||
float stage = _tweenStages.Keys.ElementAt(STEP);
|
||||
List<Tween> stageTweens = _tweenStages[stage];
|
||||
for (int i = 0; i < stageTweens.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 step = stageTweens[j];
|
||||
_tween.Parallel().TweenSubtween(step);
|
||||
}
|
||||
Tween step = stageTweens[i];
|
||||
_tween.Parallel().TweenSubtween(step);
|
||||
}
|
||||
_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);
|
||||
}
|
||||
_tween.TweenCallback(Callable.From(() => ProcessTweenStep(STEP + 1)));
|
||||
}
|
||||
|
||||
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
||||
@@ -190,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)
|
||||
|
||||
@@ -10,7 +10,6 @@ public partial class TurnController : Node2D
|
||||
|
||||
public virtual async Task StartTurn()
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void EndTurn()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user