Make player mortal

This commit is contained in:
Иван Кузьменко 2023-08-17 20:38:56 +03:00
parent 4bafa41c9d
commit 6514ce3c54

View file

@ -4,6 +4,11 @@ public partial class Player : CharacterBody2D
{
[Export] public const float Speed = 50.0f;
[Signal]
public delegate void KilledEventHandler();
public bool Alive = true;
protected AnimatedSprite2D Sprite;
public override void _Ready()
@ -47,4 +52,14 @@ public partial class Player : CharacterBody2D
Velocity = velocity;
MoveAndSlide();
}
public void Kill(Node2D killer)
{
if (!Alive)
return;
GD.Print($"Killed by {killer.Name}");
Alive = false;
EmitSignal(SignalName.Killed);
}
}