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:
2026-06-24 03:00:23 -04:00
parent 8ae8ec3e58
commit 98ca292901
6 changed files with 84 additions and 86 deletions
+13 -7
View File
@@ -2,6 +2,7 @@ using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
public partial class Enemy : StaticBody2D
{
@@ -12,7 +13,12 @@ public partial class Enemy : StaticBody2D
[Signal]
public delegate void RightClickedEventHandler(Enemy THIS);
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;
public Dictionary<string, int> _priorities = new()
{
{"attack", 0}, // 0 to 999999 reserved for attacking priorities
{"movement", 1000000} // 1000000 to 1999999 reserved for movement priorities
};
public Vector2I _address = -Vector2I.One, _range = Vector2I.Up;
public List<Vector2I> _path = new(), _pathStored = new();
public float _movement = 0;
@@ -49,7 +55,8 @@ public partial class Enemy : StaticBody2D
{
Tween subtween = CreateTween();
subtween.TweenProperty(this, "global_position", CONTROLLER._playArea._map.GetCellPositionFromAddress(_path[i]), 0.25f);
float key = _priority + i/1000;
int key = _priorities["movement"] + i;
if (!CONTROLLER._tweenStages.ContainsKey(key))
{
CONTROLLER._tweenStages[key] = new();
@@ -76,8 +83,7 @@ public partial class Enemy : StaticBody2D
public virtual List<Vector2I> GetGoals(Map MAP)
{
List<Vector2I> firstOpenRow = [.. MAP._cells.Where(c => c.Y == MAP.GetFirstOpenRow() && !MAP._astar.IsPointSolid(c))];
return firstOpenRow;
return [.. MAP._cells.Where(c => c.Y == Math.Max(_address.Y - _visibilityRange, MAP._firstOpenRow)).Where(c => !MAP._astar.IsPointSolid(c))];
}
public virtual List<Vector2I> GetBestPath(Map MAP)
@@ -89,13 +95,13 @@ public partial class Enemy : StaticBody2D
{
paths.Add(MAP.GetPath(_address, goals[i]));
}
List<Vector2I> bestPath = paths.OrderBy(p => p.Count).ThenBy(p => p.Last().X % 2).ToList()[0];
List<Vector2I> bestPath = paths.Where(p => p.Count > 0).OrderBy(p => p.Count).ThenBy(p => p.Last().X % 2).ToList()[0];
return bestPath;
}
public void GetRemainingStamina(EnemyController CONTROLLER)
public void StartTurn()
{
_staminaRemaining = _address.Y <= CONTROLLER._playArea._map.GetFirstOpenRow() ? 0 : _staminaRemaining;
_staminaRemaining = _stamina;
}
public void TakeDamage(int DAMAGE, Commander ATTACKER)