score.gd 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. extends HBoxContainer
  2. var player_labels = {}
  3. func _process(delta):
  4. var rocks_left = get_node("../rocks").get_child_count()
  5. if rocks_left == 0:
  6. var winner_name = ""
  7. var winner_score = 0
  8. for p in player_labels:
  9. if player_labels[p].score > winner_score:
  10. winner_score = player_labels[p].score
  11. winner_name = player_labels[p].name
  12. get_node("../winner").set_text("THE WINNER IS:\n" + winner_name)
  13. get_node("../winner").show()
  14. sync func increase_score(for_who):
  15. assert(for_who in player_labels)
  16. var pl = player_labels[for_who]
  17. pl.score += 1
  18. pl.label.set_text(pl.name + "\n" + str(pl.score))
  19. func add_player(id, new_player_name):
  20. var l = Label.new()
  21. l.set_align(Label.ALIGN_CENTER)
  22. l.set_text(new_player_name + "\n" + "0")
  23. l.set_h_size_flags(SIZE_EXPAND_FILL)
  24. var font = DynamicFont.new()
  25. font.set_size(18)
  26. font.set_font_data(preload("res://montserrat.otf"))
  27. l.add_font_override("font", font)
  28. add_child(l)
  29. player_labels[id] = { name = new_player_name, label = l, score = 0 }
  30. func _ready():
  31. get_node("../winner").hide()
  32. set_process(true)
  33. func _on_exit_game_pressed():
  34. gamestate.end_game()