From 5adf87fbc7c11e36e1e317fbed850e3fa98d0d06 Mon Sep 17 00:00:00 2001 From: h0lybyte <5599058+h0lybyte@users.noreply.github.com> Date: Thu, 20 Feb 2025 06:52:50 -0500 Subject: [PATCH 1/5] feat(brackey13): added a small hud. --- apps/gamejam/brackeys/13/scenes/game.tscn | 74 +++++++++++++++++-- apps/gamejam/brackeys/13/scenes/ui/toast.tscn | 7 +- apps/gamejam/brackeys/13/scripts/game.gd | 6 +- apps/gamejam/brackeys/13/scripts/hud.gd | 11 +++ apps/gamejam/brackeys/13/scripts/laser.gd | 1 + 5 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 apps/gamejam/brackeys/13/scripts/hud.gd diff --git a/apps/gamejam/brackeys/13/scenes/game.tscn b/apps/gamejam/brackeys/13/scenes/game.tscn index 107d8a74f..a3ba0dd94 100644 --- a/apps/gamejam/brackeys/13/scenes/game.tscn +++ b/apps/gamejam/brackeys/13/scenes/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://cbrda40vq26pj"] +[gd_scene load_steps=14 format=3 uid="uid://cbrda40vq26pj"] [ext_resource type="Script" path="res://scripts/game.gd" id="1_oyaqx"] [ext_resource type="PackedScene" uid="uid://1s5v0llrjq3" path="res://scenes/spaceship.tscn" id="1_rlyye"] @@ -10,10 +10,75 @@ [ext_resource type="Script" path="res://scripts/environment_layer.gd" id="8_rakg7"] [ext_resource type="Script" path="res://scripts/toast_manager.gd" id="9_tiuga"] [ext_resource type="Script" path="res://scripts/entity.gd" id="10_1liq3"] +[ext_resource type="Script" path="res://scripts/hud.gd" id="11_e1u8f"] +[ext_resource type="Theme" uid="uid://bkt3waoihtb6j" path="res://theme/Theme.tres" id="11_je1f8"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_4vpul"] +bg_color = Color(0.6, 0.6, 0.6, 0.5) +expand_margin_left = 20.0 +expand_margin_right = 20.0 [node name="Game" type="Node2D"] script = ExtResource("1_oyaqx") +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="UI" type="Control" parent="CanvasLayer"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="HUD" type="Control" parent="CanvasLayer/UI"] +custom_minimum_size = Vector2(0, 80) +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +theme = ExtResource("11_je1f8") +script = ExtResource("11_e1u8f") + +[node name="Panel" type="PanelContainer" parent="CanvasLayer/UI/HUD"] +custom_minimum_size = Vector2(0, 80) +layout_mode = 1 +anchors_preset = 10 +anchor_right = 1.0 +offset_bottom = 23.0 +grow_horizontal = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_4vpul") + +[node name="Menu" type="HBoxContainer" parent="CanvasLayer/UI/HUD/Panel"] +layout_mode = 2 +alignment = 1 + +[node name="Label" type="Label" parent="CanvasLayer/UI/HUD/Panel/Menu"] +layout_mode = 2 + +[node name="Bottom" type="Control" parent="CanvasLayer"] +layout_mode = 3 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 0 + +[node name="ToastManager" type="Control" parent="CanvasLayer/Bottom"] +layout_mode = 1 +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_top = -80.0 +offset_right = 40.0 +offset_bottom = -40.0 +grow_vertical = 0 +script = ExtResource("9_tiuga") + [node name="Spaceship" parent="." instance=ExtResource("1_rlyye")] position = Vector2(500, 300) @@ -39,12 +104,5 @@ script = ExtResource("7_hvh2v") [node name="EnvironmentLayer" type="Node2D" parent="Background"] script = ExtResource("8_rakg7") -[node name="ToastManager" type="Control" parent="."] -layout_mode = 3 -anchors_preset = 0 -offset_right = 40.0 -offset_bottom = 40.0 -script = ExtResource("9_tiuga") - [node name="Entity" type="Node2D" parent="."] script = ExtResource("10_1liq3") diff --git a/apps/gamejam/brackeys/13/scenes/ui/toast.tscn b/apps/gamejam/brackeys/13/scenes/ui/toast.tscn index f92aece5b..fd61fbd66 100644 --- a/apps/gamejam/brackeys/13/scenes/ui/toast.tscn +++ b/apps/gamejam/brackeys/13/scenes/ui/toast.tscn @@ -5,7 +5,12 @@ [node name="Toast" type="Control"] layout_mode = 3 -anchors_preset = 0 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 0 script = ExtResource("1_jpci1") [node name="Panel" type="Panel" parent="."] diff --git a/apps/gamejam/brackeys/13/scripts/game.gd b/apps/gamejam/brackeys/13/scripts/game.gd index 6477a08b8..fea0d7731 100644 --- a/apps/gamejam/brackeys/13/scripts/game.gd +++ b/apps/gamejam/brackeys/13/scripts/game.gd @@ -3,14 +3,14 @@ extends Node2D @onready var spaceship = $Spaceship @onready var projectiles = $Projectiles @onready var background = $Background -@onready var tm = $ToastManager +#@onready var tm = $ToastManager -const LASER_POOL_SIZE = 25 +const LASER_POOL_SIZE = 10 func _ready(): spaceship.connect("laser_shot", _on_spaceship_laser_shot) projectiles.initialize_pool(LASER_POOL_SIZE) - tm.show_toast("game_start", "Game Started! Ready for launch.", "info") + Global.emit_signal("notification_received", "game_start", "Game Started! Ready for launch.", "info") func _on_spaceship_laser_shot(scope_position: Vector2, rotation: float): projectiles.shoot_laser(scope_position, rotation) diff --git a/apps/gamejam/brackeys/13/scripts/hud.gd b/apps/gamejam/brackeys/13/scripts/hud.gd new file mode 100644 index 000000000..a1d4176a6 --- /dev/null +++ b/apps/gamejam/brackeys/13/scripts/hud.gd @@ -0,0 +1,11 @@ +extends Control + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/apps/gamejam/brackeys/13/scripts/laser.gd b/apps/gamejam/brackeys/13/scripts/laser.gd index 8626be712..5aaff5408 100644 --- a/apps/gamejam/brackeys/13/scripts/laser.gd +++ b/apps/gamejam/brackeys/13/scripts/laser.gd @@ -17,6 +17,7 @@ func _on_area_entered(area): if area is Asteroid: var asteroid = area asteroid.destroy() + Global.emit_signal("notification_received", "asteroid_hit", "Asteroid was destoried!", "success") visible = false if get_parent(): get_parent()._on_laser_exited(self) From fcafebfb10ee5d528515fe1cad95ac7104b8c78d Mon Sep 17 00:00:00 2001 From: h0lybyte <5599058+h0lybyte@users.noreply.github.com> Date: Thu, 20 Feb 2025 07:02:14 -0500 Subject: [PATCH 2/5] feat(brackeys13): fixing asteroid typo. --- apps/gamejam/brackeys/13/scripts/entity.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/gamejam/brackeys/13/scripts/entity.gd b/apps/gamejam/brackeys/13/scripts/entity.gd index 4fcfbfb00..d0336b35d 100644 --- a/apps/gamejam/brackeys/13/scripts/entity.gd +++ b/apps/gamejam/brackeys/13/scripts/entity.gd @@ -1,6 +1,6 @@ extends Node2D -const ASTEROID_SCENE = preload("res://scenes/Asteroid.tscn") +const ASTEROID_SCENE = preload("res://scenes/asteroid.tscn") var asteroid_pool: Array = [] var active_asteroids: Array = [] From 19d6b6ce5fcc757ba3c2e3ef4c18ae97ff78b9aa Mon Sep 17 00:00:00 2001 From: h0lybyte <5599058+h0lybyte@users.noreply.github.com> Date: Thu, 20 Feb 2025 18:03:44 -0500 Subject: [PATCH 3/5] feat(brackeys13): updating the resource hud and collection of stone. --- apps/gamejam/brackeys/13/scenes/game.tscn | 15 ++++++ apps/gamejam/brackeys/13/scripts/global.gd | 4 +- apps/gamejam/brackeys/13/scripts/hud.gd | 50 ++++++++++++++++--- apps/gamejam/brackeys/13/scripts/laser.gd | 1 + .../brackeys/13/scripts/projectiles.gd | 6 +-- 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/apps/gamejam/brackeys/13/scenes/game.tscn b/apps/gamejam/brackeys/13/scenes/game.tscn index a3ba0dd94..203df8e97 100644 --- a/apps/gamejam/brackeys/13/scenes/game.tscn +++ b/apps/gamejam/brackeys/13/scenes/game.tscn @@ -56,6 +56,21 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_4vpul") layout_mode = 2 alignment = 1 +[node name="Stone" type="Label" parent="CanvasLayer/UI/HUD/Panel/Menu"] +layout_mode = 2 + +[node name="Metal" type="Label" parent="CanvasLayer/UI/HUD/Panel/Menu"] +layout_mode = 2 + +[node name="Gems" type="Label" parent="CanvasLayer/UI/HUD/Panel/Menu"] +layout_mode = 2 + +[node name="Gold" type="Label" parent="CanvasLayer/UI/HUD/Panel/Menu"] +layout_mode = 2 + +[node name="StarshipName" type="Label" parent="CanvasLayer/UI/HUD/Panel/Menu"] +layout_mode = 2 + [node name="Label" type="Label" parent="CanvasLayer/UI/HUD/Panel/Menu"] layout_mode = 2 diff --git a/apps/gamejam/brackeys/13/scripts/global.gd b/apps/gamejam/brackeys/13/scripts/global.gd index 167f939e3..2902c67bd 100644 --- a/apps/gamejam/brackeys/13/scripts/global.gd +++ b/apps/gamejam/brackeys/13/scripts/global.gd @@ -8,6 +8,8 @@ signal starship_data_changed(data_name, new_value) signal environment_data_changed(data_name, new_value) signal notification_received(message_id: String, message: String, type: String) +@export var resources_list: Array[String] = ["gold", "stone", "metal", "gems"] + var environment_data := { "asteroids": 10, "asteroid_speed": 200, @@ -27,7 +29,7 @@ var base_starship_stats := { "rotation_speed": 270.0, "laser_speed": 550.0, "overheat": 0.0, - "laser_ammo": 25.0, + "laser_ammo": 10.0, } var starship_bonuses := { diff --git a/apps/gamejam/brackeys/13/scripts/hud.gd b/apps/gamejam/brackeys/13/scripts/hud.gd index a1d4176a6..4606717fd 100644 --- a/apps/gamejam/brackeys/13/scripts/hud.gd +++ b/apps/gamejam/brackeys/13/scripts/hud.gd @@ -1,11 +1,49 @@ extends Control +@onready var score_label = $Panel/Menu/Label +@onready var name_label = $Panel/Menu/StarshipName +@onready var stone_label = $Panel/Menu/Stone +@onready var metal_label = $Panel/Menu/Metal +@onready var gems_label = $Panel/Menu/Gems +@onready var gold_label = $Panel/Menu/Gold -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - pass # Replace with function body. +var resource_labels = {} +func _ready(): + resource_labels = { + "gold": gold_label, + "stone": stone_label, + "metal": metal_label, + "gems": gems_label + } + + call_deferred("_update_starship_name") + call_deferred("_update_starship_resources") + Global.connect("resource_changed", Callable(self, "_on_resource_changed")) + update_score(0) -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass +func update_score(new_score): + if score_label: + score_label.text = "Score: %d" % new_score + else: + push_warning("Score label not found!") + +func _update_starship_resources(): + for resource in Global.resources_list: + var amount = Global.get_resource(resource) + if resource_labels.has(resource) and resource_labels[resource]: + resource_labels[resource].text = "%s: %d" % [resource.capitalize(), amount] + +func _on_resource_changed(resource_name: String, new_value: int): + if resource_labels.has(resource_name) and resource_labels[resource_name]: + resource_labels[resource_name].text = "%s: %d" % [resource_name.capitalize(), new_value] + +func _update_starship_name(): + var starship_name = Global.get_starship_data("name") + if name_label: + if starship_name: + name_label.text = "Starship: " + starship_name + else: + name_label.text = "Starship: Unknown" + else: + push_warning("Starship name label not found!") diff --git a/apps/gamejam/brackeys/13/scripts/laser.gd b/apps/gamejam/brackeys/13/scripts/laser.gd index 5aaff5408..5adce495d 100644 --- a/apps/gamejam/brackeys/13/scripts/laser.gd +++ b/apps/gamejam/brackeys/13/scripts/laser.gd @@ -18,6 +18,7 @@ func _on_area_entered(area): var asteroid = area asteroid.destroy() Global.emit_signal("notification_received", "asteroid_hit", "Asteroid was destoried!", "success") + Global.earn_resource("stone", 10) visible = false if get_parent(): get_parent()._on_laser_exited(self) diff --git a/apps/gamejam/brackeys/13/scripts/projectiles.gd b/apps/gamejam/brackeys/13/scripts/projectiles.gd index 638b54224..bf7a0f6c5 100644 --- a/apps/gamejam/brackeys/13/scripts/projectiles.gd +++ b/apps/gamejam/brackeys/13/scripts/projectiles.gd @@ -1,7 +1,7 @@ extends Node const LASER_SCENE = preload("res://scenes/laser.tscn") -@onready var tm = get_parent().get_node("ToastManager") +# @onready var tm = get_parent().get_node("ToastManager") # Shift these to the Q crate later on. var laser_pool: Array = [] var active_lasers: Array = [] @@ -42,7 +42,7 @@ func dynamic_pool_adjustment(): laser.set_deferred("visible", false) laser_pool.append(laser) add_child(laser) - emit_signal("notification_received","laser_upgrade", "Laser Upgraded", "info") + Global.emit_signal("notification_received","laser_upgrade", "Laser Upgraded", "info") print("Laser pool increased to:", desired_pool_size) elif desired_pool_size < current_pool_size: @@ -51,5 +51,5 @@ func dynamic_pool_adjustment(): if laser_pool.size() > 0: var laser = laser_pool.pop_back() laser.queue_free() - emit_signal("notification_received","laser_downgrade", "Laser Downgraded", "warning") + Global.emit_signal("notification_received","laser_downgrade", "Laser Downgraded", "warning") print("Laser pool decreased to:", desired_pool_size) From f8c3b28d4ca590e56c1d4915bafcbf475d4d2e75 Mon Sep 17 00:00:00 2001 From: h0lybyte <5599058+h0lybyte@users.noreply.github.com> Date: Thu, 20 Feb 2025 18:32:30 -0500 Subject: [PATCH 4/5] feat(brackeys): added a random resource function. --- apps/gamejam/brackeys/13/scripts/global.gd | 5 +++++ apps/gamejam/brackeys/13/scripts/laser.gd | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/gamejam/brackeys/13/scripts/global.gd b/apps/gamejam/brackeys/13/scripts/global.gd index 2902c67bd..7e826f3d0 100644 --- a/apps/gamejam/brackeys/13/scripts/global.gd +++ b/apps/gamejam/brackeys/13/scripts/global.gd @@ -47,6 +47,11 @@ var starship_data := { "shield_active": false } +func earn_random_resource(resource_name: String, min_value: int = 3, max_value: int = 15): + var amount = randi_range(min_value, max_value) + earn_resource(resource_name, amount) + + func earn_resource(resource_name: String, amount: int, invoice: String = "Earned"): if amount <= 0: return diff --git a/apps/gamejam/brackeys/13/scripts/laser.gd b/apps/gamejam/brackeys/13/scripts/laser.gd index 5adce495d..60df8a274 100644 --- a/apps/gamejam/brackeys/13/scripts/laser.gd +++ b/apps/gamejam/brackeys/13/scripts/laser.gd @@ -18,7 +18,7 @@ func _on_area_entered(area): var asteroid = area asteroid.destroy() Global.emit_signal("notification_received", "asteroid_hit", "Asteroid was destoried!", "success") - Global.earn_resource("stone", 10) + Global.earn_random_resource("stone") visible = false if get_parent(): get_parent()._on_laser_exited(self) From 7e5cea0d614febfa567f38f2069ff3936b65eecf Mon Sep 17 00:00:00 2001 From: h0lybyte <5599058+h0lybyte@users.noreply.github.com> Date: Thu, 20 Feb 2025 18:33:51 -0500 Subject: [PATCH 5/5] feat(brackeys13): added a shop scene. --- apps/gamejam/brackeys/13/scenes/ui/shop.tscn | 12 ++++++++++++ apps/gamejam/brackeys/13/scripts/shop.gd | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 apps/gamejam/brackeys/13/scenes/ui/shop.tscn create mode 100644 apps/gamejam/brackeys/13/scripts/shop.gd diff --git a/apps/gamejam/brackeys/13/scenes/ui/shop.tscn b/apps/gamejam/brackeys/13/scenes/ui/shop.tscn new file mode 100644 index 000000000..8e7ef9fd7 --- /dev/null +++ b/apps/gamejam/brackeys/13/scenes/ui/shop.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=2 format=3 uid="uid://cl2srbe0xb2gw"] + +[ext_resource type="Script" path="res://scripts/shop.gd" id="1_xq0us"] + +[node name="Shop" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_xq0us") diff --git a/apps/gamejam/brackeys/13/scripts/shop.gd b/apps/gamejam/brackeys/13/scripts/shop.gd new file mode 100644 index 000000000..a1d4176a6 --- /dev/null +++ b/apps/gamejam/brackeys/13/scripts/shop.gd @@ -0,0 +1,11 @@ +extends Control + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass