Made pause controller to be created on player if it exists
This commit is contained in:
parent
350b9853f2
commit
93aa83dcaa
11 changed files with 129 additions and 17 deletions
|
|
@ -18,7 +18,7 @@ class_name Hull
|
|||
"Rockets": 10,
|
||||
}
|
||||
## Current ammunition. Change this with set_ammunition
|
||||
@onready var ammunition: Dictionary = max_ammunition
|
||||
@onready var ammunition: Dictionary = max_ammunition.duplicate()
|
||||
|
||||
## Current HP of the hull. If it reaches zero, it emits parent's destroyed signal
|
||||
@onready var hp: float = max_hp:
|
||||
|
|
@ -35,9 +35,8 @@ var scalar_velocity: float = 0.0
|
|||
func add_ammunition(which: String, value: float) -> bool:
|
||||
if ammunition[which] + value < 0:
|
||||
return false
|
||||
ammunition[which] += value;
|
||||
if ammunition[which] > max_ammunition[which]:
|
||||
ammunition[which] = max_ammunition[which]
|
||||
ammunition[which] = snapped(ammunition[which] + value, 0.01)
|
||||
ammunition[which] = min(ammunition[which], max_ammunition[which])
|
||||
return true
|
||||
|
||||
## Update ship's position and rotation
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ class_name PlayerShip
|
|||
|
||||
## Player camera reference
|
||||
@onready var camera = $Camera
|
||||
## Player colorable GUI reference
|
||||
@onready var colorable_gui = $ColorableGUI
|
||||
|
||||
## Currency variable
|
||||
var money: float = 1000.0
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class_name Shield
|
|||
## Indicates if shield will charge
|
||||
var can_recharge_shield: bool = false
|
||||
## Indicates if laser will charge
|
||||
var can_recharge_laser: bool = true
|
||||
var can_recharge_laser: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
shield_recharge_timer.timeout.connect(shield_timer_out)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ func _process(_delta) -> void:
|
|||
shoot_timer.start()
|
||||
if ammo_type == "Laser Energy":
|
||||
ship.shield.laser_recharge_timer.start()
|
||||
ship.shield.can_recharge_laser = false
|
||||
|
||||
func shoot() -> void:
|
||||
for spawner in spawner_points:
|
||||
|
|
|
|||
|
|
@ -7,21 +7,32 @@ class_name StarSystem
|
|||
## Height of the system. Limits stars generation and camera bounds
|
||||
@export var height: int = 8192
|
||||
|
||||
## Pause controller node reference
|
||||
@onready var pause_controller = $PauseController
|
||||
## Pause controller packed scene
|
||||
@export var pause_controller_scene: PackedScene
|
||||
|
||||
## Player ship reference. May be null.
|
||||
var player_ship: PlayerShip
|
||||
## Pause controller reference
|
||||
var pause_controller: Control
|
||||
|
||||
func _ready():
|
||||
player_ship = get_node_or_null("PlayerShip")
|
||||
|
||||
# adjust player ship camera if player ship exists
|
||||
pause_controller = pause_controller_scene.instantiate()
|
||||
|
||||
if player_ship != null:
|
||||
# adjust player ship camera if player ship exists
|
||||
player_ship.camera.limit_left = -width / 2
|
||||
player_ship.camera.limit_right = width / 2
|
||||
player_ship.camera.limit_top = -height / 2
|
||||
player_ship.camera.limit_bottom = height / 2
|
||||
# add pause controller child to the gui
|
||||
player_ship.colorable_gui.add_child(pause_controller)
|
||||
else:
|
||||
# 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!
|
||||
func pause():
|
||||
|
|
@ -36,3 +47,6 @@ func unpause():
|
|||
func _process(_delta):
|
||||
if Input.is_action_just_released("pause"):
|
||||
unpause() if get_tree().paused else pause()
|
||||
|
||||
if player_ship != null:
|
||||
pause_controller.position = player_ship.global_position
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue