summaryrefslogtreecommitdiff
path: root/hp_bar.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-09-10 18:16:15 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-09-10 18:16:15 +0200
commit3fdb011ef62249a514a8eba2556cc9f6ea5ea477 (patch)
tree3273fe2e4736f6843d1a86ae0bcf5901ffbedc86 /hp_bar.gd
parentd200edc1a73f4cb8e7595579a8914301b3248299 (diff)
next commit
Diffstat (limited to 'hp_bar.gd')
-rw-r--r--hp_bar.gd21
1 files changed, 21 insertions, 0 deletions
diff --git a/hp_bar.gd b/hp_bar.gd
new file mode 100644
index 0000000..042d467
--- /dev/null
+++ b/hp_bar.gd
@@ -0,0 +1,21 @@
+extends Control
+
+
+@onready var player = get_tree().get_first_node_in_group("player") as Player
+@onready var hp_scene = preload("res://HP.tscn")
+
+
+func _ready() -> void:
+ for child in $HBoxContainer.get_children():
+ $HBoxContainer.remove_child(child)
+
+ for n in range(player.max_hp):
+ $HBoxContainer.add_child(hp_scene.instantiate())
+
+ player.hp_changed.connect(func():
+ for n in range(player.max_hp):
+ if n < player.hp:
+ $HBoxContainer.get_child(n).set_full()
+ else:
+ $HBoxContainer.get_child(n).set_empty()
+ )