|
1234567891011121314151617181920212223242526272829 |
- extends Control
-
- export var healthBar_path : NodePath
- onready var healthBar = get_node(healthBar_path)
- export var goldText_path : NodePath
- onready var goldText = get_node(goldText_path)
-
- func _ready():
- Controller.player_infos.connect("curHp_update", self, "update_health_bar")
- Controller.player_infos.connect("gold_update", self, "update_gold_text")
- update_health_bar(Controller.player_infos.curHp)
- update_gold_text(Controller.player_infos.gold)
-
- # called when we take damage
- func update_health_bar (curHp):
- fetch_components()
- var maxHp : int = Controller.player_infos.maxHp
- healthBar.value = (100 / maxHp) * curHp
-
- # called when our gold changes
- func update_gold_text (gold):
- fetch_components()
- goldText.text = "Gold: " + str(gold)
-
- func fetch_components():
- if healthBar == null:
- healthBar = get_node("HealthBar")
- if goldText == null:
- goldText = get_node("GoldText")
|