From bb963db15ff422f58d6ebfaad28aeecc2d19ce57 Mon Sep 17 00:00:00 2001 From: Benjamin Morgan Date: Tue, 21 Oct 2025 21:38:06 -0600 Subject: [PATCH] Added credits screen off of main menu --- Scenes/credits.gd | 47 +++++++++++++++++++++++++++++++++++ Scenes/credits.gd.uid | 1 + Scenes/credits.tscn | 58 +++++++++++++++++++++++++++++++++++++++++++ Scenes/game_over.tscn | 8 +++--- Scenes/main_menu.tscn | 32 ++++++++++++++++-------- Scripts/game.gd | 26 +++++++++++++++---- Scripts/main_menu.gd | 20 ++++++++------- Scripts/ship.gd | 2 +- 8 files changed, 165 insertions(+), 29 deletions(-) create mode 100644 Scenes/credits.gd create mode 100644 Scenes/credits.gd.uid create mode 100644 Scenes/credits.tscn diff --git a/Scenes/credits.gd b/Scenes/credits.gd new file mode 100644 index 0000000..498cd7f --- /dev/null +++ b/Scenes/credits.gd @@ -0,0 +1,47 @@ +extends Control + +@onready var grid: GridContainer = $Columns + +signal main_menu + +const CREDIT_LABELS_LINKS := { + "Godot Engine" : ["Godot Team : godotengine.org", "https://godotengine.org"], + "Ship and Enemies" : ["bart : opengameart.org", "https://opengameart.org/content/i-are-spaceship-16x16-space-sprites"], + "Starry Background" : ["Kutejnikov : opengameart.org", "https://opengameart.org/content/space-9"], + "Laser Sound" : ["dklon : opengameart.org", "https://opengameart.org/content/laser-fire"], + "Explosion Sounds" : ["TeamAlpha : opengameart.org", "https://opengameart.org/content/8-bitnes-explosion-sound-effecs"], + "Extra Life Jingle" : ["Mrthenoronha : freesound.org", "https://freesound.org/people/Mrthenoronha/sounds/518306/"] +} + +const LEFT_COL_WIDTH := 300 +const RIGHT_COL_WIDTH := 300 + +func _ready() -> void: + $Back.pressed.connect(_emit_back) + + # center the grid + grid.anchor_left = 0.5 + grid.anchor_right = 0.5 + grid.offset_left = int(-(LEFT_COL_WIDTH + RIGHT_COL_WIDTH) / 2.0) + grid.offset_right = int((LEFT_COL_WIDTH + RIGHT_COL_WIDTH) / 2.0) + + for btn_name in CREDIT_LABELS_LINKS.keys(): + var display_text = CREDIT_LABELS_LINKS[btn_name][0] + var link: String = CREDIT_LABELS_LINKS[btn_name][1] + + var label = Label.new() + label.text = btn_name + label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + label.custom_minimum_size.x = LEFT_COL_WIDTH + grid.add_child(label) + + var button = Button.new() + button.text = display_text + button.focus_mode = Control.FOCUS_NONE + button.custom_minimum_size.x = RIGHT_COL_WIDTH + var link_local := link + button.pressed.connect(func(): OS.shell_open(link_local)) + grid.add_child(button) + +func _emit_back(): + emit_signal("main_menu") diff --git a/Scenes/credits.gd.uid b/Scenes/credits.gd.uid new file mode 100644 index 0000000..8c10826 --- /dev/null +++ b/Scenes/credits.gd.uid @@ -0,0 +1 @@ +uid://dinqb3ubrx76h diff --git a/Scenes/credits.tscn b/Scenes/credits.tscn new file mode 100644 index 0000000..3ac5c46 --- /dev/null +++ b/Scenes/credits.tscn @@ -0,0 +1,58 @@ +[gd_scene load_steps=3 format=3 uid="uid://dylsy7qq16t6e"] + +[ext_resource type="Script" uid="uid://dinqb3ubrx76h" path="res://Scenes/credits.gd" id="1_r18jl"] + +[sub_resource type="LabelSettings" id="LabelSettings_gryuy"] +font_size = 36 + +[node name="Control" type="Control"] +layout_mode = 3 +anchors_preset = 13 +anchor_left = 0.5 +anchor_right = 0.5 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_r18jl") + +[node name="Title" type="Label" parent="."] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -61.5 +offset_top = 35.0 +offset_right = 61.5 +offset_bottom = 85.0 +grow_horizontal = 2 +text = "Credits" +label_settings = SubResource("LabelSettings_gryuy") + +[node name="Columns" type="GridContainer" parent="."] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -20.0 +offset_top = 100.0 +offset_right = 20.0 +offset_bottom = 140.0 +grow_horizontal = 2 +theme_override_constants/h_separation = 30 +theme_override_constants/v_separation = 5 +columns = 2 + +[node name="Back" type="Button" parent="."] +layout_mode = 1 +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -50.0 +offset_top = -73.0 +offset_right = 50.0 +offset_bottom = -38.0 +grow_horizontal = 2 +grow_vertical = 0 +text = "Back" diff --git a/Scenes/game_over.tscn b/Scenes/game_over.tscn index 1a2407a..901648f 100644 --- a/Scenes/game_over.tscn +++ b/Scenes/game_over.tscn @@ -59,9 +59,9 @@ layout_mode = 1 anchors_preset = 5 anchor_left = 0.5 anchor_right = 0.5 -offset_left = -46.5 -offset_top = 150.0 -offset_right = 46.5 -offset_bottom = 181.0 +offset_left = -75.0 +offset_top = 155.0 +offset_right = 75.0 +offset_bottom = 190.0 grow_horizontal = 2 text = "New Game" diff --git a/Scenes/main_menu.tscn b/Scenes/main_menu.tscn index 0ccec31..640b2b6 100644 --- a/Scenes/main_menu.tscn +++ b/Scenes/main_menu.tscn @@ -21,8 +21,8 @@ anchors_preset = 13 anchor_left = 0.5 anchor_right = 0.5 anchor_bottom = 1.0 -offset_top = -100.0 -offset_bottom = -100.0 +offset_top = -120.0 +offset_bottom = -120.0 grow_horizontal = 2 grow_vertical = 2 @@ -44,10 +44,10 @@ layout_mode = 1 anchors_preset = 5 anchor_left = 0.5 anchor_right = 0.5 -offset_left = -46.5 -offset_top = 111.0 -offset_right = 46.5 -offset_bottom = 142.0 +offset_left = -75.0 +offset_top = 105.0 +offset_right = 75.0 +offset_bottom = 140.0 grow_horizontal = 2 text = "New Game" @@ -56,9 +56,21 @@ layout_mode = 1 anchors_preset = 5 anchor_left = 0.5 anchor_right = 0.5 -offset_left = -46.5 -offset_top = 150.0 -offset_right = 46.5 -offset_bottom = 181.0 +offset_left = -75.0 +offset_top = 205.0 +offset_right = 75.0 +offset_bottom = 240.0 grow_horizontal = 2 text = "Quit" + +[node name="Credits" type="Button" parent="Container"] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -75.0 +offset_top = 155.0 +offset_right = 75.0 +offset_bottom = 190.0 +grow_horizontal = 2 +text = "Credits" diff --git a/Scripts/game.gd b/Scripts/game.gd index 140b5ba..affcd4b 100644 --- a/Scripts/game.gd +++ b/Scripts/game.gd @@ -10,19 +10,17 @@ var player: CharacterBody2D var ui: CanvasLayer var game_over_ui: Control var menu_ui: Control +var credits_ui: Control var life_icon = preload("res://Scenes/life.tscn") var menu_scn = preload("res://Scenes/main_menu.tscn") +var credits_scn = preload("res://Scenes/credits.tscn") var game_over_scn = preload("res://Scenes/game_over.tscn") var ship = preload("res://Scenes/ship.tscn") var life = preload("res://Sounds/extra_life.wav") func _ready() -> void: - menu_ui = menu_scn.instantiate() - menu_ui.new_game.connect(_new_game) - menu_ui.quit_game.connect(_quit_game) - await get_tree().process_frame - ui.add_child(menu_ui) + _main_menu() func set_score(amount: int): score = amount @@ -84,5 +82,23 @@ func _new_game(): get_tree().current_scene.add_child(player) +func _credits(): + if menu_ui: + menu_ui.queue_free() + + credits_ui = credits_scn.instantiate() + credits_ui.connect("main_menu", _main_menu) + ui.add_child(credits_ui) + +func _main_menu(): + if credits_ui: + credits_ui.queue_free() + + menu_ui = menu_scn.instantiate() + menu_ui.new_game.connect(_new_game) + menu_ui.credits.connect(_credits) + menu_ui.quit_game.connect(_quit_game) + ui.add_child(menu_ui) + func _quit_game(): get_tree().quit() diff --git a/Scripts/main_menu.gd b/Scripts/main_menu.gd index c2d8321..3b51057 100644 --- a/Scripts/main_menu.gd +++ b/Scripts/main_menu.gd @@ -1,14 +1,16 @@ extends Control signal new_game +signal credits signal quit_game -func _ready(): - $"Container/New Game".pressed.connect(_emit_new) - $Container/Quit.pressed.connect(_emit_quit) - -func _emit_new(): - emit_signal("new_game") - -func _emit_quit(): - emit_signal("quit_game") +func _ready() -> void: + var buttons = { + "New Game": "new_game", + "Credits": "credits", + "Quit": "quit_game", + } + + for btn_name in buttons.keys(): + var btn = $Container.get_node(btn_name) + btn.pressed.connect(func(): emit_signal(buttons[btn_name])) diff --git a/Scripts/ship.gd b/Scripts/ship.gd index 60631ad..3a1a24e 100644 --- a/Scripts/ship.gd +++ b/Scripts/ship.gd @@ -74,7 +74,7 @@ func _physics_process(delta: float) -> void: last_shot = 0.0 func die(): - position = get_viewport_rect().size / 2 + position = get_viewport_rect().size speed = Vector2(0, 0) inv_time = 3.0 -- 2.47.2