more stuff

This commit is contained in:
2026-05-13 19:30:02 +02:00
parent 2bb1acbece
commit 37f4ea3b4e
9 changed files with 148 additions and 16 deletions

View File

@@ -0,0 +1,60 @@
using System.Threading.Tasks;
using Godot;
namespace NodeWar.scripts.components;
public partial class HealthComponent : ProgressBar
{
[Export]
public Sprite2D Gfx { get; set; }
[Export]
public float Health { get; set; } = 100;
[Export]
public float MaxHealth { get; set; } = 100;
[Signal]
public delegate float HealthChangedEventHandler(float oldHealth, float newHealth);
public void TakeDamage(float damage)
{
Health -= damage;
EmitSignal(SignalName.HealthChanged, Health + damage, Health);
if (Health <= 0)
{
Die();
return;
}
if (Gfx != null)
{
var originalColor = Gfx.Modulate;
Gfx.Modulate = new Color(10, 10, 10);
GetTree().CreateTimer(0.1f).Timeout += () =>
{
Gfx.Modulate = originalColor;
};
}
}
public void Die()
{
GD.Print("I am dying!");
GetParent().QueueFree();
}
public override void _Ready()
{
Value = Health;
MaxValue = MaxHealth;
}
public override void _Process(double delta)
{
Value = Health;
}
}