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.

56 lines
1.4 KiB

  1. extends Spatial
  2. var player:Player
  3. const MAX_ROAD_INDEX = 1
  4. var error_rate:float = 0.00
  5. var underspeed_rate:float = 0.00
  6. func _ready():
  7. randomize()
  8. func _physics_process(delta):
  9. if is_network_master() && player != null:
  10. if player.is_out:
  11. if player.is_resetable:
  12. player.reset()
  13. else:
  14. if player.get_road() != null:
  15. var rate = randf()
  16. var road = player.get_road()
  17. var road_index = 0
  18. var speed_constrain = 0.0
  19. while road != null && road_index < MAX_ROAD_INDEX:
  20. for index in range(road.speed_constrains.size()):
  21. var constrain = road.speed_constrains[index]
  22. if constrain.z > 0:
  23. speed_constrain = max(speed_constrain, constrain.z)
  24. elif constrain.z < 0:
  25. speed_constrain = min(speed_constrain, constrain.z)
  26. road = player.route.get_road(road.get_index() + 1)
  27. road_index += 1
  28. var speed = player.current_speed
  29. if speed_constrain < 0:
  30. player.thrust = 1
  31. elif speed_constrain > 0 && speed > speed_constrain:
  32. player.thrust = -1
  33. elif rate > underspeed_rate:
  34. player.thrust = 1
  35. else:
  36. player.thrust = 0
  37. func set_player(path:String):
  38. player = get_node(path)
  39. get_node("inventory").set_player(player)
  40. func set_error_rate(new_error_rate:float):
  41. error_rate = new_error_rate
  42. func set_underspeed_rate(new_underspeed_rate:float):
  43. underspeed_rate = new_underspeed_rate