You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
944 B

  1. extends Control
  2. class_name HUD
  3. export var healthBar_path : NodePath
  4. onready var healthBar = get_node(healthBar_path)
  5. export var goldText_path : NodePath
  6. onready var goldText = get_node(goldText_path)
  7. func _ready():
  8. Controller.player_infos.connect("curHp_update", self, "update_health_bar")
  9. Controller.player_infos.connect("gold_update", self, "update_gold_text")
  10. update_health_bar(Controller.player_infos.curHp)
  11. update_gold_text(Controller.player_infos.gold)
  12. # called when we take damage
  13. func update_health_bar (curHp):
  14. fetch_components()
  15. var maxHp : int = Controller.player_infos.maxHp
  16. healthBar.value = (100 / maxHp) * curHp
  17. # called when our gold changes
  18. func update_gold_text (gold):
  19. fetch_components()
  20. goldText.text = "Gold: " + str(gold)
  21. func fetch_components():
  22. if healthBar == null:
  23. healthBar = get_node("HealthBar")
  24. if goldText == null:
  25. goldText = get_node("GoldText")
  26. func _enter_tree():
  27. Controller.hud = self