From 6514ce3c54067fbcc8bbe4425ecc6d7d2f20d9c5 Mon Sep 17 00:00:00 2001 From: Ivan Kuzmenko <6745157+rndtrash@users.noreply.github.com> Date: Thu, 17 Aug 2023 20:38:56 +0300 Subject: [PATCH] Make player mortal --- scripts/Player.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/Player.cs b/scripts/Player.cs index 908505d..e7a3a5e 100644 --- a/scripts/Player.cs +++ b/scripts/Player.cs @@ -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); + } }