|
|
|
@ -7,25 +7,24 @@ var ship_direction = 0
|
|
|
|
|
var ship_speed = 0
|
|
|
|
|
|
|
|
|
|
var current_ship_position = Vector2.ZERO
|
|
|
|
|
var current_ship_subpos = Vector2.ZERO
|
|
|
|
|
var current_ship_target = Vector2.ZERO
|
|
|
|
|
|
|
|
|
|
var current_ship_direction = 0
|
|
|
|
|
var current_ship_speed = 0
|
|
|
|
|
var current_ship_direction = 0.0
|
|
|
|
|
var current_ship_speed = 0.0
|
|
|
|
|
|
|
|
|
|
puppet var pup_ship_position = Vector2.ZERO
|
|
|
|
|
puppet var pup_ship_subpos = Vector2.ZERO
|
|
|
|
|
puppet var pup_ship_target = Vector2.ZERO
|
|
|
|
|
puppet var pup_ship_direction = 0
|
|
|
|
|
puppet var pup_ship_speed = 0
|
|
|
|
|
puppet var pup_ship_direction = 0.0
|
|
|
|
|
puppet var pup_ship_speed = 0.0
|
|
|
|
|
|
|
|
|
|
const MAX_ACCELERATION = 0.03
|
|
|
|
|
const DIRECTION_EASE = 0.4
|
|
|
|
|
const EPSILON = 0.01
|
|
|
|
|
const MAX_STEERING = 0.06
|
|
|
|
|
const EPSILON = 1e-3
|
|
|
|
|
const SCROLL_MULTIPLIER = 1e4
|
|
|
|
|
const ENGINE_MULTIPLIER = 5000
|
|
|
|
|
const MAX_SPEED = 0.2 # in Sectors/Second
|
|
|
|
|
const SLOW_SPEED = 0.02
|
|
|
|
|
const SLOW_SPEED_THRESHOLD = 0.2
|
|
|
|
|
const NO_SPEED_THRESHOLD = 0.1
|
|
|
|
|
const NO_SPEED_THRESHOLD = 0.01
|
|
|
|
|
|
|
|
|
|
const ProbeElectricity = preload("res://Actors/Systems/Electricity/ElectricProbe.tscn")
|
|
|
|
|
|
|
|
|
@ -42,7 +41,7 @@ func _ready():
|
|
|
|
|
if Engine.editor_hint:
|
|
|
|
|
return
|
|
|
|
|
$editor.queue_free()
|
|
|
|
|
set_unlit(false)
|
|
|
|
|
set_unlit(true)
|
|
|
|
|
|
|
|
|
|
if not is_network_master():
|
|
|
|
|
return
|
|
|
|
@ -59,19 +58,33 @@ func _ready():
|
|
|
|
|
func _process(delta: float):
|
|
|
|
|
if Engine.editor_hint:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
var current_speed_ratio = current_ship_speed / MAX_SPEED
|
|
|
|
|
|
|
|
|
|
var current_speed_ratio = 0
|
|
|
|
|
var engines = get_engine_count()
|
|
|
|
|
var max_speed = get_max_speed()
|
|
|
|
|
if engines > 0:
|
|
|
|
|
current_speed_ratio = current_ship_speed / max_speed
|
|
|
|
|
|
|
|
|
|
# Ease ship speed/direction changes
|
|
|
|
|
if abs(ship_direction - current_ship_direction) < EPSILON:
|
|
|
|
|
if abs(current_ship_direction) > PI*2:
|
|
|
|
|
current_ship_direction -= PI*2 * sign(current_ship_direction)
|
|
|
|
|
var direction_delta = ship_direction - current_ship_direction
|
|
|
|
|
if direction_delta < 0:
|
|
|
|
|
direction_delta += PI*2
|
|
|
|
|
if direction_delta > PI:
|
|
|
|
|
direction_delta -= PI*2
|
|
|
|
|
|
|
|
|
|
if abs(direction_delta) < 1e-3:
|
|
|
|
|
current_ship_direction = ship_direction
|
|
|
|
|
else:
|
|
|
|
|
current_ship_direction = lerp(current_ship_direction, ship_direction, delta * current_speed_ratio * DIRECTION_EASE)
|
|
|
|
|
# Avoid stuttering by not turning until there's enough reason to
|
|
|
|
|
if abs(direction_delta) > 0.1:
|
|
|
|
|
current_ship_direction += MAX_STEERING * engines * delta * sign(direction_delta)
|
|
|
|
|
var speed_delta = ship_speed - current_ship_speed
|
|
|
|
|
if abs(speed_delta) < EPSILON:
|
|
|
|
|
current_ship_speed = ship_speed
|
|
|
|
|
else:
|
|
|
|
|
current_ship_speed += MAX_ACCELERATION * max(0.1, 1-ease(current_speed_ratio, 0.6)) * delta * sign(speed_delta)
|
|
|
|
|
current_ship_speed += MAX_ACCELERATION * max_speed * delta * sign(speed_delta)
|
|
|
|
|
set_engine_strength(current_ship_speed * ENGINE_MULTIPLIER)
|
|
|
|
|
|
|
|
|
|
$deepspace.rotation = -current_ship_direction-PI/2
|
|
|
|
@ -81,27 +94,61 @@ func _physics_process(delta):
|
|
|
|
|
if Engine.editor_hint:
|
|
|
|
|
return
|
|
|
|
|
if is_network_master():
|
|
|
|
|
var distance = current_ship_position.distance_to(current_ship_target)
|
|
|
|
|
if distance > NO_SPEED_THRESHOLD:
|
|
|
|
|
ship_direction = current_ship_target.angle_to_point(current_ship_position)
|
|
|
|
|
if distance < SLOW_SPEED_THRESHOLD:
|
|
|
|
|
ship_speed = SLOW_SPEED
|
|
|
|
|
elif current_ship_speed == 0 or distance / current_ship_speed > ease(current_ship_speed, 2.8)*4000:
|
|
|
|
|
ship_speed = MAX_SPEED
|
|
|
|
|
var adj_position = current_ship_position+current_ship_subpos
|
|
|
|
|
if current_ship_target != null:
|
|
|
|
|
var distance = adj_position.distance_to(current_ship_target)
|
|
|
|
|
if distance > NO_SPEED_THRESHOLD:
|
|
|
|
|
ship_direction = current_ship_target.angle_to_point(adj_position)
|
|
|
|
|
var max_speed = get_max_speed()
|
|
|
|
|
if max_speed > 0:
|
|
|
|
|
var deceleration_time = current_ship_speed / (MAX_ACCELERATION * max_speed)
|
|
|
|
|
if current_ship_speed * deceleration_time < distance:
|
|
|
|
|
ship_speed = max_speed
|
|
|
|
|
else:
|
|
|
|
|
ship_speed = 0.0
|
|
|
|
|
else:
|
|
|
|
|
ship_speed = 0.0
|
|
|
|
|
rset("pup_ship_direction", ship_direction)
|
|
|
|
|
rset("pup_ship_speed", ship_speed)
|
|
|
|
|
else:
|
|
|
|
|
ship_speed = 0
|
|
|
|
|
rset("pup_ship_direction", ship_direction)
|
|
|
|
|
rset("pup_ship_speed", ship_speed)
|
|
|
|
|
ship_speed = 0.0
|
|
|
|
|
rset("pup_ship_speed", ship_speed)
|
|
|
|
|
if current_ship_speed > EPSILON:
|
|
|
|
|
var pos_delta = (Vector2.RIGHT * current_ship_speed * delta).rotated(current_ship_direction)
|
|
|
|
|
current_ship_subpos += pos_delta
|
|
|
|
|
if current_ship_subpos.x >= 1.0:
|
|
|
|
|
var int_part = floor(current_ship_subpos.x)
|
|
|
|
|
current_ship_position.x += int_part
|
|
|
|
|
current_ship_subpos.x -= int_part
|
|
|
|
|
if current_ship_subpos.y >= 1.0:
|
|
|
|
|
var int_part = floor(current_ship_subpos.y)
|
|
|
|
|
current_ship_position.y += int_part
|
|
|
|
|
current_ship_subpos.y -= int_part
|
|
|
|
|
rset("pup_ship_position", current_ship_position)
|
|
|
|
|
rset("pup_ship_subpos", current_ship_subpos)
|
|
|
|
|
else:
|
|
|
|
|
ship_speed = 0
|
|
|
|
|
ship_speed = 0.0
|
|
|
|
|
rset("pup_ship_speed", ship_speed)
|
|
|
|
|
if current_ship_speed > EPSILON:
|
|
|
|
|
current_ship_position += (Vector2.RIGHT * current_ship_speed * delta).rotated(current_ship_direction)
|
|
|
|
|
rset("pup_ship_position", current_ship_position)
|
|
|
|
|
else:
|
|
|
|
|
ship_direction = pup_ship_direction
|
|
|
|
|
ship_speed = pup_ship_speed
|
|
|
|
|
current_ship_position = pup_ship_position
|
|
|
|
|
current_ship_subpos = pup_ship_subpos
|
|
|
|
|
|
|
|
|
|
func get_engine_count():
|
|
|
|
|
var working_engines = 0
|
|
|
|
|
for child in $engines.get_children():
|
|
|
|
|
var engine = child as GameObjectEngine
|
|
|
|
|
if engine.force > 0:
|
|
|
|
|
working_engines += 1
|
|
|
|
|
return working_engines
|
|
|
|
|
|
|
|
|
|
func get_max_speed():
|
|
|
|
|
var max_speed = 0
|
|
|
|
|
for child in $engines.get_children():
|
|
|
|
|
var engine = child as GameObjectEngine
|
|
|
|
|
max_speed += engine.force
|
|
|
|
|
return max_speed
|
|
|
|
|
|
|
|
|
|
# Serialization / Deserialization
|
|
|
|
|
|
|
|
|
|