summaryrefslogtreecommitdiff
path: root/hp_bar.gd
blob: 042d4673a0ed56f92ce70f55a9bb4649f7b84683 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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()
	)