score.gd 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. remotesync 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. $"../Winner".hide()
  32. set_process(true)
  33. func _on_exit_game_pressed():
  34. gamestate.end_game()