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

@ -21,6 +21,8 @@ extends Node2D
## reference to the line node used to draw the finish line
@export var finish: Line2D
@export var menu: Control
signal distance_changed(new_distance)
#variables
@ -31,6 +33,7 @@ var lap_distance = 0.
var start
var finish_right
var finish_left
var paused = false
# Called when the node enters the scene tree for the first time.
func _ready():
@ -53,6 +56,10 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_action_just_pressed("pause") && running:
pause()
if (running):
# shrinking the track
width -= shrink_factor * delta
@ -86,6 +93,16 @@ func _process(delta):
distance_changed.emit(get_total_distance())
# 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():
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="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://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://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="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"]
@ -15,7 +16,7 @@ _data = {
}
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")
starting_width = 400.0
shrink_factor = 5.0
@ -23,6 +24,7 @@ path = NodePath("TrackPath")
line = NodePath("TrackLine")
player = NodePath("player")
finish = NodePath("FinishLine")
menu = NodePath("CanvasLayer/menu_box/level")
[node name="TextureRect" type="TextureRect" parent="."]
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")]
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="curveSign3" type="PointLight2D" parent="Node2D"]