score.gd 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. extends HBoxContainer
  2. var player_labels = {}
  3. func _process(_delta):
  4. var rocks_left = $"../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. $"../Winner".set_text("THE WINNER IS:\n" + winner_name)
  13. $"../Winner".show()
  14. 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.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
  22. l.set_text(new_player_name + "\n" + "0")
  23. l.set_h_size_flags(SIZE_EXPAND_FILL)
  24. var font = preload("res://montserrat.otf")
  25. l.set("custom_fonts/font", font)
  26. l.set("custom_font_size/font_size", 18)
  27. add_child(l)
  28. player_labels[id] = { name = new_player_name, label = l, score = 0 }
  29. func _ready():
  30. $"../Winner".hide()
  31. set_process(true)
  32. func _on_exit_game_pressed():
  33. gamestate.end_game()