pause menu with spaghettis mixed in

This commit is contained in:
Taevas 2025-02-23 16:18:14 +01:00
parent c19d1dffcb
commit 2f066938ac
6 changed files with 151 additions and 68 deletions

View file

@ -4,22 +4,30 @@
script/source = "extends Node
var seconds_spent: float = 0.0
var changing_level: bool = false
var base = preload(\"res://levels/base/level.tscn\")
var forest = preload(\"res://levels/forest/level.tscn\")
var night = preload(\"res://levels/night/level.tscn\")
func _ready() -> void:
$PauseMenu.hide()
## Add the version of the game and the name of the OS to the footer of the start menu
$StartMenu/VBoxContainer/MarginContainer2/Notice.text += \" - build \" + ProjectSettings.get_setting(\"application/config/version\") + \" (\" + OS.get_name() + \")\"
func start_level(level_scene: PackedScene) -> void:
if level_scene and level_scene.can_instantiate():
AudioServer.set_bus_volume_db(0, 0)
var level = level_scene.instantiate()
$Levels.add_child(level)
$Timer.paused = false
changing_level = false
else:
assert(false, \"NO LEVEL AAAA\")
func stop_level() -> void:
PhysicsServer3D.area_set_param(get_viewport().find_world_3d().space, PhysicsServer3D.AREA_PARAM_GRAVITY, 1)
$Timer.paused = true
changing_level = true
AudioServer.set_bus_volume_db(0, -5)
await get_tree().create_timer(0.5).timeout
@ -34,9 +42,9 @@ func stop_level() -> void:
var current_levels = $Levels.get_children(true)
if len(current_levels):
var current_level = current_levels[0]
if current_level.name == \"Base\":
if current_level.get_meta(\"name\") == \"Base\":
next_level = forest
elif current_level.name == \"Forest\":
elif current_level.get_meta(\"name\") == \"Forest\":
next_level = night
for level in current_levels:
@ -44,13 +52,47 @@ func stop_level() -> void:
start_level(next_level)
func _on_btn_fullscreen_pressed() -> void:
func restart_level() -> void:
if changing_level == false:
var current_levels = $Levels.get_children(true)
if len(current_levels):
pause_game()
changing_level = true
var current_level = current_levels[0]
var next_level: PackedScene = base
if current_level.get_meta(\"name\") == \"Forest\":
next_level = forest
elif current_level.get_meta(\"name\") == \"Night\":
next_level = night
for level in current_levels:
level.queue_free()
start_level(next_level)
func pause_game() -> void:
if $Levels.process_mode == PROCESS_MODE_INHERIT:
$Levels.process_mode = Node.PROCESS_MODE_DISABLED
$Timer.paused = true
$PauseMenu.show()
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
$Levels.process_mode = Node.PROCESS_MODE_INHERIT
$Timer.paused = false
$PauseMenu.hide()
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
func fullscreen_game() -> void:
var fs = DisplayServer.window_get_mode()
if fs != DisplayServer.WindowMode.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_FULLSCREEN)
else:
DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_WINDOWED)
func _on_btn_fullscreen_pressed() -> void:
fullscreen_game()
func _on_btn_start_pressed() -> void:
$StartMenu/AnimationPlayer.play(\"fadeout\")
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
@ -66,12 +108,36 @@ func _on_timer_timeout() -> void:
var minutes = floor(seconds_spent / 60)
$Informations/MarginContainer/Timer.text = (\"%0*d\" % [2, minutes]) + \":\" + (\"%0*.1f\" % [4, seconds_spent - (minutes * 60)])
func _process(delta: float) -> void:
func _process(_delta: float) -> void:
var current_levels = $Levels.get_children(true)
if len(current_levels):
var current_level = current_levels[0]
if is_instance_valid(current_level) and \"velocity\" in current_level:
$Informations/MarginContainer/VBoxContainer/Speed.text = str(floor(current_level.velocity)) + \" km/h\"
if is_instance_valid(current_level):
if \"velocity\" in current_level:
$Informations/MarginContainer/VBoxContainer/Speed.text = str(floor(current_level.velocity)) + \" km/h\"
if \"rings_count\" in current_level and \"finished_rings_count\" in current_level:
$Informations/MarginContainer/VBoxContainer/Rings.text = str(current_level.finished_rings_count) + \"/\" + str(current_level.rings_count)
func _unhandled_key_input(event: InputEvent) -> void:
if event.is_pressed() and event is InputEventKey:
if $StartMenu.visible == false and changing_level == false:
if event.keycode == KEY_ESCAPE:
pause_game()
elif event.keycode == KEY_R:
pause_game()
restart_level()
func _on_btn_resume_pressed() -> void:
pause_game()
func _on_btn_fullscreen_2_pressed() -> void:
fullscreen_game()
func _on_btn_restart_pressed() -> void:
restart_level()
func _on_btn_quit_pressed() -> void:
get_tree().quit()
"
[sub_resource type="LabelSettings" id="LabelSettings_0s07t"]
@ -291,14 +357,14 @@ layout_mode = 2
size_flags_horizontal = 4
text = "START the game!"
[node name="Notice" type="MarginContainer" parent="StartMenu/VBoxContainer"]
[node name="MarginContainer2" type="MarginContainer" parent="StartMenu/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_left = 20
theme_override_constants/margin_top = 20
theme_override_constants/margin_right = 20
theme_override_constants/margin_bottom = 20
[node name="Title3" type="Label" parent="StartMenu/VBoxContainer/Notice"]
[node name="Notice" type="Label" parent="StartMenu/VBoxContainer/MarginContainer2"]
layout_mode = 2
text = "Made during the 21st edition of Alakajam!"
label_settings = SubResource("LabelSettings_5jdmh")
@ -314,7 +380,54 @@ libraries = {
[node name="Timer" type="Timer" parent="."]
wait_time = 0.1
[node name="PauseMenu" type="Control" parent="."]
visible = false
z_index = 2
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 1
[node name="VBoxContainer" type="VBoxContainer" parent="PauseMenu"]
layout_mode = 1
anchors_preset = 14
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
offset_top = -50.5
offset_bottom = 50.5
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/separation = 10
[node name="Btn_Resume" type="Button" parent="PauseMenu/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 6
text = "RESUME game"
[node name="Btn_Fullscreen2" type="Button" parent="PauseMenu/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 6
text = "Toggle FULLSCREEN"
[node name="Btn_Restart" type="Button" parent="PauseMenu/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 6
text = "RESTART the level"
[node name="Btn_Quit" type="Button" parent="PauseMenu/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 6
text = "QUIT game"
[connection signal="pressed" from="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Buttons/HBoxContainer/Btn_Fullscreen" to="." method="_on_btn_fullscreen_pressed"]
[connection signal="pressed" from="StartMenu/VBoxContainer/MarginContainer/HBoxContainer/Buttons/HBoxContainer/Btn_Start" to="." method="_on_btn_start_pressed"]
[connection signal="animation_finished" from="StartMenu/AnimationPlayer" to="." method="_on_animation_player_animation_finished"]
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
[connection signal="pressed" from="PauseMenu/VBoxContainer/Btn_Resume" to="." method="_on_btn_resume_pressed"]
[connection signal="pressed" from="PauseMenu/VBoxContainer/Btn_Fullscreen2" to="." method="_on_btn_fullscreen_2_pressed"]
[connection signal="pressed" from="PauseMenu/VBoxContainer/Btn_Restart" to="." method="_on_btn_restart_pressed"]
[connection signal="pressed" from="PauseMenu/VBoxContainer/Btn_Quit" to="." method="_on_btn_quit_pressed"]