81 lines
3.4 KiB
GDScript
81 lines
3.4 KiB
GDScript
extends Node
|
|
const MOTION := preload("res://scripts/planets/lander_motion.gd")
|
|
func _ready() -> void:
|
|
var motion := MOTION.new()
|
|
for tick in 60:
|
|
motion.step(1.0/60,1,false,false,0,false)
|
|
assert(motion.velocity == Vector2.ZERO and motion.rotation > 1)
|
|
motion = MOTION.new()
|
|
for tick in 60:
|
|
motion.step(1.0/60,0,true,false,0,false)
|
|
assert(motion.velocity.y < -50)
|
|
var speed: float = motion.velocity.length()
|
|
motion.step(1.0/60,0,false,false,0,false)
|
|
assert(motion.velocity.length() > speed-1 and motion.velocity.length() < speed)
|
|
for tick in 120:
|
|
motion.step(1.0/60,0,false,true,0,false)
|
|
assert(motion.velocity.y > 0 and motion.velocity.y <= motion.reverse_max_speed)
|
|
motion = MOTION.new()
|
|
motion.rotation = PI*0.5
|
|
motion.step(0.1,0,true,false,0,false)
|
|
assert(motion.velocity.x > 0 and absf(motion.velocity.y) < 0.01)
|
|
motion = MOTION.new()
|
|
motion.step(0.1,0,false,false,1,false)
|
|
assert(motion.velocity.x > 0 and motion.rotation == 0)
|
|
for tick in 120:
|
|
motion.step(1.0/60,0,true,false,0,true)
|
|
assert(motion.boost_active and motion.energy < 100 and motion.velocity.length() > motion.max_speed)
|
|
var game := preload("res://scenes/game/game.tscn").instantiate()
|
|
add_child(game)
|
|
await get_tree().process_frame
|
|
var manager := game.get_node("PlanetExpeditions")
|
|
for enemy in get_tree().get_nodes_in_group("enemies"):
|
|
enemy.position = Vector2(-9999,-9999)
|
|
# Compare the actual ship controller with the lander under the same actions.
|
|
var paired := MOTION.new()
|
|
paired.configure(game.player)
|
|
game.player.position = Vector2(10000,10000)
|
|
game.player.velocity = Vector2.ZERO
|
|
game.player.rotation = 0
|
|
game.player.angular_velocity = 0
|
|
for phase in [["ship_thrust",0.0,true,false,0.0],["ship_turn_right",1.0,false,false,0.0],["ship_strafe_right",0.0,false,false,1.0],["ship_brake",0.0,false,true,0.0]]:
|
|
Input.action_press(phase[0])
|
|
for tick in 60:
|
|
game.player._physics_process(1.0/60)
|
|
paired.step(1.0/60,phase[1],phase[2],phase[3],phase[4],false)
|
|
assert(game.player.velocity.distance_to(paired.velocity) < 0.001)
|
|
assert(absf(angle_difference(game.player.rotation,paired.rotation)) < 0.001)
|
|
Input.action_release(phase[0])
|
|
game.player.velocity = Vector2.ZERO
|
|
game.player.rotation = 0
|
|
game.player.angular_velocity = 0
|
|
game.player.position = game.protected_planet.position
|
|
manager._process(0)
|
|
assert(manager._text.text.contains("TLEN") and manager._text.text.contains("TEMPERATURA") and manager._text.text.contains("FLORA"))
|
|
assert(manager._text.text.contains("Pierwszy etap POI"))
|
|
manager.land_nearby()
|
|
var screen: Control = manager.screen
|
|
assert(screen._motion.max_speed == game.player.max_speed)
|
|
assert(screen._motion.turn_acceleration == game.player.turn_acceleration)
|
|
screen.lander.position = screen.world.data.pois[0].position
|
|
var key := InputEventKey.new()
|
|
key.pressed = true
|
|
key.keycode = KEY_E
|
|
screen._input(key)
|
|
assert(not screen._dialog.visible)
|
|
key.keycode = KEY_F
|
|
screen._input(key)
|
|
assert(screen._dialog.visible)
|
|
var ship_energy: float = game.player.energy
|
|
Input.action_press("ship_thrust")
|
|
screen._dialog.hide()
|
|
screen._physics_process(0.1)
|
|
Input.action_release("ship_thrust")
|
|
assert(screen._motion.velocity.y < 0)
|
|
assert(game.player.energy == ship_energy)
|
|
manager.finish_surface(true)
|
|
game.queue_free()
|
|
await get_tree().process_frame
|
|
print("LANDER FLIGHT PASS: thrust, inertia, brake/reverse, rotation, local strafe, boost, shared parameters, F interaction, immediate scan")
|
|
get_tree().quit()
|