forked from stevelavietes/pico8carts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dead_mans_slope_minified.p8
2160 lines (2160 loc) · 73.2 KB
/
dead_mans_slope_minified.p8
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
pico-8 cartridge // http://www.pico-8.com
version 14
__lua__
-- dead mans slope
-- @stephan_gfx / @stevelavieties
--
-- v0.6
beta = 0.0001
mincutoff = 0.0001
function make_one_euro_filt(beta, mincutoff)
return {
first_time = true,
dx = 0,
rate = 0.0333,
mincutoff = mincutoff,
beta = beta,
d_cutoff = 0,
xfilt = make_low_pass_filter(),
dxfilt = make_low_pass_filter(),
filter=function(t, x)
t.dx = t.first_time and 0 or (x - t.xfilt.hatxprev) * t.rate
local edx = t.dxfilt:filter(t.dx, t:alpha(t.rate, t.d_cutoff))
local cutoff = mincutoff + beta * abs(edx)
return t.xfilt:filter(x, t:alpha(t.rate, cutoff))
end,
alpha = function(t, rate, cutoff)
local tau = 1.0 / (2 * 3.14159 * cutoff)
local te = 1.0 / rate
return (1.0 / (1.0 + tau/te))
end
}
end
function make_low_pass_filter()
return {
first_time = true,
hat_x_prev = nil,
hat_x = nil,
filter = function(t, x, alpha)
if t.first_time then
t.first_time = false
t.hat_x_prev = x
end
t.hat_x = alpha * x + (1 - alpha) * t.hat_x_prev
t.hat_x_prev = t.hat_x
return t.hat_x
end
}
end
function add_particle(x, y, dx, dy, life, color, ddy, pass)
particle_array_length += 1
if (#particle_array < particle_array_length) add(particle_array, 0)
particle_array[particle_array_length] = {x = x, y = y, dx = dx, dy = dy, life = life or 8, color = color or 6, ddy = ddy or 0.0625, pass = pass or 0}
end
function process_particles(at_scope, pass)
local p = 1
local off = {0,0}
if at_scope == sp_world and g_cam != nil then
off = {-g_cam.x + 64, -g_cam.y + 64}
end
pass = pass or 0
while p <= particle_array_length do
local particle = particle_array[p]
if particle.pass == pass then
if bor(band(0x8000, particle.life), band(bor(off[1]+particle.x, off[2]+particle.y), 0xff80)) != 0 then
particle_array[p], particle_array[particle_array_length] = particle_array[particle_array_length], nil
particle_array_length -= 1
else
local addr = bor(0x6000, bor(shr(off[1]+particle.x, 1), shl(band(off[2]+particle.y, 0xffff), 6)))
local pixel_pair = peek(addr)
if band(off[1]+particle.x, 1) == 1 then
pixel_pair = bor(band(pixel_pair, 0x0f), shl(particle.color, 4))
else
pixel_pair = bor(band(pixel_pair, 0xf0), particle.color)
end
poke(addr, pixel_pair)
particle.dy += particle.ddy
particle.x += particle.dx
particle.y += particle.dy
particle.life -= 1
if g_state == ge_state_menu then
for _, c in pairs(collision_objects) do
local collision_result = c:collides(particle)
if collision_result != nil then
particle.x += collision_result[1]
particle.y += collision_result[2]
particle.dy = 0
particle.dx = 0
end
end
end
p += 1
end
else
p +=1
end
end
end
collision_objects = {}
g_mogulneer_accel = 0.45
function make_snow_particles()
return {
update=function()
if g_state == ge_state_menu then
add_particle(rnd(128), 0, rnd_centered(0.5), 0.5+rnd(0.3), 270, 7, 0)
end
end,
draw=function()
process_particles()
end
}
end
function spray_particles()
return {
start_spray=0,
add_trail_spray=function()
local velmag = vecmag(g_p1.vel)
if velmag < 2 then
return
end
local amount = clamp(remap(velmag, 3, 5, 0, 1))
local n_trail_pts = #g_p1.trail_points
for i=0,25 do
if rnd() < amount or amount > 0.95 then
local ind = ceil(rnd(min(6, n_trail_pts)))
local pt = g_p1.trail_points[n_trail_pts - ind] or g_p1
pos = vecadd(
vecadd(vecscale(g_p1.ski_vec, rnd_centered(6)), pt),
vecfromangle(pt.perpendicular, rnd_centered(5))
)
add_particle(
pos.x, pos.y,
rnd_centered(0.5), 0.5+rnd(0.3),
270,
12,
0
)
end
end
end,
add_brake_spray=function()
if not g_p1.sliding then
return
end
local mag = -min(abs(g_p1.vel_against/1.5), 1)
for i=0,25 do
local ski_vec = vecfromangle(g_p1.perpendicular+rnd_centered(0.2),mag)
local off=vecadd(
vecscale(g_p1.ski_vec_perp, -3),
vecscale(g_p1.ski_vec, rnd_centered(6))
)
off = vecadd(off, vecrand(4, true))
local life = 30+rnd(5)
local num_parts = rnd() < 0.25 and 1 or 0
for i_x=0,num_parts do
for i_y=0,num_parts do
add_particle(
g_p1.x+off.x+i_x,
g_p1.y+off.y+i_y,
ski_vec.x,
max(ski_vec.y, -0.5),
life,
6,
-0.01,
1
)
end
end
end
end,
update=function(t)
if not g_p1.jumping then
t:add_trail_spray()
t:add_brake_spray()
end
end,
draw=function()
process_particles(sp_world)
end
}
end
function make_title()
return {
y=-64,
duration=40,
start_frame=g_tick-15,
start=vecmake(-264, -264),
target=vecmake(8, 20),
update=function(t)
local frame = elapsed(t.start_frame)
if frame < t.duration then
vecset(t, veclerp(t.start, t.target, smootherstep(frame/t.duration)))
for j=4,16*8,8 do
for i=0,15,2 do
local off=vecadd(t, vecrand(12, true))
add_particle(
j+off.x,
off.y,
rnd_centered(6),
1,
30+rnd(100),
7,
0.5
)
end
end
end
end,
draw=function(t)
spr(216, 44, 0, 3, 1)
spr(232, 42, 10, 4, 1)
spr(248, 42, 20, 4, 1)
palt(3, true)
palt(0, false)
spr(230, 48, 30, 2, 2)
if elapsed(t.start_frame) > t.duration then
print("by: @stephan_gfx ", 19, 46, 12)
print(" @stevelavieties", 19, 54, 12)
local ic_s = "controls are " .. (ge_inverted_controls and "inverted" or "not inverted")
print(ic_s, 8, 100, 7)
end
palt()
end,
}
end
function _init()
music(-1)
reset_shake()
g_flash_end = nil
g_flash_color =nil
particle_array, particle_array_length = {}, 0
stdinit()
add_gobjs(make_snow_trans(_title_stuff, 6))
end
function _title_stuff()
music(-1)
music(0)
g_state = ge_state_menu
stdinit()
add_gobjs(make_bg(6))
add_gobjs(make_title())
add_gobjs(make_snow_particles())
add_gobjs(
make_timer(
10,
function()
add(
collision_objects,
{
x=30,
y=80,
width=67,
height=24,
collides=function(t, part)
if (
part.x > t.x
and part.x - t.x < t.width
and part.y > t.y and
part.y - t.y < t.height
) then
return {0, -1}
end
end
}
)
add_gobjs(
make_menu(
track_names,
function (t, i, s)
if i < #tracks then
function done_func()
slalom_start(i+1)
end
add_gobjs(make_snow_trans(done_func, 7))
else
ge_inverted_controls = not ge_inverted_controls
end
end
)
)
end
)
)
end
function make_timer(time_to_wait, callback)
return {
start=g_tick,
time_to_wait=time_to_wait,
callback=callback,
update=function(t)
if elapsed(t.start) > t.time_to_wait then
del(t, g_objs)
t.callback()
t.update = nil
end
end
}
end
function _update()
stdupdate()
end
function _draw()
stddraw()
end
sp_world = 0
sp_local = 1
sp_screen_native = 2
sp_screen_center = 3
function add_gobjs(thing)
return add(g_objs, thing)
end
function ef_out_quart(amount)
local t = clamp(amount) - 1
return -1 * (t*t*t*t- 1)
end
function smootherstep(x)
return x*x*x*(x*(x*6 - 15) + 10);
end
function lerp(input, min_out, max_out)
return input * (max_out - min_out) + min_out
end
function remap(
val,
i_min,
i_max,
o_min,
o_max
)
return lerp((val-i_min)/(i_max-i_min), o_min, o_max)
end
function vecdraw(v, c, scale, o)
o = o or null_v
local end_point = vecadd(o, vecscale(v, scale or 30))
line(o.x, o.y, end_point.x, end_point.y, c)
return
end
function rnd_centered(max_val)
return rnd(max_val)-(max_val/2)
end
function vecrand(scale, center, yscale)
local result = vecmake(rnd(scale), rnd(yscale or scale))
if center then
result = vecsub(result, vecmake(scale/2, (yscale or scale)/2))
end
return result
end
function vecmake(xf, yf)
xf = xf or 0
return {x=xf, y=(yf or xf)}
end
function veccopy(tgt)
return vecmake(tgt.x, tgt.y)
end
null_v = vecmake()
function vecscale(v, m)
return {x=v.x*m, y=v.y*m}
end
function vecmagsq(v)
return v.x*v.x+v.y*v.y
end
function vecmag(v, sf)
if sf then
v = vecscale(v, sf)
end
local result=sqrt(vecmagsq(v))
if sf then
result=result/sf
end
return result
end
function vecdot(a, b)
return (a.x*b.x+a.y*b.y)
end
function vecadd(a, b)
return {x=a.x+b.x, y=a.y+b.y}
end
function vecsub(a, b)
return {x=a.x-b.x, y=a.y-b.y}
end
function vecflr(a)
return vecmake(flr(a.x), flr(a.y))
end
function vecset(target, source)
target.x = source.x
target.y = source.y
end
function vecfromangle(angle, mag)
mag = mag or 1.0
return vecmake(mag*cos(angle), mag*sin(angle))
end
function veclerp(v1, v2, amount, clamp)
local result = vecadd(vecscale(vecsub(v2,v1),amount),v1)
if clamp and vecmag((vecsub(result,v2))) < clamp then
result = v2
end
return result
end
function clamp(v, min_v, max_v)
return min(max(v, min_v or 0), max_v or 1)
end
function vecclamp(v, min_v, max_v)
return vecmake(
clamp(v.x, min_v.x, max_v.x),
clamp(v.y, min_v.y, max_v.y)
)
end
function make_player(p)
return {
x=0.1,
y=-3,
p=p,
space=sp_world,
vel=null_v,
vel_along=0,
vel_against=0,
bound_min=vecmake(-3, -4),
bound_max=vecmake(2,0),
angle=-0.25,
perpendicular=0.5,
turn_start = nil,
drag_scale = 1,
ski_vec=null_v,
ski_vec_perp=null_v,
skier_state=ge_skier_start,
trail_points={},
crashed=false,
made_timer = false,
last_push=g_tick,
c_drag_along=0.02,
c_drag_against=0.05,
sliding=false,
is_on_ice=nil,
drag_along_multiplier=5,
drag_against_multiplier=5,
jumping = nil,
jump_velocity = 0,
jump_height= 0,
mogul_off = 0,
g=null_v,
total_accel=null_v,
drag_along=null_v,
drag_against=null_v,
update=function(t)
if t.crashed then
t.vel = vecscale(t.vel, 0.9)
vecset(t, vecadd(t, t.vel))
g_cam.drift = true
g_cam.last_target_point = veccopy(t)
t.sliding = true
if not t.made_timer and vecmagsq(t.vel) < 0.1 then
t.made_timer = true
add_gobjs(
make_timer(
30,
function()
t.made_timer = false
t.vel = null_v
vecset(t, t.respawn_location)
t.crashed = false
t.sliding = false
t.skier_state = ge_skier_start
t.angle = -0.25
g_cam.drift = false
flash_screen(4, 8)
end
)
)
end
return
end
if t.skier_state != ge_skier_start then
t.skier_state = ge_skier_normal
end
local tgt_dir = nil
if btn(0, t.p) then
tgt_dir = ge_inverted_controls and 0 or -0.5
end
if btn(1, t.p) then
if tgt_dir != nil then
t.skier_state = ge_skier_wedge
else
tgt_dir = ge_inverted_controls and -0.5 or 0
end
end
if btn(3, t.p) then
if not tgt_dir then
tgt_dir = -0.25
else
tgt_dir = (tgt_dir -0.25)/2
end
end
if btn(2, t.p) then
t.skier_state = ge_skier_wedge
end
if btn(5, t.p) and t.skier_state != ge_skier_wedge then
t.skier_state = ge_skier_tuck
if (
(t.angle <= -0.45 or t.angle >= -0.05)
and elapsed(t.last_push) > 25
and vecmag(t.vel) < 1
)
then
t.vel = vecadd(t.vel, vecfromangle(t.angle, 2.5))
t.last_push = g_tick
end
end
if t.skier_state == ge_skier_start and not tgt_dir and not jmp then
return
elseif t.skier_state == ge_skier_start then
t.skier_state = ge_skier_normal
end
local jmp = btn(4, t.p)
if jmp then
t.jumping = t.jumping or g_tick
elseif t.jumping then
if t.jump_velocity < 0 then
t.jump_velocity = 0
elseif t.jump_height == 0 then
t.jumping = nil
end
end
if t.jumping == g_tick then
t.jump_velocity = -3.375
t.jump_height = 0
end
if t.jumping and t.jump_height <= 0 then
t.jump_velocity += g_mogulneer_accel
t.jump_height += t.jump_velocity
if t.jump_height > 0 then
t.turn_start = g_tick - 20
t.jump_height = 0
t.jump_velocity = 0
end
end
local turn_amount = (
(t.jumping and 0.021)
or ((t.skier_state == ge_skier_tuck) and 0.011)
or 0.015
)
if tgt_dir then
if t.turn_start == nil then
t.turn_start = g_tick
end
if tgt_dir > t.angle then
t.angle = min(t.angle + turn_amount, 0)
elseif tgt_dir < t.angle then
t.angle = max(t.angle - turn_amount, -0.5)
end
t.angle = clamp_to(t.angle, tgt_dir)
else
t.turn_start = nil
end
t.total_accel = t.jumping and null_v or t:acceleration()
t.vel = vecadd(t.vel, t.total_accel)
vecset(t, vecadd(t, t.vel))
for i=#t.trail_points,1,-1 do
if (t.y - t.trail_points[i].y > 100) then
del(t.trail_points, t.trail_points[i])
end
end
t.mogul_off = 0
for i=1,#g_mountain.p_objs do
local o = g_mountain.p_objs[i]
if overlaps_bounds(o, t) and o.overlaps then
o:overlaps(t)
end
end
t:add_new_trail_point(t)
end,
acceleration=function(t)
local ski_vec = vecfromangle(t.angle)
t.ski_vec = ski_vec
local perpendicular = t.angle - 0.25
if t.angle > -0.25 then
perpendicular = t.angle + 0.25
end
local ski_vec_perp = vecfromangle(perpendicular)
t.ski_vec_perp = ski_vec_perp
t.perpendicular = perpendicular
local drag_along_multiplier = 1
local drag_against_multiplier = 5
if t.skier_state == ge_skier_normal then
drag_along_multiplier = 5
elseif t.skier_state == ge_skier_wedge then
drag_along_multiplier = 25
drag_against_multiplier = 15
end
if t.is_on_ice and t.is_on_ice + 1 == g_tick then
drag_along_multiplier *= 0.5
drag_against_multiplier *= 0.4
end
if t.mogul_off > 0 then
drag_along_multiplier *= 5
drag_against_multiplier /= 3
end
t.drag_along_multiplier = lerp(0.3, t.drag_along_multiplier, drag_along_multiplier)
t.drag_against_multiplier = lerp(0.3, t.drag_against_multiplier, drag_against_multiplier)
local mod_ang = (0.25 - abs(0.25 + t.angle))*4
local ang_fact = ef_out_quart(mod_ang)
local g_accel = ang_fact * g_mogulneer_accel
local g = vecscale(ski_vec, g_accel)
t.ang_fact = ang_fact
t.g = g
local vel_along = vecdot(ski_vec, t.vel)
t.vel_along = vel_along
local vel_against = vecdot(ski_vec_perp, t.vel)
t.vel_against = vel_against
t.drag_along = vecscale(
ski_vec,
-1 * t.c_drag_along * t.drag_along_multiplier * vel_along*abs(vel_along)
)
local drag_scale = 1
if t.turn_start and elapsed(t.turn_start) < 30 then
drag_scale = cos(elapsed(t.turn_start)/(2*30))
drag_scale *= drag_scale
end
t.drag_scale = drag_scale
t.drag_against = vecscale(
ski_vec_perp,
-drag_scale * t.c_drag_against * t.drag_against_multiplier * vel_against
)
t.sliding = abs(vel_against) > abs(vel_along)
return vecadd(g, vecadd(t.drag_along, t.drag_against))
end,
draw=function(t, _, layername)
local pose = flr((t.angle + 0.25)*16)
if layername == "backmost" then
for i=2,#t.trail_points do
local real_p1 = t.trail_points[i-1]
local real_p2 = t.trail_points[i]
if not real_p1.gap and not real_p2.gap then
local p1 = vecflr(vecsub(real_p1, t))
local p2 = vecflr(vecsub(real_p2, t))
for off_mult=-1,1,2 do
local off_perp = vecfromangle(real_p2.perpendicular, off_mult)
local p1_off = vecadd(p1, off_perp)
local p2_off = vecadd(p2, off_perp)
line(
p1_off.x, p1_off.y,
p2_off.x, p2_off.y,
6
)
end
end
end
return
end
if not t.crashed then
for x_off=-1,1,2 do
local ang = t.angle
local offset = 1
if t.jumping or t.skier_state == ge_skier_wedge then
ang = t.angle-0.06*x_off
if t.jumping then
ang += 0.08*x_off
end
offset = 2
end
local jump_off = vecmake(0, t.jump_height)
local turn_off = vecscale(vecmake(cos(ang+0.25*x_off), sin(ang+0.25*x_off)), offset)
turn_off = vecadd(turn_off, jump_off)
local first_p = vecscale(vecmake(cos(ang), sin(ang)),4)
local last_p = vecscale(first_p, -1)
first_p = vecadd(first_p, turn_off)
last_p = vecadd(last_p, turn_off)
pushc(0, t.mogul_off)
line(first_p.x, first_p.y, last_p.x, last_p.y, 4)
circfill(first_p.x, first_p.y, 1, 8)
popc()
end
end
if t.jumping then
local shadow_size = lerp(smootherstep(-t.jump_height/18), 3, 1)
circfill(0, 0, shadow_size, 5)
end
local offset = 0
palt(0, false)
palt(3, true)
if t.skier_state == ge_skier_tuck then
palt(14, true)
palt(13, true)
offset = 2
else
palt(14, false)
pal(14, 11)
pal(13, 11)
end
local sprn = 17+abs(pose)*2
if t.crashed then
sprn = 29
elseif sprn == 25 and elapsed(t.last_push) < 5 or vecmag(t.vel) < 0.1 then
if t.skier_state != ge_skier_start then
sprn = 27
else
sprn = 100
local frame = flr(g_tick / 41) % 2
local y_offst = frame == 0 and 0 or 1
if not t.blink or t.blink == g_tick then
pal(7, 0)
t.blink = g_tick + 45+ flr(rnd(120))
end
for x_off=-3,3,6 do
line(x_off, -4+y_offst, x_off, 1+y_offst, 1)
line(x_off, -3+y_offst, x_off, -3+y_offst, 11)
end
end
end
pushc(0, t.mogul_off)
spr(sprn, -8, -11 + offset + t.jump_height, 2, 2, pose < 0)
popc()
palt()
pal()
g_cursor_y=12
jump_height_max = max(abs(t.jump_height), jump_height_max)
end,
add_new_trail_point=function(t, p)
p = vecadd(vecflr(p), vecmake(1))
p.gap = t.jumping or t.crashed
p.perpendicular = t.perpendicular
local last_point = t.trail_points[#t.trail_points]
if (
last_point == nil
or last_point.x != p.x
or last_point.y != p.y
) then
add(t.trail_points, p)
end
end
}
end
function clamp_to(val_to_clamp, val_to_clamp_to)
return abs(val_to_clamp - val_to_clamp_to) < 0.015 and val_to_clamp_to or val_to_clamp
end
function make_camera(x,y)
return {
x=x or 30,
y=y or 60,
low_pass=make_one_euro_filt(beta, mincutoff),
delta_offset = 0,
drift = false,
last_target_point = nil,
drift_start = nil,
update=function(t)
if g_state == ge_state_menu_trans then
return
end
local target_point = null_v
if g_p1 then
local offset = 20
if g_p1.vel then
offset += g_p1.vel.y*10
end
local new_offset = t.low_pass:filter(offset)
t.delta_offset = new_offset - offset
target_point = vecadd(g_p1, vecmake(0, new_offset))
if not t.drift then
t.last_target_point = target_point
t.last_vel = g_p1.vel
else
t.drift_start = t.drift_start or g_tick
target_point = t.last_target_point
if elapsed(t.drift_start) < 20 then
vecset(
t.last_target_point,
vecadd(
t.last_target_point,
veclerp(t.last_vel, null_v, elapsed(t.drift_start)/10)
)
)
end
end
end
vecset(t,veclerp(t,target_point,0.2,0.7))
if g_shake_end and g_tick < g_shake_end then
if (
not g_shake_frequency
or ((g_shake_end - g_tick) % g_shake_frequency) == 0
) then
vecset(t, vecadd(t, vecrand(g_shake_mag, true)))
end
end
vecset(t, vecflr(t))
end,
}
end
ge_inverted_controls = false
ge_trackitem_start = 0
ge_trackitem_end = 1
ge_trackitem_left = 2
ge_trackitem_right = 3
ge_trackitem_mogul = 10
ge_trackitem_text = 20
ge_trackitem_hole = 21
ge_trackitem_ice = 22
ge_state_menu = 0
ge_state_menu_trans = 1
ge_state_playing = 2
ge_skier_normal = 0
ge_skier_tuck = 1
ge_skier_wedge = 2
ge_skier_start = 3
gate_height = 10
gate_stem_color = 5
gate_flag_height = 4
gate_flag_width = 4
gate_flag_height_offset = 6
tracks = {
{
name = "first tracks",
course = {
{vecmake(), ge_trackitem_start, 32},
{vecmake(-48, 8), ge_trackitem_text, " press any key\nto start"},
{vecmake(-16, 64), ge_trackitem_text, " hold \nfor brakes"},
{vecmake(-48, 70), ge_trackitem_right},
{vecmake(32, 100)},
{vecmake(-48, 32), ge_trackitem_text, " hold \n to dash "},
{vecmake(-96, 140)},
{vecmake(0, 80)},
{vecmake(-20, 90)},
{vecmake(-45, 60), ge_trackitem_text, " press \nto jump over the hole!"},
{vecmake(-45, 80), ge_trackitem_hole, 12, 1},
{vecmake(-20, 200), ge_trackitem_text, "finish line!"},
{vecmake(0, 220), ge_trackitem_end, 16},
}
},
{
name = "powder days",
course = {
{vecmake(), ge_trackitem_start, 32},
{vecmake(-50, 90), ge_trackitem_right},
{vecmake(50, 90)},
{vecmake(200, 80)},
{vecmake(90, 90)},
{vecmake(-60, 90)},
{vecmake(-0, 90)},
{vecmake(0, 90), ge_trackitem_right},
{vecmake(0, 60)},
{vecmake(0, 60)},
{vecmake(-30, 40), ge_trackitem_hole, 12, 1},
{vecmake(-60, 120), ge_trackitem_hole, 12, 4},
{vecmake(0, 180)},
{vecmake(-30, 40), ge_trackitem_hole, 12, 1},
{vecmake(-60, 120), ge_trackitem_hole, 12, 4},
{vecmake(0, 220), ge_trackitem_end, 16},
}
},
{
name = "sunnyside",
course = {
{vecmake(), ge_trackitem_start, 32},
{vecmake(-50, 90), ge_trackitem_right},
{vecmake(50, 90)},
{vecmake(-10, 40), ge_trackitem_ice, 12, 1},
{vecmake(-50, 90)},
{vecmake(200, 80)},
{vecmake(90, 90)},
{vecmake(-60, 90)},
{vecmake(-0, 90)},
{vecmake(0, 90), ge_trackitem_right},
{vecmake(0, 60)},
{vecmake(0, 60)},
{vecmake(-30, 40), ge_trackitem_hole, 12, 1},
{vecmake(-60, 120), ge_trackitem_hole, 12, 4},
{vecmake(0, 180)},
{vecmake(-30, 40), ge_trackitem_hole, 12, 1},
{vecmake(-60, 120), ge_trackitem_hole, 12, 4},
{vecmake(0, 220), ge_trackitem_end, 16},
}
}
}
track_names = {}
foreach(tracks, function(t) add(track_names, t.name) end)
add(track_names, "invert controls")
ge_timerstate_stopped = 0
ge_timerstate_running = 1
function make_clock()
return {
x=64,
y=2,
c=0,
m=0,
s=0,
misses=0,
state=ge_timerstate_stopped,
start=function(t)
t.state = ge_timerstate_running
end,
stop=function(t)
t.state = ge_timerstate_stopped
end,
draw=function(t)
rectfill(-16,-1,16,5,6)
local mp,sp,cp = '','',''
if t.m<10 then
mp=0
end
if t.s<10 then
sp=0
end
if t.c < 10 then
cp=0
end
print(mp..t.m..':'..sp..t.s.."."..cp..t.c, -15,0,0)
local ndigits=6
if t.misses > 9 then
ndigits +=1
end
if t.misses > 99 then
ndigits += 1
end
local half_len = ndigits/2
rectfill(-half_len*4, 7, half_len*4, 13, 6)
print("miss:"..t.misses, -half_len*4+1, 8, 0)
end,
increment=function(t, amount)
for i=1,amount do
t.c+=1
if t.c>=30 then
t.c=0
t.s+=1
if t.s>=60 then
t.s=0
t.m+=1
end
end
end
end,
update=function(t)
if t.state == ge_timerstate_stopped then
return
end
t:increment(1)
end,
inc_missed_gate = function(t)
t.misses += 1
shake_screen(min(15*(vecmag(g_p1.vel)/4), 5), 15, 3)
flash_screen(4, 8)
end
}
end
function make_score_display(base_timer, score_mode, track_ind)
local total_misses = base_timer.misses
return {
y=-192,
start=vecmake(0, -192),
target=vecmake(0, -4),
frame=15,
made=g_tick,
duration=25,
space=sp_world,
update=function(t)
if t.frame < t.duration then
vecset(t, veclerp(t.start, t.target, smootherstep(t.frame/t.duration)))
end
t.frame += 1
if t.frame < t.duration then
for j=-32,32,8 do
for i=0,30 do
local off=vecrand(6, true)
add_particle(
j+t.x + off.x+rnd_centered(6),
t.y + off.y+rnd_centered(6),
0 + rnd_centered(6),
3+rnd(1),
8,
6,
0.5
)
end
end
elseif (
base_timer.misses
and base_timer.misses > 0
and t.made and (elapsed(t.made) % 15) == 0
) then
base_timer.misses -= 1
g_timer:increment(50)
shake_screen(8, 5)
flash_screen(4, 8)
end
if (
t.made
and elapsed(t.made) > 45
and (score_mode or base_timer.misses == 0)
) then
t.made = nil
local menu_items = {'try track again'}
local n_tracks = #tracks
if track_ind != n_tracks then
add(menu_items, 'next track')
end
add(menu_items, 'main menu')
add_gobjs(
make_menu(
menu_items,
function (t, i, s)
local function done_func()
if i==0 then
slalom_start(track_ind)
elseif i==2 or track_ind == n_tracks then
_title_stuff()