trying out enemy animation again
This commit is contained in:
@@ -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();
|
||||
public List<Vector2I> _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)
|
||||
|
||||
+34
-35
@@ -11,7 +11,8 @@ public partial class EnemyController : TurnController
|
||||
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
||||
public List<Enemy> _enemies = new();
|
||||
public PlayerController _playerController;
|
||||
public Tween _movementTween;
|
||||
public Dictionary<float, List<Tween>> _tweenStages = new();
|
||||
public Tween _tween;
|
||||
|
||||
public void AddEnemies(int ENEMY_COUNT = 1)
|
||||
{
|
||||
@@ -71,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());
|
||||
@@ -86,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;
|
||||
}
|
||||
|
||||
@@ -102,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--;
|
||||
}
|
||||
@@ -150,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<float> tweenPriorities = [.. _tweenStages.Keys];
|
||||
for (int i = 0; i < tweenPriorities.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.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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user