Public repository for MUR pre alpha
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.

49 lines
1.1 KiB

  1. extends Spatial
  2. class_name Game
  3. var players:Array
  4. var route:Route
  5. var first:Player
  6. var last:Player
  7. const REMOVE_LAST = 2
  8. func _ready():
  9. route = get_node("route")
  10. if is_network_master():
  11. route.rpc("add_road",roads_factory.START, -1)
  12. func _physics_process(delta):
  13. if is_network_master():
  14. set_player_order()
  15. check_autotrack()
  16. func set_player_order():
  17. players = get_node("players").get_children()
  18. players.sort_custom(PlayerSorter,"sort")
  19. if players.size() > 0 && players[0] != first:
  20. new_first(players[0])
  21. if players.size() > 0 && players[players.size()-1] != last:
  22. last = players[players.size()-1]
  23. func new_first(player):
  24. if first != null:
  25. first.rpc("set_first",false)
  26. first = player
  27. first.rpc("set_first",true)
  28. func check_autotrack():
  29. if first != null:
  30. if first.position.x != -1 && route.get_last_road() != null:
  31. if first.position.x == route.get_last_road().get_index():
  32. route.rpc("add_road", roads_factory.STRAIGHT, -1)
  33. class PlayerSorter:
  34. static func sort(a, b):
  35. return a.position.x > b.position.x || a.position.x == b.position.x && a.position.y > b.position.y