forked from stevelavietes/pico8carts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dead_mans_slope.p8
2917 lines (2646 loc) · 94.4 KB
/
dead_mans_slope.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
-- skiiiii
-- cool flavor:
-- draw the hat when you crash
-- skis skitter down the mountain
-- birds that fly away when you go by
-- little bit of always falling snow
-- wind?
-- done:
-- don't spawn trees near the player [x]
-- make trees spawn to the left and right as well as up and down [x]
-- add a point counter for back country mode [x]
-- token pass [x]
-- add music [x]
-- rock spawn location [x]
-- make the camera focus on the finish line when you cross it instead of the player in slalom mode [x]
-- fix the player standing back up after crashing [x]
-- bend course to show better which way the player should go [x]
-- use curved lines instead of straight lines [x]
-- penalty for missing gates [x]
-- animation that "pays out" the missed gates penalty on your final time [x]
-- jump that you can control the height of (like mario) [x]
-- make skis spread out while jumping [x]
-- kill downarrow hunker down mode [x]
-- a jump system [x]
-- split the spray up into two objects, one underneath the player, one on top
-- can't do ^ because rght now there is one and only one particle bank
-- "z-sorted" tree drawing system [x]
-- tune the brake spray to be lighter [x]
-- pointing down should still give you a bit more gravity than pointing across the mountain [x]
-- when flat, the tuck button should give you a push (rather than the arrows) [x]
-- maybe the up button brakes? increases the drag on both dimensions? [x]
-- fix interaction of tuck and wedge [x]
-- trail doesn't line up with mogulneer/skis right [x]
-- start facing downwards [x]
-- don't let the player move until they hit a key [x]
-- add starting hut with gate bar that flies up when you hit a button [x]
-- diagonal presses should still point you diagonally [x]
-- where did the music go on the start screen? [x]
-- don't like the way the trail collapses when you're going diagonal down left [x]
-- X under a missed flag instead of an O [x]
-- refactor gate constructor/gate data to need less placeholder [x]
-- moguls, push your skiier up as you go over them. [x]
-- put track names into menu [x]
-- better backcountry score display
-- increase the top speed as the level goes on (backcountry mode)
-- ice that makes you slide [x]
-- holes spawn you below them after a time penalty (+ speed penalty) [x]
-- add pits [x]
-- add ice [x]
-- strip out backcountry mode [x]
-- make trees things that collide with you [x]
-- fix menus after completing a level to go to the next one, replay the current, or go to the main menu [x]
-- menu snow doesn't sit on the text box fully [x]
-- title text above starting gate [x]
-- no shake on crash for some reason [x]
-- some trees aren't spawning outside of the track [x]
-- message on 0 misses "NICE" [x]
-- misses: count up to total instead of down [x]
-- "TRACK SELECT" header on text box [x]
-- DEAD MAN'S SLOPE? [x]
-- token pass [x]
-- today:
-- third level moving holes to that
-- move up menu box (and entire screen, really)
-- adjust size of menubox collider
-- probably not:
-- rotation momentum on jump landing
-- use moguls to impact jump height
-- make missing the end gates also a penalty
-- retune penalties with current speed
-- add crashing to slalom
-- after jumping give a boost to drag against and reduction to drag along to get a bit of a zigzag going
-- a little pop of confetti when you clear a gate would be cool
-- add a "GO!" sprite at the beginning of slalom mode
-- find some way to add a little bit of animation to the trees maybe? Really static right now
-- add a button prompt with the "dash" button
-- maybe cheering crowds in slalom mode? something else to help cue you for your progress in the level!
-- retune camera filter (add some x to it too?)
-- maybe move jump to up instead of brake?
-- add sfx
-- turn
-- gate hit
-- gate miss
-- end of the slalom
-- menu select
-- mute_debug = true
-- @{ one euro filter impl, see: http://cristal.univ-lille.fr/~casiez/1euro/
-- 1 euro filter parameters, tuned to make the effect visible
beta = 0.0001
mincutoff = 0.0001
-- mincutoff = 0.0003
function make_one_euro_filt(beta, mincutoff)
return {
first_time = true,
dx = 0,
rate = 0.0333, --1/30
mincutoff = mincutoff, -- hz
beta = beta, -- cutoff slope
d_cutoff = 0, -- derivative cutoff
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
-- @}
-- { particle stuff
function add_particle(x, y, dx, dy, life, color, ddy, pass)
particle_array_length += 1
-- grow if needed
if (#particle_array < particle_array_length) add(particle_array, 0)
-- insert into the next available spot
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)
-- @casualeffects particle system
-- http://casual-effects.com
-- simulate particles during rendering for efficiency
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}
-- 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
-- the bitwise expression will have the high (negative) bit set
-- if either coordinate is negative or greater than 127, or life < 0
if bor(band(0x8000, particle.life), band(bor(off[1]+particle.x, off[2]+particle.y), 0xff80)) != 0 then
-- delete dead particles efficiently. pico8 doesn't support
-- table.setn, so we have to maintain an explicit length variable
particle_array[p], particle_array[particle_array_length] = particle_array[particle_array_length], nil
particle_array_length -= 1
else
-- draw the particle by directly manipulating the
-- correct nibble on the screen
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
-- even x; we're writing to the high bits
pixel_pair = bor(band(pixel_pair, 0x0f), shl(particle.color, 4))
else
-- odd x; we're writing to the low bits
pixel_pair = bor(band(pixel_pair, 0xf0), particle.color)
end
poke(addr, pixel_pair)
-- acceleration
particle.dy += particle.ddy
-- advance state
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 -- if alive
else
p +=1
end -- if pass
end -- while
end
collision_objects = {}
-- }
g_mogulneer_accel = 0.45
-- { debug stuff can be deleted
-- function make_debugmsg()
-- local maxmem=stat(2)
-- local minmem=stat(2)
-- return {
-- space=sp_screen_native,
-- draw=function(t)
-- if mute_debug == true then
-- return
-- end
-- maxmem = max(maxmem, stat(0)/1024)
-- -- minmem = min(minmem, stat(2))
-- color(14)
-- cursor(1,1)
-- print("cpu: ".. stat(1))
-- print("mem: ".. stat(0)/1024)
-- print(" max:" ..maxmem)
-- print("gst: "..state_map[g_state])
-- print("sld: "..repr(g_p1.sliding))
-- -- print("smg: "..repr(g_shake_mag))
-- -- print("shf: "..repr(g_shake_frequency))
-- -- print("lst: "..repr(last_shake))
-- if g_p1 then
-- print("vel: ".. vecmag(g_p1.vel))
-- print("ang: ".. g_p1.angle)
-- -- print("g: ".. repr(g_p1.perp_dot))
-- print("d_al: ".. vecmag(g_p1.drag_along))
-- print("d_ag: ".. vecmag(g_p1.drag_against))
-- print("t_a: ".. vecmag(g_p1.total_accel))
-- print("g: ".. vecmag(g_p1.g))
-- if g_p1.amount then
-- print("amt: ".. g_p1.amount)
-- end
-- print("ice: "..repr(g_p1.is_on_ice == g_tick))
-- -- if not g_p1.svp then
-- -- g_p1.svp = null_v
-- -- end
-- -- print("v_d: ".. repr(vecdot(g_p1.svp, g_p1.vel)))
-- -- print("d_o: ".. g_cam.delta_offset)
-- end
-- end
-- }
-- end
-- dead code
-- function repr(arg)
-- -- turn any thing into a string (table, boolean, whatever)
-- if type(arg) == "table" then
-- local retval = " table{ "
-- for k, v in pairs(arg) do
-- retval = retval .. k .. ": ".. repr(v).. ","
-- end
-- retval = retval .. "} "
-- return retval
-- end
-- return tostr(arg)
-- end
-- -- }
--
function make_snow_particles()
return {
update=function()
if g_state == ge_state_menu then
-- make snow
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
pos.x, pos.y,
-- vel
rnd_centered(0.5), 0.5+rnd(0.3),
270,
12, -- col
0 -- pass
)
end
end
end,
add_brake_spray=function()
if not g_p1.sliding then
return
end
-- compute the spray angle
-- along the perpendicular
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)
-- makes bigger chunks some % of the time
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,--+rnd(1),
max(ski_vec.y, -0.5),--+rnd(1),
life, -- life
6, -- col
-0.01, --ddy
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,
-- 3+rnd(1),
30+rnd(100),
7,
0.5
)
end
end
end
end,
draw=function(t)
-- spr(128, 0, 0, 16,4)
-- pushc(-64, -64)
-- g_cursor_y = -37
-- g_cursor_y = -47
-- print_cent("dead", 12)
-- print_cent("man's", 12)
-- print_cent("slope", 12)
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_debugmsg())
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))
-- add_gobjs(make_debugmsg())
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()
-- @TODO: why is this not deleting itself?
t.update = nil
end
end
}
end
function _update()
stdupdate()
end
function _draw()
stddraw()
end
-- coordinate systems
sp_world = 0
sp_local = 1
sp_screen_native = 2
sp_screen_center = 3
-- @{ useful utility function for getting started
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)
-- assumes x in [0, 1]
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
-- assumes coord [0, 1]
-- function bilinear_interp(coord, f00, f01, f10, f11)
-- return (
-- f00 * (1 - coord.x) * (1 - coord.y)
-- + f10 * coord.x * (1 - coord.y)
-- + f01 * (1 - coord.x) * coord.y
-- + f11 * coord.x * coord.y
-- )
-- 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
-- @}
-- @{ vector library
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
-- global null vector
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 vecnormalized(v)
-- return vecscale(v, 1/vecmag(v))
-- 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 vecminvec(target, minvec)
-- target.x = min(target.x, minvec.x)
-- target.y = min(target.y, minvec.y)
-- return target
-- end
-- function vecmaxvec(target, maxvec)
-- target.x = max(target.x, maxvec.x)
-- target.y = max(target.y, maxvec.y)
-- return target
-- 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)
-- tokens: can compress this with ternary
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
-- @}
-- @{ built in diagnostic stuff
function make_player(p)
return {
x=0.1, -- not 0 - that messes the flr up in add_new_trail_point
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, -- ski angle
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.1,
c_drag_against=0.05,
sliding=false,
is_on_ice=nil,
drag_along_multiplier=5,
drag_against_multiplier=5,
-- jump
jumping = nil,
jump_velocity = 0,
jump_height= 0,
-- mogul
mogul_off = 0,
-- debug variables
g=null_v,
total_accel=null_v,
drag_along=null_v,
drag_against=null_v,
update=function(t)
-- crash case
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
)
)
-- function done_func()
-- make_score_screen(g_bc_score, true)
-- end
-- add_gobjs(make_snow_trans(done_func, 7, 45))
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
-- left
tgt_dir = ge_inverted_controls and 0 or -0.5
end
if btn(1, t.p) then
-- right
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
-- down
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
-- up
-- t.angle = abs(t.angle) < 0.25 and 0 or -0.5
t.skier_state = ge_skier_wedge
end
-- tuck
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
-- push right
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)
-- jump button states
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
-- jump acceleration == mogulneer acceleration for now
end
if t.jumping and t.jump_height <= 0 then
-- apply euler integration to the jump
t.jump_velocity += g_mogulneer_accel
t.jump_height += t.jump_velocity
-- @todo: this jumping model assumes a flat plane.
-- should compute the slope of the slope and then figure out when
-- the player crosses the plane of the snow again. but this might
-- just work well enough even though it isn't correct.
-- could just accumulate the y component of the velocity and then
-- multiply that by the slope of the slope each tick to move the target
-- height down each tick as long as the player falls faster than they move down the slope, they'll hit the ground
if t.jump_height > 0 then
-- reset the jump
t.turn_start = g_tick - 20
t.jump_height = 0
t.jump_velocity = 0
end
end
-- tuck based turnability scaling
local turn_amount = (
(t.jumping and 0.021)
or ((t.skier_state == ge_skier_tuck) and 0.011)
-- wedge or normal
or 0.015
)
-- sets up the current direction of the skis, "brakes"
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
-- compute the acceleration
t.total_accel = t.jumping and null_v or t:acceleration()
-- euler integration for now
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)
-- ski direction unit vector
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
-- helps with stablility
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)
-- component of gravity along the skis (acceleration)
-- remap angle [0,-0.25], [-0.25, -0.5] to [0, 1]
local mod_ang = (0.25 - abs(0.25 + t.angle))*4
-- apply easing
local ang_fact = ef_out_quart(mod_ang)
-- scale
local g_accel = ang_fact * g_mogulneer_accel
-- turn into a vector
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
-- drag along the ski is against the component of velocity along the ski
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)