From cd0476d9bea814340a0e5de4b2b01ee39656add2 Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Wed, 7 Jan 2026 02:48:07 +0300 Subject: [PATCH] Added pause menu --- game/collision_switcher.gd | 2 +- game/levels/abstract_level.gd | 13 +++++++++ game/levels/abstract_level.tscn | 8 +++++- game/menu/pause_menu.gd | 36 +++++++++++++++++++++++ game/menu/pause_menu.gd.uid | 1 + game/menu/pause_menu.tscn | 51 +++++++++++++++++++++++++++++++++ project.godot | 3 +- 7 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 game/menu/pause_menu.gd create mode 100644 game/menu/pause_menu.gd.uid create mode 100644 game/menu/pause_menu.tscn diff --git a/game/collision_switcher.gd b/game/collision_switcher.gd index efcc609..da0a548 100644 --- a/game/collision_switcher.gd +++ b/game/collision_switcher.gd @@ -79,7 +79,7 @@ func switch_color(time: float = 0.0) -> void: _state = State.Black if _state == State.White else State.White else: _state = State.TransitionToBlack if _state == State.White else State.TransitionToWhite - + _intensity_tween = create_tween() _intensity_tween.tween_method(_set_shader_internsity, 0.0, MAX_INTENSITY, time) _intensity_tween.finished.connect(_update_state) diff --git a/game/levels/abstract_level.gd b/game/levels/abstract_level.gd index a88774e..ae37181 100644 --- a/game/levels/abstract_level.gd +++ b/game/levels/abstract_level.gd @@ -1,2 +1,15 @@ class_name AbstractLevel extends Node2D + + +@onready var pause_menu : PauseMenu = $%PauseMenu + + +func _ready() -> void: + pause_menu.hide() + + +func _input(event: InputEvent) -> void: + if event.is_action_pressed("pause"): + get_tree().paused = true + pause_menu.show() diff --git a/game/levels/abstract_level.tscn b/game/levels/abstract_level.tscn index 56adcd8..fdcfd7f 100644 --- a/game/levels/abstract_level.tscn +++ b/game/levels/abstract_level.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=3 uid="uid://mpsu4g2b5h3a"] +[gd_scene load_steps=14 format=3 uid="uid://mpsu4g2b5h3a"] [ext_resource type="Script" uid="uid://c737mx0kxva7i" path="res://game/levels/abstract_level.gd" id="1_o2mui"] [ext_resource type="PackedScene" uid="uid://dtcad8tdx78tg" path="res://game/characters/player.tscn" id="2_r0ht6"] @@ -6,6 +6,7 @@ [ext_resource type="Material" uid="uid://dojhoc6ljpt1a" path="res://game/materials/gray_walls.tres" id="3_pi5fd"] [ext_resource type="Material" uid="uid://d2o2o1w8kb51g" path="res://game/materials/white_walls.tres" id="5_6b8cu"] [ext_resource type="Material" uid="uid://bhksbugqhxxa0" path="res://game/materials/black_walls.tres" id="6_x8k35"] +[ext_resource type="PackedScene" uid="uid://dsts4y32slhnc" path="res://game/menu/pause_menu.tscn" id="7_l0xih"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_pi5fd"] texture = ExtResource("3_fnnmn") @@ -381,3 +382,8 @@ tile_set = SubResource("TileSet_b7vts") [node name="WhiteWalls" type="TileMapLayer" parent="Tiles"] material = ExtResource("5_6b8cu") tile_set = SubResource("TileSet_l0xih") + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="PauseMenu" parent="CanvasLayer" instance=ExtResource("7_l0xih")] +unique_name_in_owner = true diff --git a/game/menu/pause_menu.gd b/game/menu/pause_menu.gd new file mode 100644 index 0000000..7014060 --- /dev/null +++ b/game/menu/pause_menu.gd @@ -0,0 +1,36 @@ +class_name PauseMenu +extends Control + + +@onready var continue_button : Button = $%ContinueButton +@onready var main_menu_button : Button = $%MainMenuButton + + +func _ready() -> void: + _init_focus() + _setup_neighbors() + + +func _init_focus() -> void: + continue_button.grab_focus() + + +func _setup_neighbors() -> void: + continue_button.focus_neighbor_top = main_menu_button.get_path() + main_menu_button.focus_neighbor_bottom = continue_button.get_path() + + +func _on_continue_button_pressed() -> void: + get_tree().paused = false + hide() + + +func _on_main_menu_button_pressed() -> void: + get_tree().paused = false + get_tree().change_scene_to_file("res://game/menu/main_menu.tscn") + + +func _on_visibility_changed() -> void: + if visible: + if continue_button != null: + continue_button.grab_focus() diff --git a/game/menu/pause_menu.gd.uid b/game/menu/pause_menu.gd.uid new file mode 100644 index 0000000..89c6812 --- /dev/null +++ b/game/menu/pause_menu.gd.uid @@ -0,0 +1 @@ +uid://cvw5egmj1f62u diff --git a/game/menu/pause_menu.tscn b/game/menu/pause_menu.tscn new file mode 100644 index 0000000..644f4c2 --- /dev/null +++ b/game/menu/pause_menu.tscn @@ -0,0 +1,51 @@ +[gd_scene load_steps=3 format=3 uid="uid://dsts4y32slhnc"] + +[ext_resource type="Theme" uid="uid://bh56my8b2htnr" path="res://themes/menu.tres" id="1_i4rg2"] +[ext_resource type="Script" uid="uid://cvw5egmj1f62u" path="res://game/menu/pause_menu.gd" id="2_e1jsn"] + +[node name="PauseMenu" type="Control"] +process_mode = 2 +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme = ExtResource("1_i4rg2") +script = ExtResource("2_e1jsn") + +[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, 0, 0, 1) + +[node name="MarginContainer" type="MarginContainer" 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="MarginContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 + +[node name="ContinueButton" type="Button" parent="MarginContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +text = "Continue" + +[node name="MainMenuButton" type="Button" parent="MarginContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +text = "Main menu" + +[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/ContinueButton" to="." method="_on_continue_button_pressed"] +[connection signal="pressed" from="MarginContainer/VBoxContainer/MainMenuButton" to="." method="_on_main_menu_button_pressed"] diff --git a/project.godot b/project.godot index 51ff1fa..df451fe 100644 --- a/project.godot +++ b/project.godot @@ -10,7 +10,7 @@ config_version=5 [application] -config/name="OneBitGameJam8" +config/name="Cult Manor" run/main_scene="uid://c4iica45gnke0" config/features=PackedStringArray("4.5", "GL Compatibility") boot_splash/bg_color=Color(0, 0, 0, 1) @@ -159,3 +159,4 @@ pause={ textures/canvas_textures/default_texture_filter=0 renderer/rendering_method="gl_compatibility" renderer/rendering_method.mobile="gl_compatibility" +environment/defaults/default_clear_color=Color(0, 0, 0, 1)