Added temporary game over mechanic (just reloads the scene right now)

This commit is contained in:
KingGurke 2023-10-01 09:49:47 +02:00
parent cf0fbfa45f
commit fa2d82475b
3 changed files with 18 additions and 2 deletions

View file

@ -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
@ -30,6 +32,17 @@ func _process(delta):
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

View file

@ -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

View file

@ -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="."]