From eab5bc9257b65d73f98753dee820ead5428fc968 Mon Sep 17 00:00:00 2001 From: Al Justin Date: Sun, 23 Feb 2025 09:51:12 +0800 Subject: [PATCH] feat: update theme, put up a direction on how planet open the shop --- apps/gamejam/brackeys/13/scenes/planet.tscn | 19 ++ .../gamejam/brackeys/13/scenes/shop/shop.tscn | 2 + apps/gamejam/brackeys/13/scripts/planet.gd | 21 ++ apps/gamejam/brackeys/13/scripts/shop.gd | 201 +++++++++--------- apps/gamejam/brackeys/13/theme/Theme.tres | 10 +- 5 files changed, 151 insertions(+), 102 deletions(-) create mode 100644 apps/gamejam/brackeys/13/scenes/planet.tscn create mode 100644 apps/gamejam/brackeys/13/scripts/planet.gd diff --git a/apps/gamejam/brackeys/13/scenes/planet.tscn b/apps/gamejam/brackeys/13/scenes/planet.tscn new file mode 100644 index 000000000..823fb0404 --- /dev/null +++ b/apps/gamejam/brackeys/13/scenes/planet.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=4 format=3 uid="uid://c772pj7ujqm8m"] + +[ext_resource type="Script" path="res://scripts/planet.gd" id="1_x2mqs"] +[ext_resource type="Texture2D" uid="uid://dcrqllgsdaexs" path="res://assets/audioknobs-ui/audioknobs/green-light-off.png" id="2_f0omh"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_lpow5"] +radius = 6.0 + +[node name="Planet" type="Area2D"] +script = ExtResource("1_x2mqs") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("2_f0omh") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_lpow5") + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] +[connection signal="body_exited" from="." to="." method="_on_body_exited"] diff --git a/apps/gamejam/brackeys/13/scenes/shop/shop.tscn b/apps/gamejam/brackeys/13/scenes/shop/shop.tscn index fd641f9cf..176675324 100644 --- a/apps/gamejam/brackeys/13/scenes/shop/shop.tscn +++ b/apps/gamejam/brackeys/13/scenes/shop/shop.tscn @@ -27,6 +27,7 @@ expand_margin_right = 20.0 expand_margin_bottom = 10.0 [node name="Shop" type="ColorRect"] +process_mode = 3 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 @@ -405,6 +406,7 @@ script = ExtResource("14_mhgll") lights_on = ExtResource("17_2kql4") lights_off = ExtResource("13_swidh") +[connection signal="pressed" from="HBoxContainer/Label3/Button" to="." method="_on_button_pressed_exit"] [connection signal="pressed" from="MainBG/LeftPanel/HBoxContainer/LeftButton" to="." method="_on_left_button_pressed_left_panel"] [connection signal="pressed" from="MainBG/LeftPanel/HBoxContainer/EnterButton" to="." method="_on_enter_button_pressed_left_panel"] [connection signal="pressed" from="MainBG/LeftPanel/HBoxContainer/RightButton" to="." method="_on_right_button_pressed_left_panel"] diff --git a/apps/gamejam/brackeys/13/scripts/planet.gd b/apps/gamejam/brackeys/13/scripts/planet.gd new file mode 100644 index 000000000..f7cc70907 --- /dev/null +++ b/apps/gamejam/brackeys/13/scripts/planet.gd @@ -0,0 +1,21 @@ +extends Area2D + +#onready var shop := shop_path in the game scene + + +func _on_body_entered(body) -> void: + if body is Spaceship: + # Show button that can open the shop + # if clicked: + # get_tree().paused = true - Pause game + # shop.show() - Show shop + # animation_shop_open.play() - Animation opening the shop + pass + + # On the shop, when pressing the top right button, it exits/hide the shop/reverse the animation, + # and then unpause the game + +func _on_body_exited(body): + if body is Spaceship: + # hide the button + pass # Replace with function body. diff --git a/apps/gamejam/brackeys/13/scripts/shop.gd b/apps/gamejam/brackeys/13/scripts/shop.gd index 85063330c..5f65a1030 100644 --- a/apps/gamejam/brackeys/13/scripts/shop.gd +++ b/apps/gamejam/brackeys/13/scripts/shop.gd @@ -36,159 +36,164 @@ var is_on_confirm := false var chosen_upgrade var shown_text var weapons := [ - {"name": "+1 laser speed", "stat_name": "laser_speed", "value": 1.0, "cost": - {"stone": 200.0, "metal": 50.0}}, - {"name": "+1 ammo count", "stat_name": "laser_ammo", "value": 1.0, "cost": - {"gems": 10, "gold": 5}} + {"name": "+1 laser speed", "stat_name": "laser_speed", "value": 1.0, "cost": + {"stone": 200.0, "metal": 50.0}}, + {"name": "+1 ammo count", "stat_name": "laser_ammo", "value": 1.0, "cost": + {"gems": 10, "gold": 5}} ] var shield := [ - {"name": "None", "stat_name": "none", "value": 1.0, "cost": - {}} + {"name": "None", "stat_name": "none", "value": 1.0, "cost": + {}} ] var power := [ - {"name": "Overheat?", "stat_name": "overheat", "value": 1.0, "cost": - {}} + {"name": "Overheat?", "stat_name": "overheat", "value": 1.0, "cost": + {}} ] var thrusters := [ - {"name": "+1 acceleration", "stat_name": "acceleration", "value": 1.0, "cost": - {}}, - {"name": "+1 rotation speed", "stat_name": "rotation_speed", "value": 1.0, "cost": - {}} + {"name": "+1 acceleration", "stat_name": "acceleration", "value": 1.0, "cost": + {}}, + {"name": "+1 rotation speed", "stat_name": "rotation_speed", "value": 1.0, "cost": + {}} ] var chosen = [weapons, shield, power, thrusters] func _ready(): - update_resource_panel() - update_bottom_panel_screen() + update_resource_panel() + update_bottom_panel_screen() #region LeftPanelRegion func _on_left_button_pressed_left_panel() -> void: - if cate_selected == categories[0]: - pass - else: - current_category -= 1 - update_categories() + if cate_selected == categories[0]: + pass + else: + current_category -= 1 + update_categories() func _on_right_button_pressed_left_panel() -> void: - if cate_selected == categories[3]: - pass - else: - current_category += 1 - update_categories() + if cate_selected == categories[3]: + pass + else: + current_category += 1 + update_categories() func update_categories() -> void: - cate_selected = categories[current_category] - categories_label.text = cate_selected + cate_selected = categories[current_category] + categories_label.text = cate_selected func _on_enter_button_pressed_left_panel() -> void: - shown_text = chunk_array(chosen[current_category], 4) - unshow_confirm_upgrade() # unshow when the confirm text when switching categories - update_parts() + shown_text = chunk_array(chosen[current_category], 4) + unshow_confirm_upgrade() # unshow when the confirm text when switching categories + update_parts() func update_parts() -> void: - center_label_left.text = shown_text[current_parts][0].name + "\n" + shown_text[current_parts][1].name - center_label_right.text = shown_text[current_parts][2].name + "\n" + shown_text[current_parts][3].name + center_label_left.text = shown_text[current_parts][0].name + "\n" + shown_text[current_parts][1].name + center_label_right.text = shown_text[current_parts][2].name + "\n" + shown_text[current_parts][3].name func chunk_array(base: Array, t_size: int) -> Array: - var result = [] - for i in range(0, base.size(), t_size): - var chunk = base.slice(i, i + t_size) # Get up to 'size' elements - while chunk.size() < t_size: # Fill missing spots with "empty" - chunk.append({"name": "", "stat": "none", "value": 0.0}) - result.append(chunk) - return result + var result = [] + for i in range(0, base.size(), t_size): + var chunk = base.slice(i, i + t_size) # Get up to 'size' elements + while chunk.size() < t_size: # Fill missing spots with "empty" + chunk.append({"name": "", "stat": "none", "value": 0.0}) + result.append(chunk) + return result #endregion #region Center Panel func _on_button_1_left_pressed() -> void: - show_confirm_upgrade(0) + show_confirm_upgrade(0) func _on_button_2_left_pressed() -> void: - show_confirm_upgrade(1) + show_confirm_upgrade(1) func _on_button_3_left_pressed() -> void: - if shown_text != null: - current_parts -= 1 - current_parts = clamp(current_parts, 0, shown_text.size() - 1) - update_parts() + if shown_text != null: + current_parts -= 1 + current_parts = clamp(current_parts, 0, shown_text.size() - 1) + update_parts() func _on_button_right_pressed() -> void: - if is_on_confirm: # Confirm upgrade - if can_afford(): - Global.apply_starship_bonus(chosen_upgrade.stat_name, chosen_upgrade.value) - update_resource_panel() - update_bottom_panel_screen() - print("bought") - green_light.texture = green_light_on - await get_tree().create_timer(1.0).timeout - green_light.texture = green_light_off - else: - red_light.texture = red_light_on - await get_tree().create_timer(1.0).timeout - red_light.texture = red_light_off - else: - show_confirm_upgrade(2) + if is_on_confirm: # Confirm upgrade + if can_afford(): + Global.apply_starship_bonus(chosen_upgrade.stat_name, chosen_upgrade.value) + update_resource_panel() + update_bottom_panel_screen() + print("bought") + green_light.texture = green_light_on + await get_tree().create_timer(1.0).timeout + green_light.texture = green_light_off + else: + red_light.texture = red_light_on + await get_tree().create_timer(1.0).timeout + red_light.texture = red_light_off + else: + show_confirm_upgrade(2) func can_afford() -> bool: - var cost = chosen_upgrade.get("cost", {}) - for resource in cost.keys(): - if Global.resources.get(resource, 0) < cost[resource]: - return false # Not enough resources - return true # Upgrade is affordable + var cost = chosen_upgrade.get("cost", {}) + for resource in cost.keys(): + if Global.resources.get(resource, 0) < cost[resource]: + return false # Not enough resources + return true # Upgrade is affordable func _on_button_2_right_pressed() -> void: - if is_on_confirm: # Cancel upgrade - unshow_confirm_upgrade() - update_parts() - else: - show_confirm_upgrade(3) + if is_on_confirm: # Cancel upgrade + unshow_confirm_upgrade() + update_parts() + else: + show_confirm_upgrade(3) func _on_button_right_3_pressed() -> void: - if shown_text != null: - current_parts += 1 - current_parts = clamp(current_parts, 0, shown_text.size() - 1) - update_parts() + if shown_text != null: + current_parts += 1 + current_parts = clamp(current_parts, 0, shown_text.size() - 1) + update_parts() func show_confirm_upgrade(button: int) -> void: - if shown_text != null: - if shown_text[current_parts][button].name != "": - is_on_confirm = true - chosen_upgrade = shown_text[current_parts][button] - center_label_left.text = chosen_upgrade.name - center_label_right.text = "Confirm" + "\n" + "Cancel" - center_label_bottom.text = "" - button_1_left.disabled = true - button_2_left.disabled = true - button_3_left.disabled = true - button_3_right.disabled = true + if shown_text != null: + if shown_text[current_parts][button].name != "": + is_on_confirm = true + chosen_upgrade = shown_text[current_parts][button] + center_label_left.text = chosen_upgrade.name + center_label_right.text = "Confirm" + "\n" + "Cancel" + center_label_bottom.text = "" + button_1_left.disabled = true + button_2_left.disabled = true + button_3_left.disabled = true + button_3_right.disabled = true func unshow_confirm_upgrade() -> void: - is_on_confirm = false - button_1_left.disabled = false - button_2_left.disabled = false - button_3_left.disabled = false - button_3_right.disabled = false - center_label_bottom.text = "Left Right" + is_on_confirm = false + button_1_left.disabled = false + button_2_left.disabled = false + button_3_left.disabled = false + button_3_right.disabled = false + center_label_bottom.text = "Left Right" #endregion func update_resource_panel() -> void: - var full_text = "" - for i in Global.resources.keys(): - full_text += "%s: %d " % [i.capitalize(), Global.resources[i]] - resource_panel.text = full_text + var full_text = "" + for i in Global.resources.keys(): + full_text += "%s: %d " % [i.capitalize(), Global.resources[i]] + resource_panel.text = full_text func update_bottom_panel_screen() -> void: - var full_text = "" - for i in Global.base_starship_stats.keys(): - full_text += "%s: %d " % [i.capitalize(), Global.base_starship_stats[i] + Global.starship_bonuses[i]] - bottom_panel_screen_label.text = full_text + var full_text = "" + for i in Global.base_starship_stats.keys(): + full_text += "%s: %d " % [i.capitalize(), Global.base_starship_stats[i] + Global.starship_bonuses[i]] + bottom_panel_screen_label.text = full_text + +func _on_button_pressed_exit(): # Hides the shop on exit + self.hide() + get_tree().paused = false + pass diff --git a/apps/gamejam/brackeys/13/theme/Theme.tres b/apps/gamejam/brackeys/13/theme/Theme.tres index 69e620b2e..4c7c7d54c 100644 --- a/apps/gamejam/brackeys/13/theme/Theme.tres +++ b/apps/gamejam/brackeys/13/theme/Theme.tres @@ -30,11 +30,11 @@ bg_color = Color(0.6, 0.6, 0.6, 0) texture = ExtResource("4_4s0nj") texture_margin_top = 20.0 -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_2n2so"] - [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_nfv2t"] texture = ExtResource("6_oemoe") +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_2n2so"] + [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_bnh2f"] texture = ExtResource("7_s6l0y") @@ -46,11 +46,11 @@ axis_stretch_vertical = 1 texture = ExtResource("7_f3kbi") axis_stretch_vertical = 1 -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_xiin7"] - [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_0f342"] texture = ExtResource("9_0vmdh") +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_xiin7"] + [sub_resource type="StyleBoxTexture" id="StyleBoxTexture_4rt04"] texture = ExtResource("12_0ebru") @@ -83,6 +83,7 @@ HSlider/styles/grabber_area = SubResource("StyleBoxFlat_64pwo") HSlider/styles/grabber_area_highlight = SubResource("StyleBoxFlat_64pwo") HSlider/styles/slider = SubResource("StyleBoxTexture_upa0w") LeftButton/base_type = &"Button" +LeftButton/styles/disabled = SubResource("StyleBoxTexture_nfv2t") LeftButton/styles/focus = SubResource("StyleBoxEmpty_2n2so") LeftButton/styles/hover = SubResource("StyleBoxTexture_nfv2t") LeftButton/styles/hover_pressed = SubResource("StyleBoxTexture_bnh2f") @@ -92,6 +93,7 @@ MarginContainer/icons/texture = ExtResource("2_wr8kl") ProgressBar/styles/background = SubResource("StyleBoxTexture_umxe3") ProgressBar/styles/fill = SubResource("StyleBoxTexture_es6xy") RightButton/base_type = &"Button" +RightButton/styles/disabled = SubResource("StyleBoxTexture_0f342") RightButton/styles/focus = SubResource("StyleBoxEmpty_xiin7") RightButton/styles/hover = SubResource("StyleBoxTexture_0f342") RightButton/styles/hover_pressed = SubResource("StyleBoxTexture_4rt04")