-
Notifications
You must be signed in to change notification settings - Fork 0
/
Baton.gd
79 lines (55 loc) · 1.96 KB
/
Baton.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
extends PathFollow2D
signal laps_changed(new_laps)
signal detection_registered(station, rssi, timestamp)
# handjes
# bewegingslijnen
# voetstappen
export(String) var mac = "00:00:00:00:00:01"
var rng = RandomNumberGenerator.new()
var laps: int = 0
var color: Color
var speed: float
var speed_offset: float = 0.0
var temp_slow: float = 1.0 # speed modifier that will always try to lerp back to 1
var speed_consistency: float = 1.0
var stop_chance: float = 0.0
var home_base: float = 0.0
# Frequency is 8 per second
var delta_since_last_emission: float = 0.0
func get_track_distance():
return get_parent().get_curve().get_baked_length()
func get_progress():
return offset/get_track_distance()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
$UI/Name.text = name
rng.randomize()
offset = 0
stop_chance = rng.randf_range(0.0, 1.0)
home_base = rng.randf_range(0.0, 1.0) * get_track_distance()
speed = rng.randf_range(2.0, 3.0) # .4, 1.0
color = Color(rng.randf_range(.4, .8), rng.randf_range(.4, .8), rng.randf_range(.4, .8), 0.8)
# mac = ("00-B0-D0-63-C2-%s%s" % [rng.randi_range(0, 10), rng.randi_range(0, 10)])
func _draw():
draw_circle(Vector2(0,0),20.0,color)
func _process(delta):
delta_since_last_emission += delta
if delta_since_last_emission > 1.0/8.0:
delta_since_last_emission -= 1.0/8.0
for area in $Area2D.get_overlapping_areas():
if area.is_in_group("station"):
var station = area.get_parent()
station.add_detection(self)
update()
var previous_offset = offset
temp_slow = lerp(temp_slow, 1.0, .1)
offset += ((speed + speed_offset) * temp_slow)
if offset < previous_offset:
laps += 1
emit_signal("laps_changed", laps)
speed_offset += rng.randf_range(-.05, .05)
speed_offset = clamp(speed_offset, -.2, .2)
if previous_offset < home_base and offset > home_base:
temp_slow = .3
$UI/Progress.text = str(round(get_progress()*100)/100)
$UI/Speed.text = str(temp_slow * speed)