33 lines
1.2 KiB
GDScript
33 lines
1.2 KiB
GDScript
extends Node2D
|
|
|
|
## Shortcut to get_parent()
|
|
@onready var ship: Ship = get_parent()
|
|
## Reference to the star system
|
|
@onready var star_system: StarSystem = get_tree().current_scene
|
|
|
|
var expected_rotation: float = 0.0:
|
|
set(value):
|
|
if value > 180:
|
|
expected_rotation = value - 360
|
|
elif value < -180:
|
|
expected_rotation = 360 + value
|
|
else:
|
|
expected_rotation = value
|
|
|
|
func _physics_process(_delta) -> void:
|
|
ship.engine.acceleration_axis = Input.get_axis("deccelerate", "accelerate")
|
|
ship.engine.rotation_axis = Input.get_axis("rotateleft", "rotateright")
|
|
for weapon in ship.weapons.list:
|
|
match weapon.action_id:
|
|
"primary":
|
|
weapon.shoot_request = Input.get_action_strength("shootprimary")
|
|
"secondary":
|
|
weapon.shoot_request = Input.get_action_strength("shootsecondary")
|
|
if "gun_rotation" in weapon:
|
|
var angle_to_mouse = ship.hull.position.angle_to_point(get_global_mouse_position())
|
|
expected_rotation = rad_to_deg(angle_to_mouse - ship.hull.rotation)
|
|
weapon.gun_rotation = expected_rotation
|
|
if Input.is_action_just_released("select_target"):
|
|
ship.selected_node = star_system.targeted_node
|
|
if ship.selected_node is Base and Input.is_action_just_released("dock"):
|
|
ship.selected_node.dock_requested.emit()
|