adding in some example pegs and their actions. organizing folders, still working on pathing for some reason it won't move sometimes, and causes the looping to break

This commit is contained in:
2026-06-26 02:36:01 -04:00
parent fc32baa071
commit 350d2bc4d1
33 changed files with 366 additions and 165 deletions
+36 -46
View File
@@ -7,59 +7,48 @@ public partial class Peg : HoverableNode
{
[Signal]
public delegate void DeathEventHandler(Peg THIS);
public bool _track = false, _warp = false;
public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _attackCost = 1;
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _visibility = 4, _movement = 0, _movementCost = 1;
public Dictionary<string, int> _priorities = new()
{
{"attack", 1000000}, // 1000000 to 1999999 reserved for attack priorities
{"ball", 1000000}, // 1000000 to 1999999 reserved for ball priorities
{"movement", 0} // 0 to 999999 reserved for movement priorities
};
public Vector2I _address = -Vector2I.One, _range = Vector2I.Up;
public List<Vector2I> _path = new();
public float _movement = 0;
public PegController _pegController;
public Sprite2D _attack;
public PegAction _action;
public override void _Ready()
{
base._Ready();
_attack = GetNode<Sprite2D>("Attack");
}
public void Attack()
public virtual void Act()
{
// _attack.Visible = true;
Tween subtween = CreateTween();
subtween.TweenProperty(_attack, "visible", true, 0.0f);
subtween.TweenProperty(_attack, "global_position", Vector2.Zero, 0.5f);
subtween.TweenCallback(Callable.From(() =>
if (_action == null)
{
_pegController._playerController.ChangeHealth(-1, this);
_attack.Position = Vector2.Zero;
_attack.Visible = false;
}));
int key = _priorities["attack"];
if (!_pegController._tweenStages.ContainsKey(key))
{
_pegController._tweenStages[key] = new();
GD.Print("NO ACTION");
return;
}
_pegController._tweenStages[key].Add(subtween);
_staminaRemaining = Math.Max(_staminaRemaining - 2, 0);
Tween subtween = _action.CreateAnimation(this);
if (!_pegController._tweenStages.ContainsKey(_action._priority))
{
_pegController._tweenStages[_action._priority] = new();
}
_pegController._tweenStages[_action._priority].Add(subtween);
_staminaRemaining = Math.Max(_staminaRemaining - _action._cost, 0);
}
public bool CanAttack()
public virtual bool CanAct()
{
return _staminaRemaining > 0 && _address.Y <= _hitRange;
return _staminaRemaining > 0 && _address.Y <= _action._range && _action._usesRemaining > 0 && _staminaRemaining <= _action._cost;
}
public bool CanMove()
public virtual bool CanMove()
{
// GD.Print(_staminaRemaining," ",_address.Y," ", CONTROLLER._playArea._map._firstOpenRow);
return _staminaRemaining > 0 && _address.Y > _pegController._playArea._map._firstOpenRow;
}
public void CounterAttack(Commander COMMANDER)
public virtual void CounterAct(Commander COMMANDER)
{
}
@@ -68,31 +57,27 @@ public partial class Peg : HoverableNode
{
Map map = _pegController._playArea._map;
List<Vector2I> goals = GetGoals();
// List<List<Vector2I>> paths = new();
Vector2I bestGoal = goals[0];
float bestCost = map._astar._EstimateCost(_address, bestGoal);
List<Vector2I> bestPath = map.GetPath(_address, goals[0]);
for (int i = 1; i < goals.Count; i++)
{
Vector2I testGoal = goals[i];
float testCost = map._astar._EstimateCost(_address, testGoal);
if (testCost < bestCost)
List<Vector2I> testPath = map.GetPath(_address, testGoal);
if (testPath.Count < bestPath.Count)
{
bestCost = testCost;
bestGoal = testGoal;
bestPath = testPath;
}
}
// List<Vector2I> bestPath = paths.Where(p => p.Count > 0).OrderBy(p => p.Count).ToList()[0];
List<Vector2I> bestPath = map.GetPath(_address, bestGoal);
return bestPath;
}
public virtual List<Vector2I> GetGoals()
{
Map map = _pegController._playArea._map;
return [.. map._cells.Where(c => c.Y == Math.Max(_address.Y - _visibilityRange, map._firstOpenRow)).Where(c => !map._astar.IsPointSolid(c))];
return [.. map._cells.Where(c => c.Y == map._firstOpenRow).Where(c => !map._astar.IsPointSolid(c))];
}
public void Move(Vector2I PATH_STEP)
public virtual void Move(Vector2I PATH_STEP)
{
_pegController._playArea._map.SetCellPeg(PATH_STEP, this);
_path.Add(PATH_STEP);
@@ -100,29 +85,34 @@ public partial class Peg : HoverableNode
Tween subtween = CreateTween();
subtween.TweenProperty(this, "global_position", _pegController._playArea._map.GetCellPositionFromAddress(PATH_STEP), 0.25f);
int key = _priorities["movement"] + _pegController._actionLoop;
GD.Print(key);
if (!_pegController._tweenStages.ContainsKey(key))
{
_pegController._tweenStages[key] = new();
}
_pegController._tweenStages[key].Add(subtween);
_staminaRemaining--;
_staminaRemaining -= _movementCost;
}
public void StartTurn()
public virtual void StartTurn()
{
_staminaRemaining = _stamina;
_action._usesRemaining = _action._usesMax;
}
public void TakeDamage(int DAMAGE, Commander ATTACKER)
public virtual void ChangeHealth(int DELTA, Commander BALLER)
{
_health -= DAMAGE;
CounterAttack(ATTACKER);
_health += DELTA;
CounterAct(BALLER);
if (_health <= 0)
{
EmitSignal(SignalName.Death, this);
}
else if (_health > _healthMax)
{
_health = _healthMax;
}
}
}