Base docking system (areas don't monitor ship somehow)
This commit is contained in:
parent
ab3ac4af66
commit
739cdbe4c3
11 changed files with 190 additions and 18 deletions
101
scripts/Base/base.gd
Normal file
101
scripts/Base/base.gd
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
extends StaticBody2D
|
||||
|
||||
class_name Base
|
||||
|
||||
enum DockState { Ready, Process, Busy }
|
||||
|
||||
signal dock_requested
|
||||
|
||||
## Reference to star system
|
||||
@onready var star_system: StarSystem = get_tree().current_scene
|
||||
|
||||
@onready var gate_static = $Gate
|
||||
|
||||
@onready var gate_area = $GateArea
|
||||
|
||||
@onready var dock_area = $DockingArea
|
||||
|
||||
@export var faction: Game.Faction
|
||||
|
||||
var dock_state: DockState = DockState.Ready
|
||||
|
||||
var touching_gate = false
|
||||
var touching_dock = false
|
||||
|
||||
var player_ship = null
|
||||
|
||||
func _ready():
|
||||
mouse_entered.connect(star_system.set_targeted_node.bind(self))
|
||||
mouse_exited.connect(star_system.clear_targeted_node)
|
||||
gate_area.body_entered.connect(gate_area_body_entered)
|
||||
gate_area.body_exited.connect(gate_area_body_exited)
|
||||
dock_area.body_entered.connect(dock_area_body_entered)
|
||||
dock_area.body_exited.connect(dock_area_body_exited)
|
||||
dock_requested.connect(on_dock_requested)
|
||||
dock_ready()
|
||||
|
||||
## Switches dock state
|
||||
func on_dock_requested():
|
||||
player_ship = star_system.player_ship
|
||||
match dock_state:
|
||||
DockState.Ready:
|
||||
dock_process()
|
||||
DockState.Process:
|
||||
dock_ready()
|
||||
|
||||
func gate_area_body_entered(body):
|
||||
if body is PlayerShip:
|
||||
touching_gate = true
|
||||
|
||||
func gate_area_body_exited(body):
|
||||
if body is PlayerShip:
|
||||
touching_gate = false
|
||||
|
||||
func dock_area_body_entered(body):
|
||||
if body is PlayerShip:
|
||||
touching_dock = true
|
||||
|
||||
func dock_area_body_exited(body):
|
||||
if body is PlayerShip:
|
||||
touching_dock = false
|
||||
|
||||
func _process(_delta):
|
||||
if dock_state == DockState.Process:
|
||||
var distance_to_player = global_position.distance_to(player_ship.global_position)
|
||||
print(touching_dock, " ", touching_gate)
|
||||
if touching_dock and !touching_gate:
|
||||
dock_busy()
|
||||
if !touching_dock and !touching_gate and distance_to_player > 2048:
|
||||
dock_ready()
|
||||
|
||||
## Sets dock state to Ready
|
||||
func dock_ready():
|
||||
print("no shit")
|
||||
dock_state = DockState.Ready
|
||||
gate_static.visible = true
|
||||
gate_static.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
gate_area.visible = false
|
||||
dock_area.visible = false
|
||||
touching_gate = false
|
||||
touching_dock = false
|
||||
## Sets dock state to Process
|
||||
func dock_process():
|
||||
print("wanna dock")
|
||||
dock_state = DockState.Process
|
||||
gate_static.visible = false
|
||||
gate_static.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
gate_area.visible = true
|
||||
dock_area.visible = true
|
||||
touching_gate = false
|
||||
touching_dock = false
|
||||
## Sets dock state to Busy
|
||||
func dock_busy():
|
||||
dock_state = DockState.Busy
|
||||
gate_static.visible = true
|
||||
gate_static.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
gate_area.visible = false
|
||||
dock_area.visible = false
|
||||
touching_gate = false
|
||||
touching_dock = true
|
||||
print("busy kozyzy")
|
||||
# TODO: implement opening the base menu
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@ extends Node
|
|||
|
||||
class_name StarSystem
|
||||
|
||||
@onready var fact_player = $FactionPlayer
|
||||
@onready var fact_peaceful = $FactionPeaceful
|
||||
@onready var fact_neutral = $FactionNeutral
|
||||
@onready var fact_aggressive = $FactionAggressive
|
||||
|
||||
## Width of the system. Limits stars generation and camera bounds
|
||||
@export var width: int = 8192
|
||||
## Height of the system. Limits stars generation and camera bounds
|
||||
|
|
@ -10,6 +15,8 @@ class_name StarSystem
|
|||
## Pause controller packed scene
|
||||
@export var pause_controller_scene: PackedScene
|
||||
|
||||
var targeted_node: Node2D = null
|
||||
|
||||
## Player ship reference. May be null.
|
||||
var player_ship: PlayerShip
|
||||
## Pause controller reference
|
||||
|
|
@ -32,6 +39,7 @@ func _ready():
|
|||
# or add it to root node lol
|
||||
add_child(pause_controller)
|
||||
|
||||
|
||||
pause_controller.visible = false
|
||||
|
||||
## Pause the game. Remember to unpause it when switching scenes!
|
||||
|
|
@ -50,3 +58,9 @@ func _process(_delta):
|
|||
|
||||
if player_ship != null:
|
||||
pause_controller.position = player_ship.global_position
|
||||
|
||||
func set_targeted_node(node):
|
||||
targeted_node = node
|
||||
|
||||
func clear_targeted_node():
|
||||
targeted_node = null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue