Added a scene for a level, with a track that shrinks (at least visually)

This commit is contained in:
KingGurke 2023-09-30 16:23:22 +02:00
parent f602e04e16
commit f9917528dc
2 changed files with 55 additions and 0 deletions

35
src/game/level.gd Normal file
View file

@ -0,0 +1,35 @@
extends Node2D
#constants
## initial width of the drawn track
@export var starting_width := 50.0
## amount of pixels that the width decreases every second
@export var shrink_factor := .1
## the diefference between the track's width and the maximum distance of the car from the center of the track. Should be about half the width of the car
@export var max_distance_offset := .5
#references
## reference to the path describing the track
@export var path: Path2D
## reference to the line that draws the visual track
@export var line: Line2D
#variables
var width
var running = true
# Called when the node enters the scene tree for the first time.
func _ready():
width = starting_width
line.set_width(width)
line.set_points(path.curve.get_baked_points())
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if (running):
width -= shrink_factor * delta
update_line()
func update_line():
line.set_width(width)