From 113a68bda3a552092da01547495f31f6d91f9509 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 3 Apr 2022 08:19:52 +0200 Subject: [PATCH] :sparkles: Create Damageable behaviour --- src/entities/behaviours/Damageable.gd | 18 ++++++++++++++++++ src/entities/behaviours/Damageable.tscn | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 src/entities/behaviours/Damageable.gd create mode 100644 src/entities/behaviours/Damageable.tscn diff --git a/src/entities/behaviours/Damageable.gd b/src/entities/behaviours/Damageable.gd new file mode 100644 index 0000000..d7814d3 --- /dev/null +++ b/src/entities/behaviours/Damageable.gd @@ -0,0 +1,18 @@ +extends Node + + +export var health: int = 1 setget set_health, get_health +export var max_health: int = 1 + +signal health_changed(value) +signal dead + + +func set_health(value): + health = value + emit_signal("health_changed", value) + if health <= 0: + emit_signal("dead") + +func get_health(): + return health diff --git a/src/entities/behaviours/Damageable.tscn b/src/entities/behaviours/Damageable.tscn new file mode 100644 index 0000000..c7bd5c2 --- /dev/null +++ b/src/entities/behaviours/Damageable.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://src/entities/behaviours/Damageable.gd" type="Script" id=1] + +[node name="Damageable" type="Node"] +script = ExtResource( 1 )