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)