Made pause controller to be created on player if it exists

This commit is contained in:
2ndbeam 2024-04-30 21:24:51 +03:00
commit 93aa83dcaa
11 changed files with 129 additions and 17 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://dok3i8u5t1ka4"] [gd_scene load_steps=11 format=3 uid="uid://dok3i8u5t1ka4"]
[ext_resource type="PackedScene" uid="uid://bjkshql8ut6hk" path="res://scenes/Ships/ship.tscn" id="1_6x7bu"] [ext_resource type="PackedScene" uid="uid://bjkshql8ut6hk" path="res://scenes/Ships/ship.tscn" id="1_6x7bu"]
[ext_resource type="Script" path="res://scripts/Ship/player_ship.gd" id="2_oqdd7"] [ext_resource type="Script" path="res://scripts/Ship/player_ship.gd" id="2_oqdd7"]
@ -58,6 +58,25 @@ func _process(_delta):
text = unformatted_text.format([ship.shield.capacity, ship.shield.max_capacity]) text = unformatted_text.format([ship.shield.capacity, ship.shield.max_capacity])
" "
[sub_resource type="GDScript" id="GDScript_rrgab"]
resource_name = "ammunition_counter"
script/source = "extends Label
## Text with placeholder
@onready var unformatted_text: String = text
## Shortcut to get_parent().get_parent()
@onready var ship: PlayerShip = get_parent().get_parent()
func _process(_delta):
var format = [
ship.hull.ammunition[\"Laser Energy\"],
ship.hull.max_ammunition[\"Laser Energy\"],
ship.hull.ammunition[\"Rockets\"],
ship.hull.max_ammunition[\"Rockets\"]
]
text = unformatted_text.format(format)
"
[node name="PlayerShip" instance=ExtResource("1_6x7bu")] [node name="PlayerShip" instance=ExtResource("1_6x7bu")]
script = ExtResource("2_oqdd7") script = ExtResource("2_oqdd7")
@ -66,6 +85,8 @@ script = ExtResource("3_0e84a")
[node name="Weapon" parent="Weapons" index="0" instance=ExtResource("4_fy1be")] [node name="Weapon" parent="Weapons" index="0" instance=ExtResource("4_fy1be")]
action_id = "primary" action_id = "primary"
ammo_type = "Laser Energy"
ammo_consumption = 1.0
[node name="ColorableGUI" type="CanvasLayer" parent="." index="5"] [node name="ColorableGUI" type="CanvasLayer" parent="." index="5"]
@ -101,6 +122,17 @@ offset_bottom = 661.0
text = "Shield: {0} / {1} units" text = "Shield: {0} / {1} units"
script = SubResource("GDScript_q1sx2") script = SubResource("GDScript_q1sx2")
[node name="Ammunition" type="Label" parent="ColorableGUI" index="4"]
offset_left = 1060.0
offset_top = 638.0
offset_right = 1273.0
offset_bottom = 713.0
text = "Ammunition:
Laser Energy: {0} / {1}
Rockets: {2} / {3}"
horizontal_alignment = 2
script = SubResource("GDScript_rrgab")
[node name="NonColorableGUI" type="CanvasLayer" parent="." index="6"] [node name="NonColorableGUI" type="CanvasLayer" parent="." index="6"]
[node name="Camera" type="Camera2D" parent="." index="7"] [node name="Camera" type="Camera2D" parent="." index="7"]

View file

@ -0,0 +1,20 @@
[gd_scene load_steps=3 format=3 uid="uid://crneq2enhxsw5"]
[ext_resource type="PackedScene" uid="uid://bsnrcw64qr2hr" path="res://scenes/Star Systems/star_system_template.tscn" id="1_2ai1l"]
[ext_resource type="PackedScene" uid="uid://dok3i8u5t1ka4" path="res://scenes/Ships/player_ship.tscn" id="7_jyplv"]
[node name="StarSystem" instance=ExtResource("1_2ai1l")]
width = 16384
height = 16384
[node name="Stars" parent="." index="0"]
scroll_offset = Vector2(681.667, 317.783)
stars_amount = 4000
[node name="Nebula" parent="Background" index="0" node_paths=PackedStringArray("tracked_node")]
tracked_node = NodePath("../../PlayerShip")
color_background = Color(0.276474, 0.0962249, 0.200656, 1)
[node name="PlayerShip" parent="." index="4" instance=ExtResource("7_jyplv")]
process_mode = 0
position = Vector2(19, 10)

View file

@ -0,0 +1,20 @@
[gd_scene load_steps=3 format=3 uid="uid://crneq2enhxsw5"]
[ext_resource type="PackedScene" uid="uid://bsnrcw64qr2hr" path="res://scenes/Star Systems/star_system_template.tscn" id="1_2ai1l"]
[ext_resource type="PackedScene" uid="uid://dok3i8u5t1ka4" path="res://scenes/Ships/player_ship.tscn" id="7_jyplv"]
[node name="StarSystem" instance=ExtResource("1_2ai1l")]
width = 16384
height = 16384
[node name="Stars" parent="." index="0"]
scroll_offset = Vector2(681.667, 317.783)
stars_amount = 4000
[node name="Nebula" parent="Background" index="0" node_paths=PackedStringArray("tracked_node")]
tracked_node = NodePath("../../PlayerShip")
color_background = Color(0.276474, 0.0962249, 0.200656, 1)
[node name="PlayerShip" parent="." index="4" instance=ExtResource("7_jyplv")]
process_mode = 0
position = Vector2(19, 10)

View file

@ -15,6 +15,6 @@ stars_amount = 4000
tracked_node = NodePath("../../PlayerShip") tracked_node = NodePath("../../PlayerShip")
color_background = Color(0.276474, 0.0962249, 0.200656, 1) color_background = Color(0.276474, 0.0962249, 0.200656, 1)
[node name="PlayerShip" parent="." index="4" instance=ExtResource("7_jyplv")] [node name="PlayerShip" parent="." index="3" instance=ExtResource("7_jyplv")]
process_mode = 0 process_mode = 0
position = Vector2(19, 10) position = Vector2(19, 10)

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=3 uid="uid://bsnrcw64qr2hr"] [gd_scene load_steps=8 format=3 uid="uid://bsnrcw64qr2hr"]
[ext_resource type="Script" path="res://scripts/star_system.gd" id="1_xx8w2"] [ext_resource type="Script" path="res://scripts/star_system.gd" id="1_xx8w2"]
[ext_resource type="PackedScene" uid="uid://dpggye27ln436" path="res://scenes/Star Systems/Required Scenes/star_generator.tscn" id="2_iqrn0"] [ext_resource type="PackedScene" uid="uid://dpggye27ln436" path="res://scenes/Star Systems/Required Scenes/star_generator.tscn" id="2_iqrn0"]
@ -7,9 +7,23 @@
[ext_resource type="Script" path="res://scripts/nebula.gd" id="5_la84n"] [ext_resource type="Script" path="res://scripts/nebula.gd" id="5_la84n"]
[ext_resource type="PackedScene" uid="uid://c7is7y341f6wa" path="res://scenes/Star Systems/Required Scenes/pause_controller.tscn" id="6_61vq5"] [ext_resource type="PackedScene" uid="uid://c7is7y341f6wa" path="res://scenes/Star Systems/Required Scenes/pause_controller.tscn" id="6_61vq5"]
[sub_resource type="GDScript" id="GDScript_4yoh5"]
resource_name = "version_label"
script/source = "extends Label
func _ready():
text = \"cosmic {version}\".format({\"version\" : Game.gameversion})
if OS.has_feature(\"editor\"):
text += \" uncompiled\\ndebug/prerelease version\"
else:
if Game.beta:
text += \" beta\\nclosed beta\"
"
[node name="StarSystem" type="Node"] [node name="StarSystem" type="Node"]
process_mode = 3 process_mode = 3
script = ExtResource("1_xx8w2") script = ExtResource("1_xx8w2")
pause_controller_scene = ExtResource("6_61vq5")
[node name="Stars" parent="." instance=ExtResource("2_iqrn0")] [node name="Stars" parent="." instance=ExtResource("2_iqrn0")]
@ -32,5 +46,12 @@ grow_vertical = 2
script = ExtResource("5_la84n") script = ExtResource("5_la84n")
color_background = Color(0.36, 0.18612, 0.1116, 1) color_background = Color(0.36, 0.18612, 0.1116, 1)
[node name="PauseController" parent="." instance=ExtResource("6_61vq5")] [node name="Version" type="Label" parent="Background"]
visible = false z_index = 50
z_as_relative = false
offset_top = 6.0
offset_right = 1280.0
offset_bottom = 29.0
text = "GammaCosmicRays version Ifre 1.0"
horizontal_alignment = 1
script = SubResource("GDScript_4yoh5")

View file

@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://scripts/objects/projectile.gd" id="1_6nacn"] [ext_resource type="Script" path="res://scripts/objects/projectile.gd" id="1_6nacn"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mo2if"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_mo2if"]
size = Vector2(1, 8) size = Vector2(4, 32)
[node name="Laser" type="Node2D" node_paths=PackedStringArray("collider")] [node name="Laser" type="Node2D" node_paths=PackedStringArray("collider")]
script = ExtResource("1_6nacn") script = ExtResource("1_6nacn")
@ -11,14 +11,17 @@ speed = 600.0
collider = NodePath("Collision") collider = NodePath("Collision")
[node name="LaserBody" type="Line2D" parent="."] [node name="LaserBody" type="Line2D" parent="."]
points = PackedVector2Array(0, 0, 8, 0) points = PackedVector2Array(2, 0, 30, 0)
width = 1.0 width = 4.0
begin_cap_mode = 2
end_cap_mode = 2
round_precision = 4
[node name="Collision" type="Area2D" parent="."] [node name="Collision" type="Area2D" parent="."]
collision_layer = 4 collision_layer = 4
collision_mask = 3 collision_mask = 3
[node name="CollisionShape2D" type="CollisionShape2D" parent="Collision"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Collision"]
position = Vector2(4, 0) position = Vector2(16, -4.34399e-05)
rotation = -1.5708 rotation = -1.5708
shape = SubResource("RectangleShape2D_mo2if") shape = SubResource("RectangleShape2D_mo2if")

View file

@ -18,7 +18,7 @@ class_name Hull
"Rockets": 10, "Rockets": 10,
} }
## Current ammunition. Change this with set_ammunition ## 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 ## Current HP of the hull. If it reaches zero, it emits parent's destroyed signal
@onready var hp: float = max_hp: @onready var hp: float = max_hp:
@ -35,9 +35,8 @@ var scalar_velocity: float = 0.0
func add_ammunition(which: String, value: float) -> bool: func add_ammunition(which: String, value: float) -> bool:
if ammunition[which] + value < 0: if ammunition[which] + value < 0:
return false return false
ammunition[which] += value; ammunition[which] = snapped(ammunition[which] + value, 0.01)
if ammunition[which] > max_ammunition[which]: ammunition[which] = min(ammunition[which], max_ammunition[which])
ammunition[which] = max_ammunition[which]
return true return true
## Update ship's position and rotation ## Update ship's position and rotation

View file

@ -4,6 +4,8 @@ class_name PlayerShip
## Player camera reference ## Player camera reference
@onready var camera = $Camera @onready var camera = $Camera
## Player colorable GUI reference
@onready var colorable_gui = $ColorableGUI
## Currency variable ## Currency variable
var money: float = 1000.0 var money: float = 1000.0

View file

@ -28,7 +28,7 @@ class_name Shield
## Indicates if shield will charge ## Indicates if shield will charge
var can_recharge_shield: bool = false var can_recharge_shield: bool = false
## Indicates if laser will charge ## Indicates if laser will charge
var can_recharge_laser: bool = true var can_recharge_laser: bool = false
func _ready() -> void: func _ready() -> void:
shield_recharge_timer.timeout.connect(shield_timer_out) shield_recharge_timer.timeout.connect(shield_timer_out)

View file

@ -39,6 +39,7 @@ func _process(_delta) -> void:
shoot_timer.start() shoot_timer.start()
if ammo_type == "Laser Energy": if ammo_type == "Laser Energy":
ship.shield.laser_recharge_timer.start() ship.shield.laser_recharge_timer.start()
ship.shield.can_recharge_laser = false
func shoot() -> void: func shoot() -> void:
for spawner in spawner_points: for spawner in spawner_points:

View file

@ -7,21 +7,32 @@ class_name StarSystem
## Height of the system. Limits stars generation and camera bounds ## Height of the system. Limits stars generation and camera bounds
@export var height: int = 8192 @export var height: int = 8192
## Pause controller node reference ## Pause controller packed scene
@onready var pause_controller = $PauseController @export var pause_controller_scene: PackedScene
## Player ship reference. May be null. ## Player ship reference. May be null.
var player_ship: PlayerShip var player_ship: PlayerShip
## Pause controller reference
var pause_controller: Control
func _ready(): func _ready():
player_ship = get_node_or_null("PlayerShip") 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: if player_ship != null:
# adjust player ship camera if player ship exists
player_ship.camera.limit_left = -width / 2 player_ship.camera.limit_left = -width / 2
player_ship.camera.limit_right = width / 2 player_ship.camera.limit_right = width / 2
player_ship.camera.limit_top = -height / 2 player_ship.camera.limit_top = -height / 2
player_ship.camera.limit_bottom = 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! ## Pause the game. Remember to unpause it when switching scenes!
func pause(): func pause():
@ -36,3 +47,6 @@ func unpause():
func _process(_delta): func _process(_delta):
if Input.is_action_just_released("pause"): if Input.is_action_just_released("pause"):
unpause() if get_tree().paused else pause() unpause() if get_tree().paused else pause()
if player_ship != null:
pause_controller.position = player_ship.global_position