basic healthbars for enemies

This commit is contained in:
2026-01-23 13:31:11 +01:00
parent 8b2bf3e32e
commit 4d419b9010
13 changed files with 139 additions and 18 deletions

View File

@@ -5,7 +5,7 @@ using Movementtests.interfaces;
[GlobalClass]
public partial class CHealth : Node, IHealthable
{
public event Action<IHealthable, float> HealthChanged;
public event Action<IHealthable, HealthChangedRecord> HealthChanged;
public event Action<IHealthable> HealthDepleted;
[Export]
@@ -18,15 +18,18 @@ public partial class CHealth : Node, IHealthable
CurrentHealth = RHealth.StartingHealth;
}
public void ReduceHealth(IDamageable source, DamageRecord damageRecord)
public HealthChangedRecord ReduceHealth(IDamageable source, DamageRecord damageRecord)
{
var previousHealth = CurrentHealth;
CurrentHealth -= damageRecord.Damage.DamageDealt;
HealthChanged?.Invoke(this, CurrentHealth);
var record = new HealthChangedRecord(CurrentHealth, previousHealth, RHealth.StartingHealth);
HealthChanged?.Invoke(this, record);
if (CurrentHealth <= 0)
{
CurrentHealth = 0;
HealthDepleted?.Invoke(this);
}
return record;
}
}