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.7 KiB

  1. extends Spatial
  2. var player:Player
  3. const MAX_OFFSET = 8.0
  4. const OFFSET_STEPS = 0.01
  5. var break_constrain = 0.0
  6. export var overspeed_rate:float = 0.3
  7. export var underspeed_rate:float = 0.1
  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 road = player.get_road()
  16. var rate = util.randf()
  17. var speed = player.current_speed
  18. var offset = 0
  19. var distance = player.follow.get_offset()
  20. var tmp_break_constrain = 0.0
  21. break_constrain = 0.0
  22. while tmp_break_constrain == 0.0 and offset < MAX_OFFSET && road != null:
  23. var constrain_index = road.get_constrain_index(distance)
  24. var road_length = road.get_lane_curve(player.lane).get_baked_length()
  25. if constrain_index >= 0:
  26. tmp_break_constrain = road.speed_constrains[constrain_index].z
  27. if tmp_break_constrain > break_constrain:
  28. break_constrain = tmp_break_constrain
  29. distance += OFFSET_STEPS
  30. offset += OFFSET_STEPS
  31. if distance >= road_length:
  32. distance = 0
  33. road = gamestate.game.route.get_road(road.get_index()+1)
  34. if break_constrain > 0 && speed > break_constrain - 0.04 && rate > overspeed_rate:
  35. player.thrust = -1
  36. elif speed - 0.08 < break_constrain && rate > underspeed_rate:
  37. player.thrust = 1
  38. elif break_constrain == 0 && rate > underspeed_rate:
  39. player.thrust = 1
  40. else:
  41. player.thrust = 0
  42. func set_player(path:String):
  43. player = get_node(path)
  44. get_node("inventory").set_player(player)
  45. func set_overspeed_rate(new_overspeed_rate:float):
  46. overspeed_rate = new_overspeed_rate
  47. func set_underspeed_rate(new_underspeed_rate:float):
  48. underspeed_rate = new_underspeed_rate