broken composition and signals
This commit is contained in:
35
scenes/health/CHealth.cs
Normal file
35
scenes/health/CHealth.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scenes/health/CHealth.cs.uid
Normal file
1
scenes/health/CHealth.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bjwrpv3jpsc1e
|
||||
6
scenes/health/CHealth.tscn
Normal file
6
scenes/health/CHealth.tscn
Normal 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")
|
||||
Reference in New Issue
Block a user