diff options
author | IcECreAm777 <hgk.1998@googlemail.com> | 2023-07-08 16:43:32 +0200 |
---|---|---|
committer | IcECreAm777 <hgk.1998@googlemail.com> | 2023-07-08 16:43:32 +0200 |
commit | 78b6db9f792e18d848383856693cff4ef223a10f (patch) | |
tree | 4d0385ae8eb8f450a6b2c40c1886a964134d154d /Scripts/scene_control.gd | |
parent | bf17c8a97b77cdb783a2751e7ee4a90843a00f06 (diff) | |
download | 2023-78b6db9f792e18d848383856693cff4ef223a10f.tar.gz 2023-78b6db9f792e18d848383856693cff4ef223a10f.tar.bz2 2023-78b6db9f792e18d848383856693cff4ef223a10f.zip |
checkpoint detection and UI
Diffstat (limited to 'Scripts/scene_control.gd')
-rw-r--r-- | Scripts/scene_control.gd | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/Scripts/scene_control.gd b/Scripts/scene_control.gd index fdaad14..0b55d0f 100644 --- a/Scripts/scene_control.gd +++ b/Scripts/scene_control.gd @@ -2,9 +2,28 @@ extends Node class_name SceneControl -@onready var path : Path2D = $DrawNode/TrackPath -@onready var path_follow : PathFollow2D = $DrawNode/TrackPath/TrackFollower -@onready var car : StaticBody2D = $Car +@onready var path: Path2D = $DrawNode/TrackPath +@onready var path_follow: PathFollow2D = $DrawNode/TrackPath/TrackFollower +@onready var car = $Car +@onready var checkpoints = $Checkpoints.get_children() +@onready var ui = $UI/Control +@onready var finish_line: Area2D + +var is_driving = false +var current_time = 0.0 + + +func _ready(): + finish_line = $FinishLine as Area2D + finish_line.body_entered.connect(_on_finish_line_body_entered) + reset_level() + +func _physics_process(delta): + if car.driving: + current_time += delta + print(current_time) + ui.update_timer_label(current_time) + func get_path_direction(pos): var offset = path.curve.get_closest_offset(pos) @@ -18,3 +37,30 @@ func get_path_next_position(pos): func set_driving(driving: bool): car.driving = driving + is_driving = driving + +func reset_level(): + ui.update_timer_label(-1) + for cp in checkpoints: + cp.set_was_visited(false) + +func start_driving(): + current_time = 0.0 + set_driving(true) + +func evaluate_driving(): + for cp in checkpoints: + if not cp.was_visited: + return false + return true + + +func _on_finish_line_body_entered(node: Node2D): + if evaluate_driving(): + ui.switch_to_post_game_UI() + + set_driving(false) + reset_level() + # TODO get this from the start position + car.global_position = Vector2.ZERO + car.global_rotation = 0; |