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.

64 lines
1.6 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.set_road(roads_factory.START, -1)
  15. route.rpc("set_road",roads_factory.START, -1)
  16. func _physics_process(delta):
  17. if is_network_master():
  18. set_player_order()
  19. check_autotrack()
  20. func get_player(player_id:String):
  21. if get_node("players") != null && get_node("players").has_node(player_id):
  22. return get_node("players").get_node(player_id)
  23. return null
  24. func get_player_by_network_id(network_id:int):
  25. return get_player(str(network_id))
  26. func set_player_order():
  27. players = get_node("players").get_children()
  28. players.sort_custom(PlayerSorter,"sort")
  29. if players.size() > 0 && players[0] != first:
  30. new_first(players[0])
  31. if players.size() > 0 && players[players.size()-1] != last:
  32. last = players[players.size()-1]
  33. func new_first(player):
  34. if first != null:
  35. first.rpc("set_first",false)
  36. first = player
  37. first.rpc("set_first",true)
  38. func check_autotrack():
  39. if first != null:
  40. if first.position.x != -1 && route.get_last_road() != null:
  41. if first.position.x == route.get_last_road().get_index():
  42. route.set_road(roads_factory.STRAIGHT, -1)
  43. route.rpc("set_road", roads_factory.STRAIGHT, -1)
  44. class PlayerSorter:
  45. static func sort(a, b):
  46. return a.position.x > b.position.x || a.position.x == b.position.x && a.position.y > b.position.y