forked from CelesteClassic/newleste.p8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.p8
1962 lines (1598 loc) · 75.7 KB
/
menu.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 27
__lua__
--TODO
--camera transition
--list credits
cheatmode=true
--globals
levels_unlocked = 1
uidata = {
border_1=5,
panel_pos=128,
hide_icons=true,
button_pos=8,
uistate='title',
flashtimer=0,
menux=0,
menubounce=0,
playx=0,
seltrail=1,
tickety=20,
tickethide=0
}
menuitems = {
menu={
items={'play', 'options', 'credits'},
sprites={0, 54, 55},
actions={
function() uidata.uistate='ticket' uianim = cocreate(playui_in) end,
function() uidata.uistate='options' uianim = cocreate(menuui_in) end,
function() transition_action=function() uidata.uistate='credits' end tstate=0 tcol=0 end
},
prev='title',
level=0
},
options={
items={'timer mode', 'screenshake', 'input display', 'delete save'},
data={
function() return timermodes[setting[1]+1] end,
function() return setting[2]>0 and 'off' or 'on' end,
function() return setting[3]>0 and 'on' or 'off' end,
function() return '' end
},
sprites={0, 0, 0, 0, 0},
actions={
function() setting[1]=(setting[1]+1)%4 poke(0x5e43, (peek(0x5e43)&0b1100)+setting[1]) end,
function() setting[2]=(setting[2]>0 and 0 or 1) poke(0x5e43, (peek(0x5e43)&0b1011)+(setting[2]<<2)) end,
function() setting[3]=(setting[3]>0 and 0 or 1) poke(0x5e43, (peek(0x5e43)&0b0111)+(setting[3]<<3)) end,
function() memset(0x5e00, 0, 0xff) sel_level=1 load_gamedata()end
},
prev='menu',
level=1
}
}
menu2={
items={'play', 'pico-8', 'options', 'credits'},
sprites={0, 53, 54, 55},
actions={
function() uidata.uistate='ticket' uianim = cocreate(playui_in) end,
function() transition_action=function() load('celeste') end tstate=0 tcol=0 end,
function() uidata.uistate='options' uianim = cocreate(menuui_in) end,
function() transition_action=function() uidata.uistate='credits' end tstate=0 tcol=0 end
},
prev='title',
level=0
}
menu1={
items={'play', 'options', 'credits'},
sprites={0, 54, 55},
actions={
function() uidata.uistate='ticket' uianim = cocreate(playui_in) end,
function() uidata.uistate='options' uianim = cocreate(menuui_in) end,
function() transition_action=function() uidata.uistate='credits' end tstate=0 tcol=0 end
},
prev='title',
level=0
}
timermodes={'chapter', 'file', 'room', 'frames'}
--uistates : title, menu, ticket, map, options
particles = {}
for i=0,12 do
add(particles,{
x=rnd(128),
y=rnd(128),
s=0+flr(rnd(5)/4),
spd=0.20+rnd(5),
off=rnd(1),
c=6+flr(0.5+rnd(1))
})
end
for i=0,12 do
add(particles2,{
x=rnd(128),
y=rnd(128),
s=0+flr(rnd(5)/4),
spd=0.20+rnd(5),
off=rnd(1),
c=6+flr(0.5+rnd(1))
})
end
function _init()
cartdata("collab_newleste_save")
load_gamedata()
sel_level = 1
sel_menu = 1
level_selected = false
idlecamtimer=0
cam_x = cam_positions[1][1][1]
cam_y = cam_positions[1][1][2]
cam_z = cam_positions[1][1][3]
cam_ax = cam_positions[1][1][4]
cam_ay = cam_positions[1][1][5]
cam_az = cam_positions[1][1][6]
init_3d()
mountain=load_object(read_vector_string(model_v), read_face_string(model_f),0,0,0,0,0,0,false,k_colorize_static,13)
prologue=load_object(read_vector_string(prologue_v), read_face_string(prologue_f),0,0,0,0,0,0,false,k_colorize_static,4)
city=load_object(read_vector_string(city_v), read_face_string(city_f),0,0,0,0,0,0,false,k_colorize_static,1)
castle=load_object(read_vector_string(castle_v), read_face_string(castle_f),0,0,0,0,0,0,false,k_colorize_static,5)
heart=load_object(read_vector_string(heart_v), read_face_string(heart_f),0,0,0,0,0,0,false,k_colorize_static,8)
waterfall=load_object(read_vector_string(waterfall_v), read_face_string(waterfall_f),0,0,0,0,0,0,false,k_colorize_static,12)
temple=load_object(read_vector_string(temple_v), read_face_string(temple_f),0,0,0,0,0,0,false,k_colorize_static,1)
lift=load_object(read_vector_string(lift_v), read_face_string(lift_f),0,0,0,0,0,0,false,k_colorize_static,13)
hotel=load_object(read_vector_string(hotel_v), read_face_string(hotel_f),0,0,0,0,0,0,false,k_colorize_static,14)
flag=load_object(read_vector_string(flag_v), read_face_string(flag_f),0,0,0,0,0,0,false,k_colorize_static,14)
end
function load_gamedata()
-- debug flags
if cheatmode then poke(0x5e03, 15) poke(0x5e47, 1) end
-- user progress
--debug force savedata
-- 0xffff.ffff = all bits to 1 (poke4 only; use -1 for normal poke)
-- 0x7fff.0000 = max int value
-- 0x7fff.ffff = max floating point value
--[[poke4(0x5e00,0xffff.ffff)
poke(0x5e03,15)
poke4(0x5e04,0xffff.ffff)
poke4(0x5e08,0xffff.ffff)
poke4(0x5e0c,0xffff.ffff)
poke4(0x5e10,0xffff.ffff)
poke4(0x5e14,0xffff.ffff)
poke4(0x5e18,0xffff.ffff)
poke4(0x5e1c,0xffff.ffff)
poke4(0x5e20,0xffff.ffff)
poke2(0x5e24,0xffff.ffff)
poke(0x5e26,-1)
--deaths
poke4(0x5e27,0x7fff.0000)
poke4(0x5e2b,0x7fff.0000)
poke4(0x5e2f,0x7fff.0000)
poke4(0x5e33,0x7fff.0000)
poke4(0x5e37,0x7fff.0000)
poke4(0x5e3b,0x7fff.0000)
poke4(0x5e3f,0x7fff.0000)
poke4(0x5e43,0x7fff.0000)--]]
-- savedata
hearts={}
for i=0,7 do
add(hearts,@0x5e00&(1<<i))
end
add(hearts,0)
goldens={}
for i=0,7 do
add(goldens,@0x5e01&(1<<i))
end
add(goldens,0)
summit_gems={}
for i=0,7 do
add(summit_gems,@0x5e02&(1<<i))
end
-- achievements:
-- 1up
-- classic clear
-- beat the game (any%) / reach the summit
-- clear all chapters
-- full clear all chapters
-- all red berries
-- all hearts
-- all golden berries
achievements={}
for i=0,7 do
add(achievements,@0x5e26&(1<<i))
end
-- chapters
-- keep track of progress for multi-cart chapters
completed_cp=@0x5e03&0b1111
levels_unlocked=completed_cp2menu()
-- berries
-- give every chapter 4 bytes, 32 possible berries
-- chapter 7 gets 6 bytes, 48 possible berries
berries={}
for chapter=1,8 do
local tab={}
for byo=0,chapter==7 and 5 or 3 do
for bit=0,7 do
add(tab,@(0x5e04+(chapter-1)*4+byo+(chapter>7 and 2 or 0))&(1<<bit))
end
end
add(berries,tab)
end
deaths={}
for i=0,7 do
add(deaths,$(0x5e27+i*4))
end
setting = {
@0x5e43&0b0011, -- timer mode (chapter, file, room, room (frames))
@0x5e43&0b0100, -- screenshake
@0x5e43&0b1000 -- input display
}
pico_unlocked=(@0x5e47>0)
if pico_unlocked then menuitems.menu = menu2 else menuitems.menu = menu1 end
-- variables
cartnames = {
"prologue",
"forsaken_city",
"old_site",
"celestial_resort",
"goden_ridge",
"mirror_temple",
"reflection",
"summit",
"epilogue",
"core"
}
end
function completed_cp2menu()
if completed_cp <= 5 then
return completed_cp+1
elseif completed_cp <= 6 then
return 6
elseif completed_cp <=8 then
return 7
elseif completed_cp <= 11 then
return 8
elseif completed_cp == 12 then
return 9
else
return 10
end
end
function selected2chap(selected)
if selected>1 and selected<9 then
return selected-1
elseif selected==10 then
return 8
else
return 9
end
end
function _update()
handle_ui()
upd_icons()
update_camera(sel_level)
update_3d()
end
function handle_ui()
uidata.flashtimer+=1
uidata.menubounce=0
if not freeze_input then
if uidata.uistate == 'title' then
if btnp(4) or btnp(5) then
transition_action = function() uidata.uistate = 'menu' end
tstate=0
tcol=1
end
elseif uidata.uistate == 'credits' then
if btnp(5) or btnp(4) then
transition_action=function() uidata.uistate='menu' end
tstate=0
tcol=0
end
elseif uidata.uistate == 'map' then
if level_selected then
if btnp(5) then
level_selected = false
uianim = cocreate(levelui_out)
elseif btnp(4) then
transition_action=function()
if selected2chap(sel_level) ~= 9 then
load(""..selected2chap(sel_level)..cartnames[sel_level])
else
load("0interludes")
end
end
tstate=0
tcol=0
end
else
if btnp(0) and sel_level > 1 then
sel_level-=1
end
if btnp(1) and sel_level < levels_unlocked then
sel_level+=1
end
if btnp(4) then
level_selected = true
uianim = cocreate(levelui_in)
elseif btnp(5) then
uidata.uistate='menu'
uidata.tickethide=0
idlecamtimer=atan2(cam_x, cam_z)
cam_ay=cam_ay-camround(cam_ay)
uianim = cocreate(menuui_out)
uidata.border_1 = 5
uidata.hide_icons = true
end
end
elseif uidata.uistate == 'ticket' then
if btnp(4) then
uidata.border_1 = 0
uidata.hide_icons = false
cam_ay=(((cam_ay+1)%2)-1)+camround(cam_positions[sel_level][1][5])
uianim = cocreate(hide_ticket)
elseif btnp(5) then
uianim = cocreate(menuui_out)
end
else
if btnp(3) and sel_menu < #menuitems[uidata.uistate].items then
sel_menu+=1
uidata.menubounce=1
end
if btnp(2) and sel_menu > 1 then
sel_menu-=1
uidata.menubounce=1
end
if btnp(4) then
menuitems[uidata.uistate].actions[sel_menu]()
uidata.menubounce=1
elseif btnp(5) then
if uidata.uistate == 'menu' then
transition_action = function() uidata.uistate = 'title' end
tstate=0
tcol=1
else
uianim = cocreate(menuui_out)
end
end
end
end
if uianim and costatus(uianim) ~= 'dead' then
coresume(uianim)
end
end
function levelui_in()
freeze_input=true
uidata.button_pos=8
for i=0,5 do
uidata.border_1 = i
yield()
end
yield()
local dist = leveldata[sel_level].width==0 and 64 or 80
for i=0,dist,16 do
uidata.panel_pos = 128-i
yield()
end
yield()
for i=8,0,-4 do
uidata.button_pos=i
yield()
end
freeze_input=false
end
function levelui_out()
freeze_input=true
local dist = leveldata[sel_level].width==0 and 64 or 80
for i=dist,0,-16 do
uidata.panel_pos = 128-i
yield()
end
yield()
for i=64,0,-16 do
uidata.border_1 = i
yield()
end
freeze_input=false
end
function menuui_in()
freeze_input=true
uidata.seltrail=sel_menu
for i=0,128,16 do
uidata.menux=i
if i == 32 then sel_menu=1 end
yield()
end
freeze_input=false
end
function playui_in()
freeze_input=true
uidata.seltrail=sel_menu
uidata.tickety=20
for i=0,64,16 do
uidata.menux=i
uidata.playx=i
if i == 32 then sel_menu=1 end
yield()
end
for i=64,-64,-16 do
uidata.playx=i
yield()
end
for i=0,7 do
if achievements[i+1]>0 then
for i=20,0,-5 do
uidata.tickety=i
yield()
end
freeze_input=false
return
end
end
freeze_input=false
end
function menuui_out()
freeze_input=true
uidata.playx=0
for i=128,0,-16 do
uidata.menux=i
if i == 32 then sel_menu=uidata.seltrail end
yield()
end
uidata.uistate='menu'
freeze_input=false
end
function hide_ticket()
freeze_input=true
for i=0,128,32 do
uidata.tickethide=i
yield()
end
uidata.uistate='map'
freeze_input=false
end
function _draw()
cls()
-- particles
foreach(particles2, function(p)
p.x += p.spd
p.y += sin(p.off)
p.off+= min(0.05,p.spd/32)
rectfill(p.x,p.y,p.x+p.s,p.y+p.s,p.c)
if p.x>128+4 then
p.x=-4
p.y=rnd(128)
end
end)
if uidata.uistate ~= 'title' then
fillp(0b1000000000100000)
rectfill(0, 0, 127, 32, 1)
fillp(0b0101000010100000)
rectfill(0, 32, 127, 64, 1)
fillp(0b1010010110100101)
rectfill(0, 64, 127, 96, 1)
fillp(0b0111111111011111)
rectfill(0, 97, 127, 127, 1)
fillp()
draw_3d()
end
if uidata.uistate == 'title' then
draw_title()
end
-- particles
foreach(particles, function(p)
p.x -= p.spd
p.y += sin(p.off)
p.off+= min(0.05,p.spd/32)
rectfill(p.x,p.y,p.x+p.s,p.y+p.s,p.c)
if p.x<-1 then
p.x=128+4
p.y=rnd(128)
end
end)
if uidata.uistate == 'menu' or uidata.uistate == 'ticket' or uidata.uistate == 'options' then
draw_menu()
end
if uidata.uistate == 'credits' then
draw_credits()
end
draw_mapui()
if uidata.uistate ~= 'title' then
print("select🅾️ back❎", 67, 120, 1)
end
draw_transition()
--[[print(stat(1), 120, 0, 8)
print(cam_x, 0, 0, 8)
print(cam_y, 0, 8, 8)
print(cam_z, 0, 16, 8)
print(cam_ax, 0, 34, 8)
print(cam_ay, 0, 42, 8)
print(cam_az, 0, 50, 8)--]]
end
function draw_transition()
if tstate>=0 then
freeze_input=true
local t20=tpos+20
if tstate==0 then
po1tri(tpos,0,t20,0,tpos,127)
if(tpos>0)rectfill(0,0,tpos,127,tcol)
if(tpos>148)tstate=1 tpos=-20 transition_action()
else
po1tri(t20,0,t20,127,tpos,127)
if(tpos<108)rectfill(t20,0,127,127,tcol)
if(tpos>148)tstate=-1tpos=-20 freeze_input=false
end
tpos+=14
end
end
function draw_title()
rectfill(0, 0, 128, 128, 0)
spr(71, 32, 22, 8, 8)
print("z+x",58,80,5)
--print("original by",43,88,5)
print("matt thorson",42,96,5)
print("noel berry",46,102,5)
--print('🅾️', 118, 120, 7)
end
function draw_credits()
rectfill(0, 0, 128, 128, 1)
print(':yadelie:',50, 60, 7)
end
function draw_menu()
for k,m in pairs(menuitems) do
if not(k=='options' and uidata.uistate~='options') then
for i=1,#m.items do
local seloff = i==sel_menu and 4 or 0
local selcol = i==sel_menu and (uidata.flashtimer%6<4 and 10 or 11) or 7
local mbounce = i==sel_menu and uidata.menubounce or 0
if m.items[i] == 'play' then
spr(80, 11-uidata.menux+uidata.playx, 12+i*10+mbounce, 2, 2)
print(m.items[i], 11-uidata.menux+uidata.playx, 30+i*10+mbounce, selcol)
else
spr(m.sprites[i], 9+seloff+128*m.level-uidata.menux-mbounce, 30+i*10+mbounce)
local text = m.items[i]
if m.data ~= null then
text = text..' '..m.data[i]()
end
print(text, 15+seloff+128*m.level-uidata.menux-mbounce, 30+i*10+mbounce, selcol)
end
end
end
end
if uidata.uistate == 'ticket' then
local tx = uidata.playx-uidata.menux+128-uidata.tickethide
rectfill(46+tx, 60-uidata.tickety, 82+tx, 82-uidata.tickety, 7)
rect(46+tx, 60-uidata.tickety, 82+tx, 82-uidata.tickety, 0)
for i=0,7 do
if achievements[i+1]>0 then
spr(56+i, 48+tx+((i%4)*8), 64+flr(i/4)*9-uidata.tickety)
end
end
rectfill(38+tx, 34, 90+tx, 62, 7)
rect(32+tx, 34, 96+tx, 62, 0)
palt(0, false)
palt(11, true)
spr(112, 22+tx, 34, 2, 4)
spr(112, 91+tx, 34, 2, 4, true)
spr(82, 20+tx, 32, 4, 4)
spr(50, 76+tx, 51)
local all_deaths = 0
for i=2,8 do
all_deaths += deaths[selected2chap(i)]
end
print(all_deaths, 86+tx, 53, 13)
palt()
for i=1,levels_unlocked do
pset(48+tx+i*5, 42, 13)
if hearts[selected2chap(i)]>0 then
spr(12, 46+tx+i*5, 41)
end
end
spr(49, 49+tx, 51)
local all_berries = 0
foreach(berries,function(m)
foreach(m,function(v)
if v>0 then
all_berries+=1
end
end)
end)
print(all_berries, 59+tx, 53, 13)
end
end
function draw_mapui()
if uidata.panel_pos ~= 128 then
--[[if uidata.border_1 ~=0 then
line(0, 64, 0, 64+uidata.border_1, 7)
line(0, 63, 0, 63-uidata.border_1, 7)
line(127, 64, 127, 64+uidata.border_1, 7)
line(127, 63, 127, 63-uidata.border_1, 7)
end
if uidata.border_2 ~=0 then
line(0, 0, 0+uidata.border_2, 0, 7)
line(127, 0, 127-uidata.border_2, 0, 7)
line(0, 127, 0+uidata.border_2, 127, 7)
line(127, 127, 127-uidata.border_2, 127, 7)
end--]]
local statoff = leveldata[sel_level].hasstats and 0 or 20
rectfill(uidata.panel_pos, 10, uidata.panel_pos+70+leveldata[sel_level].width, 60-statoff, 7)
rectfill(uidata.panel_pos, 51-statoff, uidata.panel_pos+70+leveldata[sel_level].width, 60-statoff, 6)
rect(uidata.panel_pos, 10, uidata.panel_pos+70+leveldata[sel_level].width, 60-statoff, 0)
--banner
rectfill(uidata.panel_pos, 15, uidata.panel_pos+80, 25, 0)
shade_trifill(uidata.panel_pos-5, 15, uidata.panel_pos, 15, uidata.panel_pos, 20, 0, 0)
shade_trifill(uidata.panel_pos, 20, uidata.panel_pos, 25, uidata.panel_pos-5, 25, 0, 0)
rectfill(uidata.panel_pos+1, 16, uidata.panel_pos+80, 24, leveldata[sel_level].color)
shade_trifill(uidata.panel_pos-3, 16, uidata.panel_pos+2, 16, uidata.panel_pos+2, 21, leveldata[sel_level].color, leveldata[sel_level].color)
shade_trifill(uidata.panel_pos+2, 19, uidata.panel_pos+2, 24, uidata.panel_pos-3, 24, leveldata[sel_level].color, leveldata[sel_level].color)
local offset = leveldata[sel_level].width==0 and 0 or 16
print(leveldata[sel_level].title, uidata.panel_pos+52+offset-(#leveldata[sel_level].title*4), 18, leveldata[sel_level].textcol)
--playbutton
rectfill(uidata.panel_pos+27+leveldata[sel_level].width, 58+uidata.button_pos-statoff, uidata.panel_pos+37+leveldata[sel_level].width, 68+uidata.button_pos-statoff, 0)
shade_trifill(uidata.panel_pos+27+leveldata[sel_level].width, 68+uidata.button_pos-statoff,
uidata.panel_pos+27+leveldata[sel_level].width, 73+uidata.button_pos-statoff,
uidata.panel_pos+32+leveldata[sel_level].width, 68+uidata.button_pos-statoff, 0, 0)
shade_trifill(uidata.panel_pos+32+leveldata[sel_level].width, 68+uidata.button_pos-statoff,
uidata.panel_pos+37+leveldata[sel_level].width, 73+uidata.button_pos-statoff,
uidata.panel_pos+37+leveldata[sel_level].width, 68+uidata.button_pos-statoff, 0, 0)
shade_trifill(uidata.panel_pos+27+leveldata[sel_level].width, 58+uidata.button_pos-statoff,
uidata.panel_pos+32+leveldata[sel_level].width, 53+uidata.button_pos-statoff,
uidata.panel_pos+37+leveldata[sel_level].width, 58+uidata.button_pos-statoff, 0, 0)
rectfill(uidata.panel_pos+28+leveldata[sel_level].width, 59+uidata.button_pos-statoff, uidata.panel_pos+36+leveldata[sel_level].width, 67+uidata.button_pos-statoff, 13)
shade_trifill(uidata.panel_pos+28+leveldata[sel_level].width, 68+uidata.button_pos-statoff,
uidata.panel_pos+28+leveldata[sel_level].width, 71+uidata.button_pos-statoff,
uidata.panel_pos+31+leveldata[sel_level].width, 68+uidata.button_pos-statoff, 13, 13)
shade_trifill(uidata.panel_pos+33+leveldata[sel_level].width, 68+uidata.button_pos-statoff,
uidata.panel_pos+36+leveldata[sel_level].width, 71+uidata.button_pos-statoff,
uidata.panel_pos+36+leveldata[sel_level].width, 68+uidata.button_pos-statoff, 13, 13)
shade_trifill(uidata.panel_pos+28+leveldata[sel_level].width, 58+uidata.button_pos-statoff,
uidata.panel_pos+32+leveldata[sel_level].width, 54+uidata.button_pos-statoff,
uidata.panel_pos+36+leveldata[sel_level].width, 58+uidata.button_pos-statoff, 13, 13)
spr(48, uidata.panel_pos+28+leveldata[sel_level].width, 58+uidata.button_pos-statoff)
--stats
if leveldata[sel_level].hasstats then
local berryc = 0
foreach(berries[selected2chap(sel_level)],function(v)
if v>0 then
berryc+=1
end
end)
if goldens[selected2chap(sel_level)]>0 then berryc+=1 end
print(berryc..'/'..leveldata[sel_level].max_berries, uidata.panel_pos+39+leveldata[sel_level].width, 30)
print(deaths[selected2chap(sel_level)], uidata.panel_pos+39+leveldata[sel_level].width, 41)
if goldens[selected2chap(sel_level)]>0 then
spr(63, uidata.panel_pos+30+leveldata[sel_level].width, 29)
else
spr(49, uidata.panel_pos+30+leveldata[sel_level].width, 29)
end
palt(0, false)
spr(50, uidata.panel_pos+30+leveldata[sel_level].width, 39)
palt(0, true)
if hearts[selected2chap(sel_level)]>0 then
spr(51, uidata.panel_pos+11+leveldata[sel_level].width, 30, 2, 2)
end
end
end
draw_icons()
end
iconpositions={
{x=64,y=-8},
{x=74,y=-8},
{x=84,y=-8},
{x=94,y=-8},
{x=104,y=-8},
{x=114,y=-8},
{x=124,y=-8},
{x=134,y=-8},
{x=144,y=-8},
{x=154,y=-8}
}
function upd_icons()
for i=1,levels_unlocked do
local selected = i==sel_level and 5 or 0
if level_selected or uidata.hide_icons then
if i==sel_level and not uidata.hide_icons then
iconpositions[i].x = lerp2(iconpositions[i].x, 118, 0.4)
iconpositions[i].y = movetow(iconpositions[i].y, 16, 1)
else
local moveoff = uidata.border_1*2 > i-1 and 1 or 0
iconpositions[i].y = movetow(iconpositions[i].y, -1*i-8, 2*moveoff)
end
else
if i==sel_level then
iconpositions[i].x = movetow(iconpositions[i].x, 60+10*i-10*sel_level, 8)
iconpositions[i].y = lerp2(iconpositions[i].y, 3+selected, 0.3)
else
iconpositions[i].x = movetow(iconpositions[i].x, 60+10*i-10*sel_level, 3)
iconpositions[i].y = movetow(iconpositions[i].y, 3+selected, 2)
end
end
end
end
function draw_icons()
local ref = sel_level==1 and 2 or 1
rectfill(59, -1, 68, iconpositions[ref].y*2+12, 12)
for i=1,levels_unlocked do
spr(i, iconpositions[i].x, iconpositions[i].y, 1, 1.3)
end
end
-->8
//3d library
-------------------------------------------------------------begin cut here-------------------------------------------------
------------------------------------------------------electric gryphon's 3d library-----------------------------------------
----------------------------------------------------------------------------------------------------------------------------
hex_string_data = "0123456789abcdef"
char_to_hex = {}
for i=1,#hex_string_data do
char_to_hex[sub(hex_string_data,i,i)]=i-1
end
function read_byte(string)
return char_to_hex[sub(string,1,1)]*16+char_to_hex[sub(string,2,2)]
end
function read_2byte_fixed(string)
local a=read_byte(sub(string,1,2))
local b=read_byte(sub(string,3,4))
local val =a*256+b
return val/256
end
cur_string=""
cur_string_index=1
function load_string(string)
cur_string=string
cur_string_index=1
end
function read_vector()
v={}
for i=1,3 do
text=sub(cur_string,cur_string_index,cur_string_index+4)
value=read_2byte_fixed(text)
v[i]=value
cur_string_index+=4
end
return v
end
function read_face()
f={}
for i=1,3 do
text=sub(cur_string,cur_string_index,cur_string_index+2)
value=read_byte(text)
f[i]=value
cur_string_index+=2
end
return f
end
function read_vector_string(string)
vector_list={}
load_string(string)
while(cur_string_index<#string)do
vector=read_vector()
add(vector_list,vector)
end
return vector_list
end
function read_face_string(string)
face_list={}
load_string(string)
while(cur_string_index<#string)do
face=read_face()
add(face_list,face)
end
return face_list
end
k_color1=4
k_color2=5
k_screen_scale=100
k_x_center=64
k_y_center=64
z_clip=-0.1
z_max=-50
k_min_x=0
k_max_x=128
k_min_y=0
k_max_y=128
--these are used for the 2 scanline color shading scheme
double_color_list= {{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,1,1,13,13,12,12},
{0,0,0,1,1,1,1,13,13,12},
{2,2,2,2,8,8,14,14,14,15},
{0,1,1,2,2,8,8,8,14,14},
{1,1,1,1,3,3,11,11,10,10},
{0,1,1,1,1,3,3,11,11,10},
{1,1,2,2,4,4,9,9,10,10},
{0,1,1,2,2,4,4,9,9,10},
{0,0,1,1,5,5,13,13,6,6},
{0,0,0,1,1,5,5,13,13,6},
{1,1,5,5,6,6,6,6,7,7},
{0,1,1,5,5,6,6,6,6,7},
{5,5,6,6,7,7,7,7,7,7},
{0,5,5,6,6,7,7,7,7,7},
{2,2,2,2,8,8,14,14,15,15},
{0,2,2,2,2,8,8,14,14,15},
{2,2,4,4,9,9,15,15,7,7},
{0,2,2,4,4,9,9,15,15,7},
{4,4,9,9,10,10,7,7,7,7},
{0,4,4,9,9,10,10,7,7,7},
{1,1,3,3,11,11,10,10,7,7},
{0,1,1,3,3,11,11,10,10,7},
{13,13,13,12,12,12,6,6,7,7},
{0,5,13,13,12,12,12,6,6,7},
{1,1,5,5,13,13,6,6,7,7},
{0,1,1,5,5,13,13,6,6,7},
{2,2,2,2,14,14,15,15,7,7},
{0,2,2,2,2,14,14,15,15,7},
{4,4,9,9,15,15,7,7,7,7},
{0,4,4,9,9,15,15,7,7,7}
}
k_ambient=.7
function color_faces(object,base)
--local p1x,p1y,p1z,p2x,p2y,p2z,p3x,p3y,p3z
for i=1,#object.faces do
local face=object.faces[i]
--for face in all(object.faces)do
local p1x=object.t_vertices[face[1]][1]
local p1y=object.t_vertices[face[1]][2]
local p1z=object.t_vertices[face[1]][3]
local p2x=object.t_vertices[face[2]][1]
local p2y=object.t_vertices[face[2]][2]
local p2z=object.t_vertices[face[2]][3]
local p3x=object.t_vertices[face[3]][1]
local p3y=object.t_vertices[face[3]][2]
local p3z=object.t_vertices[face[3]][3]
local nx,ny,nz = vector_cross_3d(p1x,p1y,p1z,
p2x,p2y,p2z,
p3x,p3y,p3z)
nx,ny,nz = normalize(nx,ny,nz)
local b = vector_dot_3d(nx,ny,nz,light1_x,light1_y,light1_z)
--see how closely the light vector and the face normal line up and shade appropriately
-- print(nx.." "..ny.." "..nz,10,i*8+8,8)
-- flip()
if object.color_mode==k_multi_color_dynamic then
face[4],face[5]=color_shade(object.base_faces[i][4], mid( b,0,1)*(1-k_ambient)+k_ambient )
else
face[4],face[5]=color_shade(base, mid( b,0,1)*(1-k_ambient)+k_ambient )
end
end
end
function color_shade(color,brightness)
--return double_color_list[ (color+1)*2-1 ][flr(brightness*10)] , double_color_list[ (color+1)*2 ][flr(brightness*10)]
local b= band(brightness*10,0xffff)
local c= (color+1)*2
return double_color_list[ c-1 ][b] , double_color_list[ c ][b]
end
light1_x=0
light1_y=1
light1_z=0
--t_light gets written to
t_light_x=0
t_light_y=0
t_light_z=0
function init_light()
light1_x,light1_y,light1_z=normalize(light1_x,light1_y,light1_z)
end
function update_light()
t_light_x,t_light_y,t_light_z = rotate_cam_point(light1_x,light1_y,light1_z)
end