added pause menu in level and ability to load levels from main menu

This commit is contained in:
KingGurke 2023-10-02 16:35:08 +02:00
parent f51914161e
commit b0475b1697
9 changed files with 190 additions and 37 deletions

View file

@ -61,3 +61,8 @@ reverse={
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
] ]
} }
pause={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"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,"echo":false,"script":null)
]
}

View file

@ -21,6 +21,8 @@ extends Node2D
## reference to the line node used to draw the finish line ## reference to the line node used to draw the finish line
@export var finish: Line2D @export var finish: Line2D
@export var menu: Control
signal distance_changed(new_distance) signal distance_changed(new_distance)
#variables #variables
@ -31,6 +33,7 @@ var lap_distance = 0.
var start var start
var finish_right var finish_right
var finish_left var finish_left
var paused = false
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
@ -53,6 +56,10 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
if Input.is_action_just_pressed("pause") && running:
pause()
if (running): if (running):
# shrinking the track # shrinking the track
width -= shrink_factor * delta width -= shrink_factor * delta
@ -86,6 +93,16 @@ func _process(delta):
distance_changed.emit(get_total_distance()) distance_changed.emit(get_total_distance())
# print_debug("player distance driven: ", get_total_distance(), " distance since last check: ", off_diff) # print_debug("player distance driven: ", get_total_distance(), " distance since last check: ", off_diff)
func pause():
if !paused:
Engine.time_scale = 0
menu.show()
paused = true
else:
Engine.time_scale = 1
menu.hide()
paused = false
func update_line(): func update_line():
line.set_width(width) line.set_width(width)

View file

