Randoloot/scripts/planets/lander_motion.gd

45 lines
1.4 KiB
GDScript

extends RefCounted
const FLIGHT := preload("res://scripts/game/flight_movement.gd")
var velocity := Vector2.ZERO
var rotation := 0.0
var angular_velocity := 0.0
var max_speed := 90.0
var reverse_max_speed := 45.0
var max_strafe_speed := 45.0
var thrust_acceleration := 90.0
var brake_acceleration := 180.0
var space_drag := 16.0
var max_turn_speed := 2.8
var turn_acceleration := 7.0
var turn_damping := 4.0
var energy := 100.0
var boost_active := false
var _exhausted := false
var _coast := 0.0
func configure(ship: Node) -> void:
for key in ["max_speed","reverse_max_speed","max_strafe_speed","thrust_acceleration","brake_acceleration","space_drag","max_turn_speed","turn_acceleration","turn_damping"]:
set(key, ship.get(key))
func step(delta: float, turn: float, thrust: bool, brake: bool, strafe: float, boost_pressed: bool) -> void:
energy = minf(100,energy + 5.0 * delta)
var previous := boost_active
boost_active = false
if not boost_pressed:
_exhausted = false
elif not _exhausted and not brake:
if energy < 20.0 * delta or energy <= 0:
_exhausted = true
else:
energy = maxf(0,energy-20.0*delta)
boost_active = true
if boost_active:
_coast = 0
else:
if previous:
_coast = maxf(0,velocity.length()-max_speed)
_coast = move_toward(_coast,0,space_drag*delta)
FLIGHT.apply(self,delta,turn,thrust,brake,strafe,boost_active,false,max_speed*2 if boost_active else max_speed+_coast)
rotation = wrapf(rotation,-PI,PI)