forked from ssteinbach/pico8carts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
world_space.p8
1381 lines (1242 loc) · 54.2 KB
/
world_space.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 8
__lua__
-- [co]sine tables
cal = {}
sal = {}
function compute_tables()
for theta=0,359 do
local angle=theta/360
local ca = cos(angle)
local sa = sin(angle)
cal[theta] = {}
sal[theta] = {}
for x=-8,8 do
local y = x
cal[theta][x] = ca * y
sal[theta][x] = sa * y
end
end
end
function tprint(str)
local tcurrent = time()
print(str..": "..tcurrent-tlast)
tlast = tcurrent
end
function compute_planet_noise()
tlast = time()
sprites_wide = 4
radius=(sprites_wide/2)*8
local xmin=0
local xmax=sprites_wide*8
local xcenter=(xmax-xmin)/2 + xmin
local ymin=4*8
local ymax=(4+sprites_wide)*8
local ycenter=(ymax-ymin)/2 + ymin
local copies_x = 3
local copies_y = 2
-- using the algorithm from star control 2, noted in the GDC retro game post
-- mortem - generate a bunch of lines and raise/lower the height map between
-- those regions, then quantize and map the colors
-- base height
for x=xmin,xmax do
for y=ymin,ymax do
sset(x,y,7)
end
end
cls()
function rnd_point()
-- return {rnd(sprites_wide*8-8)+xmin+4, rnd(sprites_wide*8-8)+ymin+4}
local result={
rnd(xmax-xmin)+xmin,
rnd(ymax-ymin)+ymin
}
return result
end
local img = {}
local cmin = 0
local cmax = 50
for x=xmin,xmax do
img[x] = {}
for y=ymin,ymax do
img[x][y] = flr(cmax/2)
end
end
tprint("setup")
function rnd_line()
local sp=rnd_point()
local ep=rnd_point()
local xd = ep[1] - sp[1]
local yd = ep[2] - sp[2]
local fac = sp[2]*xd-sp[1]*yd
return {
startp=sp,
endp=ep,
xd=xd,
yd=yd,
fac=fac,
s_dist=function(t, x, y)
return (x*t.yd - y*t.xd + t.fac)
end
}
end
-- generate lines and raise stuff where we are on opposite side of the lines
-- lower where we're on the same side
for i=0,cmax do
local l1 = rnd_line()
local l2 = rnd_line()
for x=xmin,xmax do
local ln=img[x]
for y=ymin,ymax do
if (l1:s_dist(x,y) < 0) != (l2:s_dist(x,y) < 0) then
ln[y] = ln[y]+1
else
ln[y] = ln[y]-1
end
end
end
end
tprint("noise")
local hist = {}
hist[1] = 0
hist[2] = 0
hist[3] = 0
hist[4] = 0
-- quantize
for x=xmin,xmax do
local ln=img[x]
for y=ymin,ymax do
local val = ln[y]
-- local c=val
local c=4
if val < cmax/4 + 0.2*cmax then
c=1
elseif val < cmax/2 + 0.1*cmax then
c=2
elseif val < 3*cmax/4 - 0.05*cmax then
c=3
end
hist[c] +=1
sset(x,y,c)
end
end
for i=1,4 do
print(i..": ".. hist[i])
end
tprint("quantize")
-- rotation
local ycenter = (radius+ymin)
local r2 = radius*radius
for y=ymin,ymax do
local b = abs(y-ycenter)
local a = sqrt(r2-b*b)
local rotation_scale = 4*cos(atan2(a, b))
for x=xmin,xmax do
local c = sget(x,y)
for off_y=0,copies_y do
local new_y = y+off_y*4*8
for off_x=0,copies_x do
if off_x > 0 or off_y > 0 then
local rotation_offset = (x+rotation_scale*((off_x-((copies_x+1)*(copies_y+1))/2)+(off_y)*(copies_x+1)))%(xmax)
local new_x = rotation_offset+off_x*(4*8)
sset(new_x,new_y,c)
end
end
end
end
end
tprint("rotation")
-- add poles and make round
for x=xmin,xmax do
local xd=x-xcenter
local xd2=xd*xd
for y=ymin,ymax do
local yd=y-ycenter
local c=1
-- crop out corners to make look round
if xd2+yd*yd < 2*8*2*8 then
-- poles
if ymax-y < 2 or y-ymin < 2 then
c=7
end
else
c=0
end
for off_x=0,copies_x do
local new_x = x+off_x*4*8
for off_y=0,copies_y do
if c == 0 or c==7 then
local new_y = y+off_y*4*8
sset(new_x,new_y,c)
end
end
end
end
end
tprint("poles")
-- if true then
-- spr(64,0,0,16,16)
-- tprint("final")
-- stop()
-- return
-- end
end
function _init()
stdinit()
compute_tables()
compute_planet_noise()
add(
g_objs,
make_menu(
{
'go',
},
function (t, i, s)
add (
s,
make_trans(
function()
game_start()
end
)
)
end
)
)
g_st = gst_menu
end
gst_menu = 0
gst_playing = 1
function _update()
stdupdate()
end
function _draw()
stddraw()
end
-- coordinate systems
sp_world = 0
sp_local = 1
sp_screen_native = 2
sp_screen_center = 3
function am_playing()
return g_st == gst_playing
end
function makev(xf, yf)
return {x=xf, y=yf}
end
-- rotate a sprite
function rotate_sprite(
angle,tcolor,sspx,sspy
)
local cala = cal[angle]
local sala = sal[angle]
for x=-7,6,1 do
for y=-7,6,1 do
-- 2d rotation about the origin
xp = (- cala[x]+sala[y])
yp = ( sala[x]+cala[y])
-- if the pixel is over range,
-- use the transparent color
-- otherwise fetch the color from
-- the sprite sheet
local c = tcolor
if abs(xp) < 8 and abs(yp) < 8 then
c = sget(xp+sspx,yp+sspy)
end
-- set a color in the sprite
-- sheet
sset(x+sspx+16,y+sspy,c)
end
end
end
function make_pushable(x,y)
return make_physobj(
{
x=x,
y=y,
name="pushable_["..x..","..y.."]",
space=sp_world,
vis_r=5,
draw=function(t)
circfill(0,0,5,6)
circfill(0,0,2,2)
circ(0,0,t.vis_r, 8)
circ(0,0,t.radius, 9)
end
},
100
)
end
-- @{ built in diagnostic stuff
function make_player(pnum)
return make_physobj(
{
x=0,
y=0,
pnum=pnum,
name="player"..pnum,
space=sp_world,
c_objs={},
vis_r=7,
sprite=32,
theta = 0,
rendered_rot=nil,
update=function(t)
if not am_playing() then
return
end
local m_x = 0
local m_y = 0
local thrust = false
if btn(0, t.pnum) then
t.theta -= 10
if t.theta < 0 then
t.theta += 360
end
end
if btn(1, t.pnum) then
t.theta += 10
if t.theta >= 360 then
t.theta -= 360
end
end
if btn(2, t.pnum) then
thrust = true
end
if btn(3, t.pnum) then
t.velocity = vecscale(t.velocity, 0.8)
end
if thrust then
m_x = cal[t.theta][-1]
m_y = sal[t.theta][1]
end
add_force(t, makev(m_x, m_y))
updateobjs(t.c_objs)
end,
draw=function(t)
-- for a double size sprite
--spr(3, -7, -7,2,2)
rect(-3,-3, 3,3, 8)
local str = "world: " .. t.x .. ", " .. t.y
print(str, -(#str)*2, 12, 8)
str="theta: " .. t.theta
print(str, -(#str)*2, 18, 8)
local col=3
if (g_cam:is_visible(t)) then
col=11
end
circ(0,0,t.vis_r,col)
local col_list = {}
for _, o in pairs(g_objs) do
if t ~= o and o.is_phys and not collided and collides_circles(t, o) then
col=col+1
add(col_list, o)
end
end
if #col_list > 0 then
local col_str = "colliding:"
for _, o in pairs(col_list) do
col_str = col_str .. " " .. o.name
end
print(col_str, -(#col_str)*2, 22, 8)
end
pusht({{3, true},{0,false}})
if t.rendered_rot != t.theta then
rotate_sprite(t.theta,3,23,23)
t.rendered_rot = t.theta
end
spr(t.sprite+4, -7, -7,2,2)
popt()
drawobjs(t.c_objs)
circ(0,0,t.radius,col)
end
},
5
)
end
g_friction=0.1
function update_phys(o)
-- in case we want to play
-- with time, even though pico
-- gives us a constant clock
local dt = 1
o.x, o.velocity.x=compute_force_1d(
o.x,
o.force.x,
o.mass,
o.velocity.x,
dt
)
o.y, o.velocity.y=compute_force_1d(
o.y,
o.force.y,
o.mass,
o.velocity.y,
dt
)
-- zero out the force
o.force = makev(0,0)
-- drag
o.force.x -= g_friction*o.velocity.x
o.force.y -= g_friction*o.velocity.y
end
function vecstr(v)
return ""..v.x..", "..v.y
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 vecmult(a, b)
return {x=a.x*b.x, y=a.y*b.y}
end
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 vecrot(v, a)
local s = sin(a/360)
local c = cos(a/360)
return {
x=v.x * c - v.y * s,
y=v.x * s + v.y * c,
}
end
function vecdistsq(a, b, sf)
if sf then
a = vecscale(a, sf)
b = vecscale(b, sf)
end
local distsq = (b.x-a.x)^2 + (b.y-a.y)^2
if sf then
distsq = distsq/sf
end
return distsq
end
null_v = makev(0,0)
function vecnorm(v)
local l =
sqrt(vecdistsq(null_v,v))
return {
x=v.x/l,
y=v.y/l,
}
end
function update_collision(o, o_num)
-- (checking o, pos is new pos
-- check boundaries first
local pos = makev(o.x, o.y)
-- pos.x, o.velocity.x = collide_walls_1d(
-- g_edges[1],pos.x,o.velocity.x,o.radius)
-- pos.y, o.velocity.y = collide_walls_1d(
-- g_edges[2],pos.y,o.velocity.y,o.radius)
for i=o_num,#g_objs do
local t = g_objs[i]
if t.is_phys and t ~= o then
if collides_circles(t, o) then
if not t.is_static then
-- current displacement
local t_pos = makev(t.x, t.y)
-- push the objects back
local r = o.radius + t.radius
local v = vecsub(pos,t_pos)
local v_n = vecnorm(v)
local new_pos = vecadd(vecscale(v_n, r),t_pos)
-- result
o.x = new_pos.x
o.y = new_pos.y
-- a.v = (a.u * (a.m - b.m) + (2 * b.m * b.u)) / (a.m + b.m)
-- b.v = (b.u * (b.m - a.m) + (2 * a.m * a.u)) / (a.m + b.m)
local o_v = o.velocity
local t_v = t.velocity
local o_m = o.mass
local t_m = t.mass
o.velocity = vecscale(
vecadd(vecscale(o_v, (o_m-t_m)), vecscale(t_v,2*t_m)),
1/(o_m+t_m)
)
t.velocity = vecscale(vecadd(vecscale(t_v, (t_m-o_m)),(vecscale(o_v,2*o_m))),(1/(o_m+t_m)))
end
end
end
end
end
function collides_circles(o1, o2)
local x_d = abs(o1.x - o2.x)
local y_d = abs(o1.y - o2.y)
local r_2 = o1.radius + o2.radius
-- cheat to avoid huge squares
if x_d > r_2 or y_d > r_2 then
return false
end
return ((x_d*x_d)+(y_d*y_d)) < r_2 * r_2
end
-- creates a physics object out
-- of the parent object with a
-- given mass
function make_physobj(p,mass)
phys = {
p=p,
mass=mass,
force=makev(0,0),
velocity=makev(0,0),
radius=p.vis_r or 5,
is_phys=true,
is_static=false,
}
for k,v in pairs(phys) do
p[k] = v
end
return p
end
g_tstack={}
-- takes a list of tuples color, tval
function pusht(tlist)
-- todo make push/pop work better
add(g_tstack, tlist)
for i, ttuple in pairs(tlist) do
palt(ttuple[1], ttuple[2])
end
end
function popt(tlist)
local len = #g_tstack
local last = g_tstack[len]
for i, ttuple in pairs(last) do
palt(ttuple[1], not ttuple[2])
end
g_tstack[len] = nil
end
g_spacing = 64
function make_infinite_grid()
return {
x=0,
y=0,
space=sp_screen_native,
draw=function(t)
local g_o_x = 128 - g_cam.x % 128
local g_o_y = 128 - g_cam.y % 128
local smin = vecsub(makev(g_cam.x, g_cam.y), makev(64, 64))
for x=0,3 do
for y=0,3 do
-- screen coordinates
local xc = (x-1.5)*g_spacing + g_o_x
local yc = (y-1.5)*g_spacing + g_o_y
rect(xc-1, yc-1,xc+1, yc+1, 5)
circ(xc, yc, 7, 5)
-- label
local str = "w: " .. xc + smin.x .. ", ".. yc + smin.y
print(str, xc-#str*2, yc+9, 5)
end
end
end
}
end
-- assumed to be in world space
function make_camera()
return {
x=0,
y=0,
is_visible=function(t, o)
-- uses a circle based visibility check
if not o.vis_r or
(
(
t.x - 64 - o.vis_r < o.x
and t.x + 64 + o.vis_r > o.x
)
and
(
t.y - 64 - o.vis_r < o.y
and t.y + 64 + o.vis_r > o.y
)
)
then
return true
end
return false
end,
update=function(t)
t.x=g_p1.x
t.y=g_p1.y
end,
draw=function(t)
end
}
end
-- @}
function make_debugmsg()
return {
x=0,
y=0,
space=sp_screen_native,
draw=function(t)
color(14)
print("",0,0)
print("cpu: ".. stat(1))
print("mem: ".. stat(2))
local vis="false"
if g_p2 and g_cam:is_visible(g_p2) then
vis = "true"
end
if g_p2 then
print("p2 vis: ".. vis)
print(g_cam.x-64-g_p2.vis_r .. ", " ..g_cam.y-64-g_p2.vis_r)
print("vel: ".. vecmag(g_p1.velocity))
print("p_vel: ".. vecmag(g_pushable.velocity))
end
end
}
end
function make_planet(x,y)
return {
x=x,
y=y,
name="planet_planetulon",
space=sp_world,
frame=0,
update=function(t)
t.frame +=1
end,
draw=function(t)
local f = flr((t.frame/16)) % 12
local fx = f % sprites_wide
-- local fx = flr(f / 3)
local fy = flr(f / sprites_wide)
-- local fy = f % 4
-- for i=1,9 do
-- pal(i,12)
-- end
-- for i=10,12 do
-- pal(i, 3)
-- end
-- for i=13,15 do
-- pal(i, 4)
-- end
-- pal(7,7)
pal(1,12)
pal(2,4)
pal(3,3)
pal(4,7)
spr(64+(fx+fy*sprites_wide*sprites_wide)*sprites_wide,-radius,-radius,sprites_wide,sprites_wide)
for i=0,15 do
pal(i,i)
end
print(fx..", "..fy, -10, 20, 7)
-- for i=1,14 do
-- palt(i,true)
-- end
-- pal(15,6)
-- spr(64+4*(flr((t.frame+8)/4)%4),-2*8,-2*8,4,4)
-- pal(15,15)
-- for i=1,14 do
-- palt(i,false)
-- end
end
}
end
function game_start()
g_objs = {
}
add(g_objs, make_infinite_grid())
g_cam= make_camera()
add(g_objs, g_cam)
add(g_objs, make_planet(32,32))
g_p1 = make_player(0)
add(g_objs, g_p1)
-- add in pushable things
for i=0,0 do
local collides = true
local pushable = make_pushable(10, 10)
while collides==true do
pushable.x = rnd(128) - 64
pushable.y = rnd(128) - 64
collides = false
for _, o in pairs(g_objs) do
if o.is_phys and not collides and collides_circles(o, pushable) then
collides = true
end
end
end
add(g_objs, pushable)
g_pushable = pushable
end
add(g_objs, make_debugmsg())
g_st = gst_playing
-- g_brd = make_board()
-- add(g_objs, g_brd)
-- g_tgt = make_tgt(0,0)
-- add(g_objs,g_tgt)
end
------------------------------
function stdinit()
g_tick=0 --time
g_ct=0 --controllers
g_ctl=0 --last controllers
g_cs = {} --camera stack
g_objs = {} --objects
end
function stdupdate()
g_tick = max(0,g_tick+1)
-- current/last controller
g_ctl = g_ct
g_ct = btn()
updateobjs(g_objs)
end
function add_force(o, f)
o.force.x += f.x
o.force.y += f.y
end
function compute_force_1d(pos, f, m, v, dt)
local a=0
if f ~= 0 then
a = f/m
end
-- update position half way
pos += 0.5 * dt * v
-- update velocity (drag)
v += dt * a
-- update position other half
pos += 0.5 * dt * v
return pos, v
end
function foreachp(lst, fnc)
for i, o in pairs(lst) do
if o.is_phys then
fnc(o, i)
end
end
end
function updateobjs(objs)
foreach(objs, function(t)
if t.update then
t:update(objs)
end
end)
-- update physics code
foreachp(objs, update_phys)
foreachp(objs, update_collision)
end
function stddraw()
cls()
drawobjs(g_objs)
end
function drawobjs(objs)
foreach(objs, function(t)
if t.draw then
if g_cam and not g_cam:is_visible(t) then
return
end
local cam_stack = 0
-- i think the idea here is that if you're only drawing local,
-- then you only need to push -t.x, -t.y
-- if you're drawing camera space, then the camera will manage the screen
-- center offset
-- if you're drawing screen center
if t.space == sp_screen_center then
pushc(-64, -64)
cam_stack += 1
elseif t.space == sp_world and g_cam then
pushc(g_cam.x - 64, g_cam.y - 64)
pushc(-t.x, -t.y)
cam_stack += 2
elseif not t.space or t.space == sp_local then
pushc(-t.x, -t.y)
cam_stack += 1
elseif t.space == sp_screen_native then
end
t:draw(objs)
for i=cam_stack,0,-1 do
popc()
end
end
end)
end
--returns state,changed
function btns(i,p)
i=shl(1,i)
if p==1 then
i=shl(i,8)
end
local c,cng =
band(i,g_ct),
band(i,g_ctl)
return c>0,c~=cng
end
--returns new press only
function btnn(i,p)
if p==-1 then --either
return btnn(i,0) or btnn(i,1)
end
local pr,chg=btns(i,p)
return pr and chg
end
function getspraddr(n)
return flr(n/16)*512+(n%16)*4
end
function sprcpy(dst,src,w,h)
w = w or 1
h = h or 1
for i=0,h*8-1 do
memcpy(getspraddr(dst)+64*i,
getspraddr(src)+64*i,4*w)
end
end
function pushc(x, y)
local l=g_cs[#g_cs] or {0,0}
local n={l[1]+x,l[2]+y}
add(g_cs, n)
camera(n[1], n[2])
end
function popc()
local len = #g_cs
g_cs[len] = nil
len -= 1
if len > 0 then
local xy=g_cs[len]
camera(xy[1],xy[2])
else
camera()
end
end
function make_menu(
lbs, --menu lables
fnc, --chosen callback
x,y, --pos
omb, --omit backdrop
p, --player
cfnc --cancel callback
)
local m={
--lbs=lbs,
--f=fnc,
--fc=cfnc,
i=0, --item
s=g_tick,
e=5,
x=x or 64,
y=y or 80,
h=10*#lbs+4,
--omb=omb,
tw=0,--text width
p=p or -1,
draw=function(t)
local e=elapsed(t.s)
local w=t.tw*4+10
local x=min(1,e/t.e)*(w+9)/2
if not omb then
rectfill(-x,0,x,t.h,0)
rect(-x,0,x,t.h,1)
end
if e<t.e then
return
end
x=w/2+1
for i,l in pairs(lbs) do
if not t.off or i==t.i+1 then
local y=4+(i-1)*10
print(l,-x+9,y+1,0)
print(l,-x+9,y,7)
end
end
spr(0,-x,2+10*t.i)
end,
update=function(t,s)
if (t.off) return
if elapsed(t.s)<(t.e*2) then
return
end
if btnn(5,t.p) then
if fnc then
fnc(t,t.i,s)
--sfx(2)
end