summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/CameraTrackFollower.gd45
-rw-r--r--components/Level.gd6
-rw-r--r--components/PathRenderer.gd28
3 files changed, 74 insertions, 5 deletions
diff --git a/components/CameraTrackFollower.gd b/components/CameraTrackFollower.gd
new file mode 100644
index 0000000..22420d9
--- /dev/null
+++ b/components/CameraTrackFollower.gd
@@ -0,0 +1,45 @@
+extends Camera2D
+class_name CameraTrackFollower
+var path : Path2D setget _path
+
+signal done()
+
+var _points
+func _path(value):
+ path = value
+ _pidx = 0
+ _t = 0
+ _points = value.curve.get_baked_points()
+ current_speed = 0
+ _done_emitted = false
+ print("New path set to CameraTrackFollower")
+export var speedup = 100
+export var speedup_time = 5
+export var initial_speed = 100
+var current_speed = initial_speed
+var _pidx = -1
+var _done_emitted = true
+var _t = 0
+
+func _process(delta):
+ if _pidx == -1:
+ if not _done_emitted:
+ emit_signal("done")
+ _done_emitted = true
+ return
+ var next_point = _points[_pidx]
+ var dist : Vector2 = next_point - position
+ print("Camera movement", dist)
+ if _t < speedup_time:
+ current_speed += speedup * max(0, min(speedup_time-_t, delta))
+ _t += delta
+ if dist.length() - current_speed * delta < 0.5:
+ position = next_point
+ _pidx += 1
+ if _pidx >= _points.size():
+ _pidx = -1
+ _process(delta - dist.length() / current_speed)
+ return
+ var velocity = dist.normalized() * current_speed * delta
+ position += velocity
+
diff --git a/components/Level.gd b/components/Level.gd
new file mode 100644
index 0000000..135a2cf
--- /dev/null
+++ b/components/Level.gd
@@ -0,0 +1,6 @@
+extends Node2D
+
+class_name Level
+
+func start():
+ print("Level starting.")
diff --git a/components/PathRenderer.gd b/components/PathRenderer.gd
index 75c7163..14853ce 100644
--- a/components/PathRenderer.gd
+++ b/components/PathRenderer.gd
@@ -1,13 +1,31 @@
extends Node2D
-onready var path : Path2D = $Path2D
-onready var points = path.curve.get_baked_points()
+class_name PathRenderer
+
+export var path_color : Color = Color.brown setget _color
+export var stroke_width : int = 6 setget _width
+var path : Path2D = null setget _path
+
+func _width(value):
+ stroke_width = value
+ update()
+
+func _color(value):
+ path_color = value
+ update()
+
+func _path(value):
+ path = value
+ update()
func _draw():
- var last_point = 0
+ if path == null:
+ return
+ var last_point = null
+ var points = path.curve.get_baked_points()
for point in points:
- if last_point is int:
+ if last_point == null:
last_point = point
continue
- draw_line(last_point, point, Color.brown, 6, false)
+ draw_line(last_point, point, path_color, stroke_width, false)
last_point = point