23 lines
566 B
GDScript
23 lines
566 B
GDScript
extends CanvasLayer
|
|
|
|
var hearts: Array[HeartGUI] = []
|
|
|
|
func _ready() -> void:
|
|
for child in $control/HFlowContainer.get_children():
|
|
if child is HeartGUI:
|
|
hearts.append(child)
|
|
child.visible = false
|
|
|
|
func update_hp(hp: int, max_hp: int) -> void:
|
|
update_max_hp(max_hp)
|
|
for i in max_hp:
|
|
update_heart(i, hp)
|
|
|
|
func update_heart(index: int, hp: int) -> void:
|
|
hearts[index].value = clampi(hp - index * 2, 0, 2)
|
|
|
|
func update_max_hp(max_hp: int) -> void:
|
|
var heart_count: int = roundi(max_hp * 0.5)
|
|
for i in hearts.size():
|
|
hearts[i].visible = i < heart_count
|