aboutsummaryrefslogtreecommitdiffstats
path: root/Scripts/scene_control.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts/scene_control.gd')
-rw-r--r--Scripts/scene_control.gd34
1 files changed, 28 insertions, 6 deletions
diff --git a/Scripts/scene_control.gd b/Scripts/scene_control.gd
index d01342f..7f0ba5e 100644
--- a/Scripts/scene_control.gd
+++ b/Scripts/scene_control.gd
@@ -7,23 +7,30 @@ class_name SceneControl
@onready var car = $Car
@onready var checkpoints = $Checkpoints.get_children()
@onready var ui = $UI/Control
-@onready var start = $Start
-
-var finish_line: Area2D
+@onready var drawing = $DrawNode
var is_driving = false
var current_time = 0.0
+var game_control
+var start
+
func _ready():
- finish_line = $FinishLine/Area2D as Area2D
- finish_line.body_entered.connect(_on_finish_line_body_entered)
+ game_control = get_tree().root.get_child(0)
+
+ $FinishLine/Area2D.body_entered.connect(_on_finish_line_body_entered)
+ $UI/Control/PostGameUI/RestartButton.pressed.connect(reset_level)
+ $UI/Control/PostGameUI/NextLevelButton.pressed.connect(next_level)
+
+ start = $Start as TextureButton
+ start.pressed.connect(start_drawing)
+
reset_level()
func _physics_process(delta):
if car.driving:
current_time += delta
- print(current_time)
ui.update_timer_label(current_time)
@@ -43,12 +50,17 @@ func set_driving(driving: bool):
func reset_level():
ui.update_timer_label(-1)
+ ui.switch_to_in_game_UI()
+
+ $DrawNode.reset()
for cp in checkpoints:
cp.set_was_visited(false)
car.global_position = start.global_position
car.global_rotation = start.rotation;
+
+ set_driving(false)
func start_driving():
current_time = 0.0
@@ -64,6 +76,16 @@ func evaluate_driving():
func _on_finish_line_body_entered(node: Node2D):
if evaluate_driving():
ui.switch_to_post_game_UI()
+ set_driving(false)
+ return
set_driving(false)
reset_level()
+
+func next_level():
+ game_control.next_level()
+
+
+func start_drawing():
+ reset_level()
+ drawing.start_drawing()