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.

52 lines
1.3 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. find_node("sun").set_visible(config.get_value("graphics","light", false))
  11. if find_node("sun").is_visible_in_tree():
  12. find_node("sun").set_shadow(config.get_value("graphics","shadows", false))
  13. if is_network_master():
  14. route.rpc("add_road",roads_factory.START, -1)
  15. func _physics_process(delta):
  16. if is_network_master():
  17. set_player_order()
  18. check_autotrack()
  19. func set_player_order():
  20. players = get_node("players").get_children()
  21. players.sort_custom(PlayerSorter,"sort")
  22. if players.size() > 0 && players[0] != first:
  23. new_first(players[0])
  24. if players.size() > 0 && players[players.size()-1] != last:
  25. last = players[players.size()-1]
  26. func new_first(player):
  27. if first != null:
  28. first.rpc("set_first",false)
  29. first = player
  30. first.rpc("set_first",true)
  31. func check_autotrack():
  32. if first != null:
  33. if first.position.x != -1 && route.get_last_road() != null:
  34. if first.position.x == route.get_last_road().get_index():
  35. route.rpc("add_road", roads_factory.STRAIGHT, -1)
  36. class PlayerSorter:
  37. static func sort(a, b):
  38. return a.position.x > b.position.x || a.position.x == b.position.x && a.position.y > b.position.y