Zombie death and damage indicators
This commit is contained in:
parent
bffb012a26
commit
b524f97e7f
14 changed files with 324 additions and 117 deletions
32
scripts/EntityHPObserver.cs
Normal file
32
scripts/EntityHPObserver.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components;
|
||||
|
||||
public partial class EntityHPObserver : Node
|
||||
{
|
||||
[Export] private float _threshold = 0.5f;
|
||||
[Export] private bool _setGreater = false;
|
||||
[Export] private Entity _observedEntity;
|
||||
[Signal] public delegate void ThresholdReachedEventHandler();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_observedEntity.OnHPChanged += OnHPChanged;
|
||||
}
|
||||
|
||||
private void OnHPChanged(float delta, Node origin)
|
||||
{
|
||||
if (_setGreater == false && _observedEntity.HP / _observedEntity.MaxHP < _threshold)
|
||||
{
|
||||
EmitSignal(SignalName.ThresholdReached);
|
||||
_observedEntity.OnHPChanged -= OnHPChanged;
|
||||
QueueFree();
|
||||
}
|
||||
else if (_setGreater && _observedEntity.HP / _observedEntity.MaxHP > _threshold)
|
||||
{
|
||||
EmitSignal(SignalName.ThresholdReached);
|
||||
_observedEntity.OnHPChanged -= OnHPChanged;
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue