diff --git a/src/game/level.gd b/src/game/level.gd index 635462c..91bdb7e 100644 --- a/src/game/level.gd +++ b/src/game/level.gd @@ -12,6 +12,8 @@ extends Node2D @export var path: Path2D ## reference to the line that draws the visual track @export var line: Line2D +## reference to the player node +@export var player: StaticBody2D #variables var width @@ -29,7 +31,18 @@ func _process(delta): if (running): width -= shrink_factor * delta update_line() + + var p_pos = player.position + var closest = path.curve.get_closest_point(p_pos) + var p_dist = (p_pos - closest).length() + print_debug(" distance from track center: ", p_dist, " current track width: ", width) + if p_dist > width/2 - max_distance_offset: + game_over() func update_line(): line.set_width(width) + + +func game_over(): + get_tree().reload_current_scene() #temp diff --git a/src/game/level1.tscn b/src/game/level1.tscn index 31b1591..4b5a7bc 100644 --- a/src/game/level1.tscn +++ b/src/game/level1.tscn @@ -10,12 +10,13 @@ _data = { } point_count = 7 -[node name="level1" type="Node2D" node_paths=PackedStringArray("path", "line")] +[node name="level1" type="Node2D" node_paths=PackedStringArray("path", "line", "player")] script = ExtResource("1_hv75i") starting_width = 400.0 -shrink_factor = 0.5 +shrink_factor = 5.0 path = NodePath("TrackPath") line = NodePath("TrackLine") +player = NodePath("player") [node name="TrackPath" type="Path2D" parent="."] curve = SubResource("Curve2D_ll8bj") @@ -27,3 +28,4 @@ texture_mode = 2 [node name="player" parent="." instance=ExtResource("2_5nf51")] position = Vector2(42.7545, -14.9219) +brake_strength = 800.0 diff --git a/src/game/player.tscn b/src/game/player.tscn index ac5592a..83eefc4 100644 --- a/src/game/player.tscn +++ b/src/game/player.tscn @@ -11,6 +11,7 @@ script = ExtResource("1_g4ij8") turn_speed = 0.8 brake_strength = 600.0 drift_factor = 1.2 +camera_offset = 200.0 camera = NodePath("Camera2D") [node name="Sprite2D" type="Sprite2D" parent="."]