Adds restart/return to main menu options after finishing run

master
TechieDamien 2025-07-31 16:13:53 +01:00
parent b32eee2d6c
commit 823d57a446
Signed by: TechieDamien
GPG Key ID: 2ACE3574E164B780
6 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,37 @@
[gd_scene load_steps=3 format=3 uid="uid://bqg3ohs1gwofr"]
[ext_resource type="Script" uid="uid://b8brifkk4knh8" path="res://Scripts/game_over_menu.gd" id="1_arass"]
[sub_resource type="LabelSettings" id="LabelSettings_7upku"]
font_size = 32
[node name="GameOverMenu" type="VBoxContainer" groups=["GameOverMenu"]]
visible = false
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_arass")
[node name="FinalScore" type="Label" parent="."]
layout_mode = 2
text = "Final Score
0"
label_settings = SubResource("LabelSettings_7upku")
horizontal_alignment = 1
[node name="Control" type="Control" parent="."]
layout_mode = 2
size_flags_vertical = 3
[node name="Restart" type="Button" parent="."]
layout_mode = 2
text = "Restart"
[node name="MainMenu" type="Button" parent="."]
layout_mode = 2
text = "Main Menu"
[connection signal="pressed" from="Restart" to="." method="restart"]
[connection signal="pressed" from="MainMenu" to="." method="back"]

View File

@ -1,9 +1,10 @@
[gd_scene load_steps=5 format=3 uid="uid://bs6an72avch86"]
[gd_scene load_steps=6 format=3 uid="uid://bs6an72avch86"]
[ext_resource type="PackedScene" uid="uid://gkqku38yb2ng" path="res://Scenes/level.tscn" id="1_bo1nx"]
[ext_resource type="PackedScene" uid="uid://d0okbjqyaoe0w" path="res://Scenes/snake_part.tscn" id="2_8gbba"]
[ext_resource type="PackedScene" uid="uid://bldekmt1rakjl" path="res://Scenes/fruit.tscn" id="3_8gbba"]
[ext_resource type="PackedScene" uid="uid://mp03fsd536be" path="res://Scenes/score_display.tscn" id="4_jjvhh"]
[ext_resource type="PackedScene" uid="uid://bqg3ohs1gwofr" path="res://Scenes/game_over_menu.tscn" id="5_kry3j"]
[node name="Main" type="Node2D"]
@ -41,5 +42,11 @@ offset_top = 42.0
offset_right = 156.0
offset_bottom = 197.0
[node name="GameOverMenu" parent="." instance=ExtResource("5_kry3j")]
offset_left = 340.0
offset_top = 173.0
offset_right = 812.0
offset_bottom = 475.0
[connection signal="area_exited" from="Level" to="SnakePart" method="_on_level_area_exited"]
[connection signal="timeout" from="RestartTimer" to="Timer" method="start" binds= [0.3]]

15
Scripts/game_over_menu.gd Normal file
View File

@ -0,0 +1,15 @@
extends VBoxContainer
var level : PackedScene = load("res://Scenes/main.tscn")
var main_menu : PackedScene = load("res://Scenes/main_menu.tscn")
@onready
var score_label : Label = $FinalScore
func update_score() -> void:
score_label.text = "Final Score\n{score}".format(GameManager)
func restart():
get_tree().change_scene_to_packed(level)
func back():
get_tree().change_scene_to_packed(main_menu)

View File

@ -0,0 +1 @@
uid://b8brifkk4knh8

View File

@ -31,6 +31,9 @@ var snake_part_obj : PackedScene = preload("res://Scenes/snake_part.tscn")
@onready
var timer_ref : Timer = $"../Timer"
@onready
var game_over_menu : VBoxContainer = get_tree().get_first_node_in_group("GameOverMenu")
var next_part : SnakePart = null
var skip_next_move_propagation : bool = false
var queued_growth : int = 0
@ -227,6 +230,7 @@ func lose_game() -> void:
print("Game lost")
state = States.DEAD
on_death.emit()
game_over_menu.visible = true
func ouroboros() -> void:
print("You have achieved the ouroboros!")
@ -239,6 +243,7 @@ func ouroboros() -> void:
# The head can spawn a new snake
if part_type == PartTypes.HEAD:
GameManager.score += 1
remove_from_group("Head")
get_tree().get_first_node_in_group("GameClockPause").start(1)
get_tree().get_first_node_in_group("GameClock").stop()
spawn_new_snake()

View File

@ -20,6 +20,10 @@ config/icon="res://icon.svg"
GridManager="*res://Scripts/grid_manager.gd"
GameManager="*res://Scripts/game_manager.gd"
[display]
window/stretch/mode="viewport"
[global_group]
Level=""