Base docking system (areas don't monitor ship somehow)

This commit is contained in:
2ndbeam 2024-05-14 00:24:36 +03:00
commit 739cdbe4c3
11 changed files with 190 additions and 18 deletions

View file

@ -2,6 +2,8 @@ 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):
@ -25,4 +27,7 @@ func _physics_process(_delta) -> void:
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()

View file

@ -6,6 +6,7 @@ class_name PlayerShip
@onready var camera = $Camera
## Player colorable GUI reference
@onready var colorable_gui = $ColorableGUI
## Node which was selected by input
var selected_node: Node2D = null
## Currency variable
var money: float = 1000.0

View file

@ -15,6 +15,8 @@ signal destroyed
@onready var weapons: Node2D = $Weapons
## Node beginning position
@onready var spawn_position: Vector2 = global_position
## Reference to the star system
@onready var star_system: StarSystem = get_tree().current_scene
## Faction which this ship belongs to
var faction : Game.Faction
@ -22,6 +24,8 @@ var faction : Game.Faction
func _ready() -> void:
hull.global_position = global_position
destroyed.connect(destroy_timeout)
hull.mouse_entered.connect(star_system.set_targeted_node.bind(self))
hull.mouse_exited.connect(star_system.clear_targeted_node)
func destroy_timeout():
destroy()