diff options
Diffstat (limited to 'hp_bar.gd')
-rw-r--r-- | hp_bar.gd | 21 |
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() + ) |