Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

test_hud.gd 884 B

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