Added credits screen off of main menu

This commit is contained in:
Benjamin Morgan 2025-10-21 21:38:06 -06:00
parent e46d1066c0
commit e2a9eb2507
5 changed files with 59 additions and 29 deletions

View file

@ -59,9 +59,9 @@ layout_mode = 1
anchors_preset = 5 anchors_preset = 5
anchor_left = 0.5 anchor_left = 0.5
anchor_right = 0.5 anchor_right = 0.5
offset_left = -46.5 offset_left = -75.0
offset_top = 150.0 offset_top = 155.0
offset_right = 46.5 offset_right = 75.0
offset_bottom = 181.0 offset_bottom = 190.0
grow_horizontal = 2 grow_horizontal = 2
text = "New Game" text = "New Game"

View file

@ -21,8 +21,8 @@ anchors_preset = 13
anchor_left = 0.5 anchor_left = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_top = -100.0 offset_top = -120.0
offset_bottom = -100.0 offset_bottom = -120.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
@ -44,10 +44,10 @@ layout_mode = 1
anchors_preset = 5 anchors_preset = 5
anchor_left = 0.5 anchor_left = 0.5
anchor_right = 0.5 anchor_right = 0.5
offset_left = -46.5 offset_left = -75.0
offset_top = 111.0 offset_top = 105.0
offset_right = 46.5 offset_right = 75.0
offset_bottom = 142.0 offset_bottom = 140.0
grow_horizontal = 2 grow_horizontal = 2
text = "New Game" text = "New Game"
@ -56,9 +56,21 @@ layout_mode = 1
anchors_preset = 5 anchors_preset = 5
anchor_left = 0.5 anchor_left = 0.5
anchor_right = 0.5 anchor_right = 0.5
offset_left = -46.5 offset_left = -75.0
offset_top = 150.0 offset_top = 205.0
offset_right = 46.5 offset_right = 75.0
offset_bottom = 181.0 offset_bottom = 240.0
grow_horizontal = 2 grow_horizontal = 2
text = "Quit" 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"

View file

@ -10,19 +10,17 @@ var player: CharacterBody2D
var ui: CanvasLayer var ui: CanvasLayer
var game_over_ui: Control var game_over_ui: Control
var menu_ui: Control var menu_ui: Control
var credits_ui: Control
var life_icon = preload("res://Scenes/life.tscn") var life_icon = preload("res://Scenes/life.tscn")
var menu_scn = preload("res://Scenes/main_menu.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 game_over_scn = preload("res://Scenes/game_over.tscn")
var ship = preload("res://Scenes/ship.tscn") var ship = preload("res://Scenes/ship.tscn")
var life = preload("res://Sounds/extra_life.wav") var life = preload("res://Sounds/extra_life.wav")
func _ready() -> void: 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 await get_tree().process_frame
ui.add_child(menu_ui) _main_menu()
func set_score(amount: int): func set_score(amount: int):
score = amount score = amount
@ -84,5 +82,23 @@ func _new_game():
get_tree().current_scene.add_child(player) 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(): func _quit_game():
get_tree().quit() get_tree().quit()

View file

@ -1,14 +1,16 @@
extends Control extends Control
signal new_game signal new_game
signal credits
signal quit_game signal quit_game
func _ready(): func _ready() -> void:
$"Container/New Game".pressed.connect(_emit_new) var buttons = {
$Container/Quit.pressed.connect(_emit_quit) "New Game": "new_game",
"Credits": "credits",
func _emit_new(): "Quit": "quit_game",
emit_signal("new_game") }
func _emit_quit(): for btn_name in buttons.keys():
emit_signal("quit_game") var btn = $Container.get_node(btn_name)
btn.pressed.connect(func(): emit_signal(buttons[btn_name]))

View file

@ -74,7 +74,7 @@ func _physics_process(delta: float) -> void:
last_shot = 0.0 last_shot = 0.0
func die(): func die():
position = get_viewport_rect().size / 2 position = get_viewport_rect().size
speed = Vector2(0, 0) speed = Vector2(0, 0)
inv_time = 3.0 inv_time = 3.0