@ -1,10 +1,11 @@
[gd_scene load_steps=10 format=3 uid="uid://c77xk0mywwt5f"] [gd_scene load_steps=11 format=3 uid="uid://c77xk0mywwt5f"]
[ext_resource type="Script" path="res://src/game/levels/level.gd" id="1_s3rsn"] [ext_resource type="Script" path="res://src/game/levels/level.gd" id="1_s3rsn"]
[ext_resource type="Texture2D" uid="uid://dio3rrptd6w7c" path="res://assets/bg2.png" id="2_57sr6"] [ext_resource type="Texture2D" uid="uid://dio3rrptd6w7c" path="res://assets/bg2.png" id="2_57sr6"]
[ext_resource type="Texture2D" uid="uid://ds0un04pocx6i" path="res://assets/track90.png" id="3_en5wc"] [ext_resource type="Texture2D" uid="uid://ds0un04pocx6i" path="res://assets/track90.png" id="3_en5wc"]
[ext_resource type="Texture2D" uid="uid://dmcrms0qu0mtt" path="res://assets/finish2.png" id="4_qeube"] [ext_resource type="Texture2D" uid="uid://dmcrms0qu0mtt" path="res://assets/finish2.png" id="4_qeube"]
[ext_resource type="PackedScene" uid="uid://ckau5s2tsb3oc" path="res://src/game/player.tscn" id="5_2n8nj"] [ext_resource type="PackedScene" uid="uid://ckau5s2tsb3oc" path="res://src/game/player.tscn" id="5_2n8nj"]
[ext_resource type="PackedScene" uid="uid://dyo5dblkfivwn" path="res://src/gui/menu/level.tscn" id="6_hs25h"]
[ext_resource type="PackedScene" uid="uid://cdlbh3smpgg42" path="res://src/gui/hud/hud.tscn" id="6_r1i0q"] [ext_resource type="PackedScene" uid="uid://cdlbh3smpgg42" path="res://src/gui/hud/hud.tscn" id="6_r1i0q"]
[ext_resource type="Texture2D" uid="uid://bq151lkkfdlf4" path="res://assets/sign.png" id="7_xmahe"] [ext_resource type="Texture2D" uid="uid://bq151lkkfdlf4" path="res://assets/sign.png" id="7_xmahe"]
[ext_resource type="AudioStream" uid="uid://dh5jxxwim7ra8" path="res://assets/sounds/music/death_by_waveshaper.wav" id="8_qlkhp"] [ext_resource type="AudioStream" uid="uid://dh5jxxwim7ra8" path="res://assets/sounds/music/death_by_waveshaper.wav" id="8_qlkhp"]
@ -15,7 +16,7 @@ _data = {
} }
point_count = 7 point_count = 7
[node name="level1" type="Node2D" node_paths=PackedStringArray("path", "line", "player", "finish")] [node name="level1" type="Node2D" node_paths=PackedStringArray("path", "line", "player", "finish", "menu")]
script = ExtResource("1_s3rsn") script = ExtResource("1_s3rsn")
starting_width = 400.0 starting_width = 400.0
shrink_factor = 5.0 shrink_factor = 5.0
@ -23,6 +24,7 @@ path = NodePath("TrackPath")
line = NodePath("TrackLine") line = NodePath("TrackLine")
player = NodePath("player") player = NodePath("player")
finish = NodePath("FinishLine") finish = NodePath("FinishLine")
menu = NodePath("CanvasLayer/menu_box/level")
[node name="TextureRect" type="TextureRect" parent="."] [node name="TextureRect" type="TextureRect" parent="."]
self_modulate = Color(0.827451, 0.521569, 0.313726, 1) self_modulate = Color(0.827451, 0.521569, 0.313726, 1)
@ -63,6 +65,24 @@ brake_strength = 800.0
[node name="hud" parent="CanvasLayer" instance=ExtResource("6_r1i0q")] [node name="hud" parent="CanvasLayer" instance=ExtResource("6_r1i0q")]
size_flags_horizontal = 3 size_flags_horizontal = 3
[node name="menu_box" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -20.0
offset_right = 20.0
offset_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2
[node name="level" parent="CanvasLayer/menu_box" instance=ExtResource("6_hs25h")]
visible = false
layout_mode = 1
[node name="Node2D" type="Node2D" parent="."] [node name="Node2D" type="Node2D" parent="."]
[node name="curveSign3" type="PointLight2D" parent="Node2D"] [node name="curveSign3" type="PointLight2D" parent="Node2D"]

13
src/gui/menu/level.gd Normal file
View file

@ -0,0 +1,13 @@
extends Control
func _on_continue_button_pressed():
get_tree().current_scene.pause()
func _on_menu_button_pressed():
get_tree().current_scene.pause()
get_tree().change_scene_to_file("res://src/gui/menu/main.tscn")
func _on_options_button_pressed():
var options = load("res://src/gui/menu/options.tscn").instantiate()
get_parent().add_child((options))
hide()

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://dyo5dblkfivwn"] [gd_scene load_steps=3 format=3 uid="uid://dyo5dblkfivwn"]
[ext_resource type="Theme" uid="uid://dpktnl3r5wul1" path="res://src/gui/menu_theme.tres" id="1_62uke"] [ext_resource type="Theme" uid="uid://dpktnl3r5wul1" path="res://src/gui/menu_theme.tres" id="1_62uke"]
[ext_resource type="Script" path="res://src/gui/menu/level.gd" id="2_6ldjx"]
[node name="level" type="Control"] [node name="level" type="Control"]
layout_mode = 3 layout_mode = 3
@ -10,3 +11,73 @@ anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
theme = ExtResource("1_62uke") theme = ExtResource("1_62uke")
script = ExtResource("2_6ldjx")
[node name="Pause" type="Panel" 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 = -131.0
offset_top = -231.0
offset_right = 132.0
offset_bottom = 169.0
grow_horizontal = 2
grow_vertical = 2
[node name="Label" type="Label" parent="Pause"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -52.0
offset_top = 24.0
offset_right = 52.0
offset_bottom = 50.0
grow_horizontal = 2
text = "PAUSED"
horizontal_alignment = 1
[node name="VBoxContainer" type="VBoxContainer" parent="Pause"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -59.5
offset_top = 3.0
offset_right = 60.5
offset_bottom = 131.0
grow_horizontal = 2
grow_vertical = 2
[node name="ContinueButton" type="Button" parent="Pause/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "CONTINUE"
[node name="OptionsButton" type="Button" parent="Pause/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "OPTIONS"
[node name="MenuButton" type="Button" parent="Pause/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "TO MENU"
[connection signal="pressed" from="Pause/VBoxContainer/ContinueButton" to="." method="_on_continue_button_pressed"]
[connection signal="pressed" from="Pause/VBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"]
[connection signal="pressed" from="Pause/VBoxContainer/MenuButton" to="." method="_on_menu_button_pressed"]

View file

@ -6,7 +6,7 @@ extends Control
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
$VBoxContainer/StartButton.grab_focus() $Main/VBoxContainer/StartButton.grab_focus()
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
@ -22,7 +22,8 @@ func _on_start_button_pressed():
func _on_options_button_pressed(): func _on_options_button_pressed():
var options = load("res://src/gui/menu/options.tscn").instantiate() var options = load("res://src/gui/menu/options.tscn").instantiate()
get_tree().current_scene.add_child((options)) get_parent().add_child((options))
hide()
func _on_quit_button_pressed(): func _on_quit_button_pressed():
get_tree().quit() get_tree().quit()

View file

@ -65,39 +65,57 @@ grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
theme = SubResource("Theme_67fiq") theme = SubResource("Theme_67fiq")
script = ExtResource("1_p5r7q") script = ExtResource("1_p5r7q")
main_menu = NodePath("VBoxContainer") main_menu = NodePath("Main")
level_select = NodePath("LevelSelect") level_select = NodePath("LevelSelect")
[node name="VBoxContainer" type="VBoxContainer" parent="."] [node name="Main" type="Panel" parent="."]
layout_mode = 1 layout_mode = 1
anchors_preset = 8 anchors_preset = 8
anchor_left = 0.5 anchor_left = 0.5
anchor_top = 0.5 anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 0.5 anchor_bottom = 0.5
offset_left = -200.0 offset_left = -131.0
offset_top = -44.0 offset_top = -231.0
offset_right = 200.0 offset_right = 132.0
offset_bottom = 156.0 offset_bottom = 169.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="Main"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -59.5
offset_top = 3.0
offset_right = 60.5
offset_bottom = 131.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
alignment = 1 alignment = 1
[node name="StartButton" type="Button" parent="VBoxContainer"] [node name="StartButton" type="Button" parent="Main/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 4
focus_neighbor_top = NodePath("../QuitButton") focus_neighbor_top = NodePath("../QuitButton")
text = "Start! text = "PLAY"
"
[node name="OptionsButton" type="Button" parent="VBoxContainer"] [node name="OptionsButton" type="Button" parent="Main/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2 layout_mode = 2
text = "Options size_flags_horizontal = 4
" text = "OPTIONS"
[node name="QuitButton" type="Button" parent="VBoxContainer"] [node name="QuitButton" type="Button" parent="Main/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 4
focus_neighbor_bottom = NodePath("../StartButton") focus_neighbor_bottom = NodePath("../StartButton")
text = "Quit" text = "QUIT"
[node name="LevelSelect" type="Panel" parent="."] [node name="LevelSelect" type="Panel" parent="."]
visible = false visible = false
@ -212,18 +230,6 @@ layout_mode = 2
size_flags_horizontal = 4 size_flags_horizontal = 4
text = "12" text = "12"
[node name="MarginContainer" type="MarginContainer" parent="LevelSelect/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_top = 20
[node name="BackButton" type="Button" parent="LevelSelect/VBoxContainer/MarginContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "Back"
[node name="Label" type="Label" parent="LevelSelect"] [node name="Label" type="Label" parent="LevelSelect"]
layout_mode = 1 layout_mode = 1
anchors_preset = 5 anchors_preset = 5
@ -237,15 +243,34 @@ grow_horizontal = 2
text = "LEVEL SELECT" text = "LEVEL SELECT"
horizontal_alignment = 1 horizontal_alignment = 1
[node name="BackButton" type="Button" parent="LevelSelect"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -60.0
offset_top = -109.0
offset_right = 60.0
offset_bottom = -69.0
grow_horizontal = 2
grow_vertical = 0
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "BACK"
[node name="MenuMusic" type="AudioStreamPlayer" parent="."] [node name="MenuMusic" type="AudioStreamPlayer" parent="."]
stream = ExtResource("2_yc480") stream = ExtResource("2_yc480")
volume_db = -29.953 volume_db = -29.953
autoplay = true autoplay = true
bus = &"Music" bus = &"Music"
[connection signal="pressed" from="VBoxContainer/StartButton" to="." method="_on_start_button_pressed"] [connection signal="pressed" from="Main/VBoxContainer/StartButton" to="." method="_on_start_button_pressed"]
[connection signal="pressed" from="VBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"] [connection signal="pressed" from="Main/VBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"]
[connection signal="pressed" from="VBoxContainer/QuitButton" to="." method="_on_quit_button_pressed"] [connection signal="pressed" from="Main/VBoxContainer/QuitButton" to="." method="_on_quit_button_pressed"]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/1" to="." method="_on_level_button_pressed" binds= [1]] [connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/1" to="." method="_on_level_button_pressed" binds= [1]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/2" to="." method="_on_level_button_pressed" binds= [2]] [connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/2" to="." method="_on_level_button_pressed" binds= [2]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/3" to="." method="_on_level_button_pressed" binds= [3]] [connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/3" to="." method="_on_level_button_pressed" binds= [3]]
@ -258,4 +283,4 @@ bus = &"Music"
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/10" to="." method="_on_level_button_pressed" binds= [10]] [connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/10" to="." method="_on_level_button_pressed" binds= [10]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/11" to="." method="_on_level_button_pressed" binds= [11]] [connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/11" to="." method="_on_level_button_pressed" binds= [11]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/12" to="." method="_on_level_button_pressed" binds= [12]] [connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/12" to="." method="_on_level_button_pressed" binds= [12]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/MarginContainer/BackButton" to="." method="_on_back_button_pressed"] [connection signal="pressed" from="LevelSelect/BackButton" to="." method="_on_back_button_pressed"]

View file

@ -1,4 +1,5 @@
extends Control extends Control
func _on_back_button_pressed(): func _on_back_button_pressed():
get_parent().get_child(0).show()
queue_free() queue_free()

View file

@ -129,9 +129,9 @@ anchor_top = 1.0
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_left = -60.0 offset_left = -60.0
offset_top = -64.0 offset_top = -109.0
offset_right = 60.0 offset_right = 60.0
offset_bottom = -24.0 offset_bottom = -69.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 0 grow_vertical = 0
size_flags_horizontal = 4 size_flags_horizontal = 4