a game about throwing hammers made for the github game off
Diffstat (limited to 'enemys/Enemy.gd')
-rw-r--r--enemys/Enemy.gd23
1 files changed, 23 insertions, 0 deletions
diff --git a/enemys/Enemy.gd b/enemys/Enemy.gd
new file mode 100644
index 0000000..55ce199
--- /dev/null
+++ b/enemys/Enemy.gd
@@ -0,0 +1,23 @@
+## A enemy! Kill it!
+extends Hittable
+class_name Enemy
+
+signal died
+
+## Maximum health
+@export var max_health: int = 1
+
+## Current health
+@onready var health := max_health:
+ set(value):
+ health = clamp(value, 0, max_health)
+ if health == 0:
+ died.emit() # voodoo magic makes this signal connect to die()
+ # die()
+
+func hit(damage: int) -> void:
+ health -= damage
+
+func die() -> void:
+ Utils.instance_scene_on_main(preload("res://fx/enemy_death.tscn"), global_position)
+ queue_free()