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)

20
src/game/level1.tscn Normal file
View file

@ -0,0 +1,20 @@
[gd_scene load_steps=3 format=3 uid="uid://b4dnui6vvlta7"]
[ext_resource type="Script" path="res://src/game/level.gd" id="1_hv75i"]
[sub_resource type="Curve2D" id="Curve2D_ll8bj"]
_data = {
"points": PackedVector2Array(-33.6888, -46.2486, 33.6888, 46.2486, 325, 200, -79.196, 14.1421, 79.196, -14.1421, 543, 271, -62.2254, 38.1838, 62.2254, -38.1838, 714, 113, -35.3553, -48.0833, 35.3553, 48.0833, 961, 148, 62.2254, -69.2965, -62.2254, 69.2965, 978, 429, 59.397, -33.9411, -59.397, 33.9411, 739, 445, 77.7818, -1.41421, -77.7818, 1.41421, 596, 562, 62.2254, 25.4558, -62.2254, -25.4558, 316, 518, 42.4264, 69.2965, -42.4264, -69.2965, 119, 387, -1.41421, 50.9117, 1.41421, -50.9117, 72, 187, -33.9411, 22.6274, 33.9411, -22.6274, 137, 52, -38.1838, -12.7279, 38.1838, 12.7279, 241, 47, -25.4558, -49.4975, 25.4558, 49.4975, 299, 154, -15.3576, -23.2238, 15.3576, 23.2238, 325, 200)
}
point_count = 14
[node name="level1" type="Node2D" node_paths=PackedStringArray("path", "line")]
script = ExtResource("1_hv75i")
shrink_factor = 0.5
path = NodePath("TrackPath")
line = NodePath("TrackLine")
[node name="TrackPath" type="Path2D" parent="."]
curve = SubResource("Curve2D_ll8bj")
[node name="TrackLine" type="Line2D" parent="."]