Added a pause menu

It was actually not that difficult surprisingly. Adding this was pretty
fun.
This commit is contained in:
Puppet committed 2025-10-12 18:31:46 -07:00
1 parent 330258f987
commit 66ca286ea9
9 files changed
+160 -14

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
[gd_scene load_steps=8 format=3 uid="uid://cs22tndewcohw"]
[ext_resource type="FontFile" uid="uid://dq7nkk7n7wrq4" path="res://Fonts/Lexend.ttf" id="1_lj4oq"]
[ext_resource type="Script" uid="uid://bc4miccifwrk0" path="res://Scripts/SceneSwitcher.cs" id="2_qwhev"]
[ext_resource type="Script" uid="uid://cmvj0ubia5hbv" path="res://Scripts/PauseMenuContinueButton.cs" id="3_5w4ur"]
[ext_resource type="Script" uid="uid://cqvgtx6usjjys" path="res://Scripts/BackToMenuLogic.cs" id="3_ey1tb"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qwhev"]
bg_color = Color(1, 1, 1, 1)
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_5w4ur"]
bg_color = Color(0.830335, 0.830335, 0.830335, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ey1tb"]
bg_color = Color(0.95158, 0.95158, 0.95158, 1)
[node name="PauseMenu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Background" 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, 0, 0, 0.49803922)
[node name="Buttons" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -250.0
offset_top = -75.0
offset_right = 250.0
offset_bottom = 75.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 50
alignment = 1
[node name="Menu" type="Button" parent="Buttons"]
custom_minimum_size = Vector2(500, 0)
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_colors/font_focus_color = Color(0, 0, 0, 1)
theme_override_colors/font_pressed_color = Color(0, 0, 0, 1)
theme_override_colors/font_hover_color = Color(0, 0, 0, 1)
theme_override_colors/font_hover_pressed_color = Color(0, 0, 0, 1)
theme_override_colors/font_disabled_color = Color(0, 0, 0, 1)
theme_override_fonts/font = ExtResource("1_lj4oq")
theme_override_font_sizes/font_size = 56
theme_override_styles/normal = SubResource("StyleBoxFlat_qwhev")
theme_override_styles/pressed = SubResource("StyleBoxFlat_5w4ur")
theme_override_styles/hover = SubResource("StyleBoxFlat_ey1tb")
text = "Back to Menu"
script = ExtResource("2_qwhev")
ScenePath = "res://Scenes/MainMenu.tscn"
[node name="BackToMenuLogic" type="Control" parent="Buttons/Menu"]
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0
script = ExtResource("3_ey1tb")
[node name="Continue" type="Button" parent="Buttons"]
custom_minimum_size = Vector2(500, 0)
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_colors/font_focus_color = Color(0, 0, 0, 1)
theme_override_colors/font_pressed_color = Color(0, 0, 0, 1)
theme_override_colors/font_hover_color = Color(0, 0, 0, 1)
theme_override_colors/font_hover_pressed_color = Color(0, 0, 0, 1)
theme_override_colors/font_disabled_color = Color(0, 0, 0, 1)
theme_override_fonts/font = ExtResource("1_lj4oq")
theme_override_font_sizes/font_size = 56
theme_override_styles/normal = SubResource("StyleBoxFlat_qwhev")
theme_override_styles/pressed = SubResource("StyleBoxFlat_5w4ur")
theme_override_styles/hover = SubResource("StyleBoxFlat_ey1tb")
text = "Continue"
script = ExtResource("3_5w4ur")
[connection signal="button_up" from="Buttons/Menu" to="Buttons/Menu/BackToMenuLogic" method="_on_menu_button_up"]
[connection signal="button_up" from="Buttons/Continue" to="Buttons/Continue" method="_on_button_up"]
+13
View File
@@ -0,0 +1,13 @@
using Godot;
using System;
public partial class BackToMenuLogic : Control {
public void _on_menu_button_up() {
Globals.IsPaused = false;
Globals.Score = 0;
Globals.ActiveEffect = "none";
Globals.EffectTimer = 0f;
BazookaManager.Write(BazookaManager.HighScore, Globals.HighScore.ToString());
}
}
+1
View File
@@ -0,0 +1 @@
uid://cqvgtx6usjjys
+5 -2
View File
@@ -6,9 +6,12 @@ public partial class Berries : Node2D {
public override void _Process(double delta) {
Vector2 Pos = Position;
Pos.Y += 500f * (float)delta;
SpawnBerryTimer += (float)delta;
if (!Globals.IsPaused) {
Pos.Y += 500f * (float)delta;
SpawnBerryTimer += (float)delta;
}
int ScreenWidth = DisplayServer.WindowGetSize().X;
+1
View File
@@ -18,4 +18,5 @@ public partial class Globals : Node {
public static int Score = 0;
public static int HighScore = 0;
public static bool IsPaused = false;
}
+9
View File
@@ -0,0 +1,9 @@
using Godot;
using System;
public partial class PauseMenuContinueButton : Button {
public void _on_button_up() {
Globals.IsPaused = false;
GetNode<Control>("../..").QueueFree();
}
}
+1
View File
@@ -0,0 +1 @@
uid://cmvj0ubia5hbv
+26 -12
View File
@@ -17,19 +17,21 @@ public partial class Player : Node2D {
Vector2 Pos = Position;
// Pos.Y = (WindowSize.Y / WindowScale.Y) - 100;
if ((Input.IsKeyPressed((Key)Key.Left) || Input.IsKeyPressed((Key)Key.A)) && Pos.X > ScreenBorders) {
GetNode<Sprite2D>("Texture").FlipH = false;
Pos.X -= Globals.MovementSpeed * (float)delta;
}
if (!Globals.IsPaused) {
if ((Input.IsKeyPressed((Key)Key.Left) || Input.IsKeyPressed((Key)Key.A)) && Pos.X > ScreenBorders) {
GetNode<Sprite2D>("Texture").FlipH = false;
Pos.X -= Globals.MovementSpeed * (float)delta;
}
float ScreenWidth = (WindowSize.X / WindowScale.X) - ScreenBorders;
if ((Input.IsKeyPressed((Key)Key.Right) || Input.IsKeyPressed((Key)Key.D)) && Pos.X < ScreenWidth) {
GetNode<Sprite2D>("Texture").FlipH = true;
Pos.X += Globals.MovementSpeed * (float)delta;
}
float ScreenWidth = (WindowSize.X / WindowScale.X) - ScreenBorders;
if ((Input.IsKeyPressed((Key)Key.Right) || Input.IsKeyPressed((Key)Key.D)) && Pos.X < ScreenWidth) {
GetNode<Sprite2D>("Texture").FlipH = true;
Pos.X += Globals.MovementSpeed * (float)delta;
}
if (Input.IsKeyPressed((Key)Key.Space) && Pos.Y >= 976) {
VelocityY = Globals.JumpHeight;
if (Input.IsKeyPressed((Key)Key.Space) && Pos.Y >= 976) {
VelocityY = Globals.JumpHeight;
}
}
if (VelocityY < 0.3f) {
@@ -46,7 +48,7 @@ public partial class Player : Node2D {
Position = Pos;
// Effect handling
if (Globals.ActiveEffect != "none") {
if (Globals.ActiveEffect != "none" && !Globals.IsPaused) {
Globals.EffectTimer -= (float)delta;
}
@@ -62,5 +64,17 @@ public partial class Player : Node2D {
} else if (Globals.ActiveEffect == "slow") {
Globals.MovementSpeed = Globals.DefaultMovementSpeed / 2f;
}
if (Input.IsActionJustPressed("EscapeKey")) {
PackedScene PauseMenu = GD.Load<PackedScene>("res://Scenes/PauseMenu.tscn");
Control PauseMenuInstance = PauseMenu.Instantiate<Control>();
PauseMenuInstance.Position = new Vector2(x: 0, y: 0);
PauseMenuInstance.ZIndex = -1;
GetNode<CanvasLayer>("/root/Game/CanvasLayer").AddChild(PauseMenuInstance);
Globals.IsPaused = true;
}
}
}
+8
View File
@@ -32,6 +32,14 @@ window/vsync/vsync_mode=0
project/assembly_name="Berry Dash Godot Remake"
[input]
EscapeKey={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
[rendering]
environment/defaults/default_clear_color=Color(0.0627451, 0.0627451, 0.0627451, 1)