36 lines
751 B
C#
36 lines
751 B
C#
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();
|
|
}
|
|
}
|
|
}
|