Add menu system and scene navigation

The changes include: - Moving script files to scripts/ directory -
Creating Start menu scene with Play/Quit buttons - Adding scene
switching between menu and gameplay - Creating theme for menu buttons -
Adding ESC key to return to menu
This commit is contained in:
Henry 2025-10-12 13:20:30 +01:00
parent 83ff6ef14d
commit 49988ae674
14 changed files with 202 additions and 6 deletions

13
scenes/Main.tscn Normal file
View file

@ -0,0 +1,13 @@
[gd_scene load_steps=4 format=3 uid="uid://dy4s4as4b07s8"]
[ext_resource type="Script" uid="uid://bi1hbvswrw6yr" path="res://scripts/main.gd" id="1_0bbpv"]
[ext_resource type="PackedScene" uid="uid://d04c3lqwj6a5h" path="res://scenes/Start.tscn" id="2_rarhs"]
[ext_resource type="PackedScene" uid="uid://ct7v3x7imstlk" path="res://scenes/gameplay.tscn" id="3_vcsgt"]
[node name="Main" type="Node2D"]
script = ExtResource("1_0bbpv")
[node name="Start" parent="." instance=ExtResource("2_rarhs")]
z_index = 5
[node name="Gameplay" parent="." instance=ExtResource("3_vcsgt")]

55
scenes/Start.tscn Normal file
View file

@ -0,0 +1,55 @@
[gd_scene load_steps=4 format=3 uid="uid://d04c3lqwj6a5h"]
[ext_resource type="Script" uid="uid://d3rocjpvkb3te" path="res://scripts/start.gd" id="1_r305v"]
[ext_resource type="Theme" uid="uid://cga6aww0tbilq" path="res://resources/pong_theme.tres" id="3_gx2gx"]
[sub_resource type="GDScript" id="GDScript_fx3ca"]
script/source = "extends VBoxContainer
"
[node name="Start" 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_r305v")
[node name="ColorRect" type="ColorRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.29000002, 0.402, 0.5, 1)
[node name="CenterContainer" type="CenterContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
layout_mode = 2
theme_override_constants/separation = 175
script = SubResource("GDScript_fx3ca")
[node name="Button_Play" type="Button" parent="CenterContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("3_gx2gx")
theme_override_colors/font_color = Color(0.87, 0.87, 0.87, 1)
theme_override_constants/outline_size = 2
text = "Play"
[node name="Button_Quit" type="Button" parent="CenterContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("3_gx2gx")
theme_override_colors/font_color = Color(0.87, 0.87, 0.87, 1)
theme_override_constants/outline_size = 2
text = "Quit"

110
scenes/gameplay.tscn Normal file
View file

@ -0,0 +1,110 @@
[gd_scene load_steps=6 format=3 uid="uid://ct7v3x7imstlk"]
[ext_resource type="PackedScene" uid="uid://dd0cxfceqwxca" path="res://prefabs/paddle.tscn" id="1_80nbo"]
[ext_resource type="Script" uid="uid://8lo33im7wrya" path="res://scripts/gameplay.gd" id="1_oe8ih"]
[ext_resource type="Script" uid="uid://wrequpaalk7f" path="res://scripts/ball.gd" id="2_e2o6t"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mwb40"]
size = Vector2(1200, 20)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_feb5d"]
[node name="Gameplay" 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_oe8ih")
[node name="Background" type="ColorRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = 2.0
offset_bottom = 2.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.184063, 0.191379, 0.203873, 1)
[node name="MiddleLine" type="ColorRect" parent="."]
custom_minimum_size = Vector2(4, 0)
layout_mode = 1
anchors_preset = 13
anchor_left = 0.5
anchor_right = 0.5
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.938114, 0.940897, 0.945648, 1)
[node name="TopWall" type="StaticBody2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="TopWall"]
position = Vector2(571, 0)
shape = SubResource("RectangleShape2D_mwb40")
[node name="Polygon2D" type="Polygon2D" parent="TopWall"]
polygon = PackedVector2Array(-30, -10, -30, 10, 1172, 10, 1172, -10)
[node name="BottomWall" type="StaticBody2D" parent="."]
position = Vector2(0, 649)
[node name="CollisionShape2D" type="CollisionShape2D" parent="BottomWall"]
position = Vector2(571, 0)
shape = SubResource("RectangleShape2D_mwb40")
[node name="Polygon2D" type="Polygon2D" parent="BottomWall"]
polygon = PackedVector2Array(-30, -10, -30, 10, 1172, 10, 1172, -10)
[node name="Paddle-0" parent="." node_paths=PackedStringArray("score_label") instance=ExtResource("1_80nbo")]
position = Vector2(40, 273)
score_label = NodePath("../HBoxContainer/Score-0")
[node name="Paddle-1" parent="." node_paths=PackedStringArray("score_label") instance=ExtResource("1_80nbo")]
position = Vector2(1078, 273)
player_id = 1
score_label = NodePath("../HBoxContainer/Score-1")
[node name="Ball" type="CharacterBody2D" parent="." node_paths=PackedStringArray("paddle_0", "paddle_1")]
position = Vector2(134, 72)
motion_mode = 1
script = ExtResource("2_e2o6t")
paddle_0 = NodePath("../Paddle-0")
paddle_1 = NodePath("../Paddle-1")
[node name="Polygon2D" type="Polygon2D" parent="Ball"]
polygon = PackedVector2Array(100, 75, 120, 75, 120, 95, 100, 95)
[node name="CollisionShape2D" type="CollisionShape2D" parent="Ball"]
position = Vector2(110, 85)
shape = SubResource("RectangleShape2D_feb5d")
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="Ball"]
position = Vector2(110, 85)
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 10
anchor_right = 1.0
offset_top = 20.0
offset_bottom = 75.0
grow_horizontal = 2
[node name="Score-0" type="Label" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_font_sizes/font_size = 40
text = "00"
horizontal_alignment = 1
[node name="Score-1" type="Label" parent="HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_font_sizes/font_size = 40
text = "00"
horizontal_alignment = 1
[connection signal="screen_exited" from="Ball/VisibleOnScreenNotifier2D" to="Ball" method="_on_screen_exited"]