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();
}
}
}

View File

@@ -0,0 +1 @@
uid://bjwrpv3jpsc1e

View File

@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://c4ikbhojckpnc"]
[ext_resource type="Script" uid="uid://bjwrpv3jpsc1e" path="res://scenes/health/CHealth.cs" id="1_75uyt"]
[node name="CHealth" type="Node"]
script = ExtResource("1_75uyt")