broken composition and signals

This commit is contained in:
2026-01-17 17:02:31 +01:00
parent 0436053c62
commit 4ccdbc0ee6
22 changed files with 302 additions and 36 deletions

35
scenes/health/CHealth.cs Normal file
View File

@@ -0,0 +1,35 @@
using Godot;
using System;
using Movementtests.interfaces;
[GlobalClass]
public partial class CHealth : Node, IHealthable
{
[Signal]
public delegate void HealthChangedEventHandler(float health);
[Signal]
public delegate void DeadEventHandler();
[Export]
public RHealth HealthResource;
public float CurrentHealth { get; set; }
public override void _Ready()
{
CurrentHealth = HealthResource.StartingHealth;
}
public void ReduceHealth(float amount)
{
CurrentHealth -= amount;
EmitSignalHealthChanged(CurrentHealth);
if (CurrentHealth <= 0)
{
CurrentHealth = 0;
GD.Print("Dead!");
EmitSignalDead();
}
}
}