-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbooty-demake.p8
More file actions
1484 lines (1429 loc) · 86 KB
/
booty-demake.p8
File metadata and controls
1484 lines (1429 loc) · 86 KB
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__
-- bootyful demake
-- jfc 1984 & nct 2017
-- rough code ahead - proceed at your own risk
function gamedraw()
cls()
map(levels[hero.lvl][6],levels[hero.lvl][7],0,0,16,13) -- draw map
if hero.lvl==1 and first==true then
color(11)
centre_print("press z if you get stuck",113)
color(7)
else
first=false
end
-- draw ladders if using fading platforms
if cheat[6]==1 then
-- add alt ladder number to levels
for ladnum = 1,levels[hero.lvl][13] do
-- loop through different ladders for level
ladx=altladders[hero.lvl][ladnum][1] -- x
lady=altladders[hero.lvl][ladnum][2] -- y
for ladraw = 0,2 do
mset(ladx,lady+ladraw,2)
-- draw ladder
end
end
end
objects()
-- player moving platform movement
if hero.ron==true then
hero.x=travs[hero.lvl][1][1]-hero.rx
-- player x = traveling platform x - riding x
end
if hero.death==false then
spr(hero.sp,hero.x,hero.y,hero.w/8,hero.h/8,hero.dr) -- draw hero
else fall()
end
if cheat[2]==0 then
-- draw pirates if present
if not (levels[hero.lvl][5]==0) then
for enemies = 1,levels[hero.lvl][5] do -- draw pirates
spr(pirate.sp,pilocate[hero.lvl][enemies][1],pilocate[hero.lvl][enemies][2],pirate.w,pirate.h,pilocate[hero.lvl][enemies][3])
end
end
end
-- draw travelators if present - defunct
if not cheat[6]==1 then
if not (levels[hero.lvl][8]==0) then
for travloops = 1,levels[hero.lvl][8] do
spr(45,travs[hero.lvl][travloops][1],travs[hero.lvl][travloops][2],1,1)
-- spr,x,y - size1,1 - fixme - account for width
end
end
end
-- draw lifts if present - defunct
if not cheat[6]==1 then
if not (levels[hero.lvl][9]==0) then
for liftloops = 1,levels[hero.lvl][9] do
spr(46,lifts[hero.lvl][liftloops][1],lifts[hero.lvl][liftloops][2],1,1)
-- spr,x,y - size1,1 - fixme - account for width
end
end
end
-- draw fading platforms if present
-- check if flash on - in draw section
if (tempon==true) then
for fadeloop = 1, levels[hero.lvl][10] do
if templatforms[hero.lvl][fadeloop][4]==1 or cheat[6]==1 then
platstart = templatforms[hero.lvl][fadeloop][1]
platend = platstart + (templatforms[hero.lvl][fadeloop][3]*8)
for platpart = platstart, platend, 8 do
if not (templatforms[hero.lvl][fadeloop][4]==2) then
-- templatforms is also used to mark no go gaps
spr(1,platpart,templatforms[hero.lvl][fadeloop][2]) -- x,y
fset(1,1,true)
end
end
end
end
end
stats()
debug()
collision() -- collision tests
end -- gamedraw end
function stats()
-- stats
color(10)
print("l",0,106)
color(7)
print(hero.lvl,4,106)
for life = 0,hero.lives-1 do -- show lives
spr(18,14+life*8,104)
end
spr(19,5*8,13*8) -- key
print(hero.keyheld,55,106)
spr(30,8*8,13*8) -- booty
print(hero.treas,78,106)
spr(14,11*8,13*8) -- treasure
print(125-hero.treas,102,106)
spr(31,15*8,13*8) -- exit
total=0
for taken = 1,levels[hero.lvl][2] do
total += booty[hero.lvl][taken][3]
end
if total == 0 then
centre_print("level complete",113)
first=false
end
if (behind==192) then
-- is there an exit and which one is it?
for exitloop = 1,levels[hero.lvl][4] do
if exits[hero.lvl][exitloop][2]==flr(hero.y)
and (exits[hero.lvl][exitloop][1]>=flr(hero.x)-7
and exits[hero.lvl][exitloop][1]<=flr(hero.x)+7) then
-- is player in front of the exit?
levl=exits[hero.lvl][exitloop][3]
-- set destination
if (levl >= 10 and levl <= 99) then
print(levl,120,106)
else print (levl,122,106)
end
if (btnp(5)) then
-- is the playter pressing x on the exit?
-- hero.keyheld=0 -- made some levels impossible!
hero.lvl=levl
break
-- change level to where exit leads
end
end
end
end
--end
color(8)
centre_print("bootyful demake",120)
end
-- doesn't work - needs to be rewritten
function fall()
if hero.death==true then
sfx(10)
-- for y=hero.y,hero.y+32 do
-- slow down?
-- timer(0.25)
-- spr(76,hero.x,y,hero.w/8,hero.h/8)
-- spr(74,hero.x,y,hero.w/8,hero.h/8)
-- maybe change to fall upside down
-- end
wait(1)
hero.lives-=1
hero.x=levels[hero.lvl][11]
hero.x=levels[hero.lvl][12]
hero.death=false
end
end
function debug() -- fixme - remove at end
-- print ("hx "..flr(hero.x),0,113)
-- print ("hy "..flr(hero.y),25,113)
-- print ("tx "..flr(hero.x/8),50,113)
-- print ("ty "..flr(hero.y/8),75,113)
-- print ("bh "..behind,50,113)
-- print ("bn "..beneath,75,113)
-- print ("fb "..floor_below,110,113)
end
function move(sprite)
hero.mov = true
hero.sp += 1
if hero.sp > sprite+hero.ani then
hero.sp = sprite
end
end
function gameupdate() -- swapped with update
hero.mov = false
if(btn(0) and platform) then
climb=false
if hero.ron == true then
-- riding platform
hero.rx+=1 --maybe hero.rx+=hero.spd
else hero.x-=hero.spd -- left
end
hero.dr = true
if hero.x < 1 then
hero.x = 1
end
move(hero.ini)
end
if(btn(1) and platform) then
climb=false
if hero.ron == true then
hero.rx-=1
else hero.x+=hero.spd -- right
end
hero.dr = false
if hero.x > world.w-hero.w then
hero.x = world.w-hero.w-1
end
move(hero.ini)
end
if (btn(3) and ladder_d) then -- down
climb=true
hero.y+=1
move(hero.clisp)
end
if (btn(2) and ladder_u) then -- up
climb=true
hero.y-=1
move(hero.clisp)
end
if (btnp(4)) then
if cheat[5]==1 and hero.lvl<20 then
-- if cheat is on can skip levels
hero.lvl+=1
hero.x=levels[hero.lvl][11]
hero.y=levels[hero.lvl][12]
else -- if cheat isn't on restart level position
hero.x=levels[hero.lvl][11]
hero.y=levels[hero.lvl][12]
-- was hero.sx=hero.x & hero.sy=hero.y
end
end
if not hero.mov then -- animation
if climb==false then
hero.sp = hero.ini
else hero.sp = hero.cli
end
end
if cheat[2]==0 then
enemy_update()
end
travel_update()
-- find fading platform wait time
maxwidth = 3
for widthloop = 1,levels[hero.lvl][10] do
width = templatforms[hero.lvl][widthloop][3]
if width > maxwidth then
maxwidth = width
-- find longest fading platform for level
end
end
fadewait = 2+(maxwidth-3)
-- add platform specific timing later?
printh(fadewait)
if (time() % fadewait)==0 then -- was % 3
tempon=true
end
fademax = fadewait*2
if (time() % (fadewait*2))==0 then -- was % 6
tempon=false
end
if hero.lives==0 then
mode = 9 -- death screen
end
if hero.treas==125 then
mode =6
end
-- print("you are dead")
-- wait(30)
-- end
end -- gameupdate / movement end
function deldoor()
sfx(13)
fset(dsprite,0) -- remove flag
doors[hero.lvl][dnum][3]=0 -- change array
mset(doors[hero.lvl][dnum][1],doors[hero.lvl][dnum][2],1)
mset(doors[hero.lvl][dnum][1],doors[hero.lvl][dnum][2]+1,0)
mset(doors[hero.lvl][dnum][1],(doors[hero.lvl][dnum][2])+2,0)
hero.keyheld=0
end
function enemy_move(pisprite)
pirate.mov = true
pirate.sp += 1
if pirate.sp > pisprite+pirate.ani then
pirate.sp = pisprite
end
end
function enemy_update()
-- if (time() % 0.25)==0 then -- too slow
if slow(5) then
for enemies = 1,levels[hero.lvl][5] do -- add y
pirate.mov = false
if pilocate[hero.lvl][enemies][3]==false then -- facing & moving right
pilocate[hero.lvl][enemies][1]-=pirate.spd
enemy_move(pirate.ini)
end
if pilocate[hero.lvl][enemies][3]==true then -- facing & moving left
pilocate[hero.lvl][enemies][1]+=pirate.spd
enemy_move(pirate.ini)
end
piy = pilocate[hero.lvl][enemies][2]
pix = pilocate[hero.lvl][enemies][1]
for platloop = 1, levels[hero.lvl][10] do
-- go through templatforms
gapy = templatforms[hero.lvl][platloop][2]
-- account for level +y?
gapleft = templatforms[hero.lvl][platloop][1] - 4
-- account for level +x?
gaplen = templatforms[hero.lvl][platloop][3] * 8
gapright = gapleft + gaplen
-- account for level +x?
if gapy==piy + pirate.h*8 then
-- if gap on platform pirate walks on
if pix == gapright then
pilocate[hero.lvl][enemies][3]=true
end
if pix == gapleft then
pilocate[hero.lvl][enemies][3]=false
end
end
end
-- if at top right ... turn around -- was 4+levels[hero.lvl][6]*8
if tile_at(pilocate[hero.lvl][enemies][1]+4+levels[hero.lvl][6]*8,
pilocate[hero.lvl][enemies][2]-8 + levels[hero.lvl][7]*8)>=60 and
tile_at(pilocate[hero.lvl][enemies][1]+4+levels[hero.lvl][6]*8,
pilocate[hero.lvl][enemies][2]-8 + levels[hero.lvl][7]*8)<=68 then
pilocate[hero.lvl][enemies][3]=false
test=true
end -- should have used same function for player & pirate!
-- if at top left ... turn around
if tile_at(pilocate[hero.lvl][enemies][1]-1+levels[hero.lvl][6]*8,
pilocate[hero.lvl][enemies][2]-1 + levels[hero.lvl][7]*8)>=60 and
tile_at(pilocate[hero.lvl][enemies][1]-1+levels[hero.lvl][6]*8,
pilocate[hero.lvl][enemies][2]-1 + levels[hero.lvl][7]*8)<=68 then
pilocate[hero.lvl][enemies][3]=true
end
if pilocate[hero.lvl][enemies][1] <= 1 then
pilocate[hero.lvl][enemies][1] = 1
pilocate[hero.lvl][enemies][3]=true
end
if pilocate[hero.lvl][enemies][1] >= 120 then
pilocate[hero.lvl][enemies][1] = 120-pirate.w -- *8
pilocate[hero.lvl][enemies][3]=false
end
if not pirate.mov then
pirate.sp = pirate.ini
end
end
end
end
function travel_update()
-- moving platforms - defunct
if not cheat[6]==1 then
for rideloop = 1,levels[hero.lvl][8] do
if hero.y+hero.h==travs[hero.lvl][rideloop][2] then
-- if player on same level (y) as platform
if hero.ron==true then -- test if move off platform
if travs[hero.lvl][rideloop][6]==1 then
-- if platform width is 1
if hero.rx >= 5 or hero.rx <= -5 then
-- test where player is on platform
-- 5 assumes 8 width/2+1 - only made for single width
hero.ron=false
end
end
if travs[hero.lvl][rideloop][6]==2 then -- fixme - add into or or else?
-- if platform width is 2
if hero.rx >= 5 or hero.rx <= -15 then
hero.ron=false
end
end
end -- end of move off platform check
-- player getting on to traveling platform (still part of if above)
if hero.ron==false then -- fixme - also need to account for moving between moving platforms?
-- only works for heading right so far
if hero.x <= travs[hero.lvl][rideloop][3] then
-- check if left of traveling platform
if hero.x == travs[hero.lvl][rideloop][1]-4 then
-- if player x >= traveling x - player width
hero.ron=true
hero.rx=travs[hero.lvl][rideloop][1]-hero.x
-- riding x = travel platform x - player x
end
end
end -- end of left to right check
if hero.x >= travs[hero.lvl][rideloop][4] then -- (still part of if above)
-- check if right of traveling platform
if travs[hero.lvl][rideloop][6]==1 then
if hero.x == travs[hero.lvl][rideloop][1]+4 then -- right to left
hero.ron=true
hero.rx=travs[hero.lvl][rideloop][1]-hero.x
-- riding x = travel platform x - player x
end
end
if travs[hero.lvl][rideloop][6]==2 then
if hero.x-8 == travs[hero.lvl][rideloop][1]+4 then -- right to left
hero.ron=true
hero.rx=travs[hero.lvl][rideloop][1]-hero.x
-- riding x = travel platform x - player x
end
end
end -- end of right to left check
end -- end of level check
end -- end of travelator loop
end
-- fixme - remove when replaced
if not cheat[6]==1 then
for liftloop = 1,levels[hero.lvl][9] do
-- if hero.x==lifts[hero.lvl][liftloop][1] then
-- if at x co-ord - fixme needs larger range
if hero.x == lifts[hero.lvl][liftloop][1]-4 then
-- if to left moving right and stepping over edge
if hero.y+hero.h==lifts[hero.lvl][liftloop][2] then
-- if at y co-ord - fixme needs a little finese
lifttravel=true
end
if lifttravel==true then
hero.y = lifts[hero.lvl][liftloop][2]-hero.h
-- seems simplest way - fixme - add to draw?
end
end
end
end -- end of travel_update function
end
function tile_at(x,y)
return fget(mget(flr(x/8),flr(y/8)))
end
function collision()
-- beneath=fget(mget(hero.x+levels[hero.lvl][6]*8,hero.y+hero.h)) - bottom half of hero / test x+1
topleft=tile_at(hero.x+levels[hero.lvl][6]*8,hero.y-1+levels[hero.lvl][7]*8) -- door left - was x-1
-- was topleft=tile_at(hero.x-1,hero.y-1) -- door left - was -8
topright=tile_at(hero.x+hero.w/2+levels[hero.lvl][6]*8,hero.y-8+levels[hero.lvl][7]*8) -- door right
-- was topright=tile_at(hero.x+8,hero.y-8)
floor_below = tile_at( hero.x, hero.y+hero.h )
floor_tile_below = tile_at(hero.x+levels[hero.lvl][6]*8, hero.y+hero.h+levels[hero.lvl][7]*8 )
platform = hero.y==8 or hero.y==32 or hero.y==56 or hero.y==80
or hero.y==136 or hero.y==160 or hero.y==184 or hero.y==208
or hero.y==264 or hero.y==288 or hero.y==312 or hero.y==336
-- dumb way fixme - but it worked - fix later?
-- fixed getting stuck on ladder - finally!
ladder_d = tile_at (hero.x+hero.w/2+levels[hero.lvl][6]*8, hero.y+hero.h+levels[hero.lvl][7]*8)==2
ladder_u = tile_at (hero.x+hero.w/2+levels[hero.lvl][6]*8, hero.y+hero.h-1+levels[hero.lvl][7]*8)==2
behind = tile_at(hero.x+levels[hero.lvl][6]*8, hero.y+levels[hero.lvl][7]*8)
-- for treasure & keys & exits?
if cheat[2]==0 then
for enemies = 1,levels[hero.lvl][5] do
-- if pirate hits into you die
if pilocate[hero.lvl][enemies][1]==hero.x and pilocate[hero.lvl][enemies][2]==hero.y then
hero.lives-=1
sfx(10)
wait(1)
hero.x=levels[hero.lvl][11]
hero.y=levels[hero.lvl][12]
end
end
end
if not (topleft==0) and (topleft>=60 and topleft<=69) then
-- if door to left
dnum=(topleft-59)
dsprite=(topleft-55)
if hero.keyheld==topleft-59 then
keydb[hero.lvl][hero.keyheld][3]=2
deldoor()
else hero.x+=1
end
end
if not (topright==0) and (topright>=60 and topright<=69) then
-- if door to right
dnum=(topright-59)
dsprite=(topright-55)
if hero.keyheld==topright-59 then
keydb[hero.lvl][hero.keyheld][3]=2
deldoor()
else hero.x-=1
end
end
if not (behind==0) then
-- pick up object
if (behind>=34) and (behind<=44) then -- if treasure flag
onum=(behind-33)
booty[hero.lvl][onum][3]=0
fset(behind,0)
mset(booty[hero.lvl][onum][1],booty[hero.lvl][onum][2],0) -- added 16
mset(booty[hero.lvl][onum][1],booty[hero.lvl][onum][2]+1,0)
hero.treas+=1
-- was it a trap?
if trap==onum then -- if object is bomb
bomb(trap)
end
end
if (behind>=21) and (behind<=29) then
-- if it's a key
knum=(behind-20) -- which key is it? 1-8
if not (hero.keyheld==0 or keydb[hero.lvl][hero.keyheld][3]==2) then
-- if holding any key, or key used
keydb[hero.lvl][hero.keyheld][3]=1 -- set that key back to unheld
end
keydb[hero.lvl][knum][3]=0 -- make unavailable
fset(behind,0)
mset(keydb[hero.lvl][knum][1],keydb[hero.lvl][knum][2],0)
mset(keydb[hero.lvl][knum][1],keydb[hero.lvl][knum][2]+1,0)
hero.keyheld=knum
end
end
if floor_tile_below==0 and tempon==false and climb==false then
-- add if not riding platform
if hero.death==false then
hero.death=true
-- fall()
end
end
end -- collision end
function objects()
if cheat[3]==0 then
-- place keys
for keys = 1,levels[hero.lvl][3] do
if not (keydb[hero.lvl][keys][3]==0 or keydb[hero.lvl][keys][3]==2) then -- only if keys there
fset(20+keys,20+keys)
mset(keydb[hero.lvl][keys][1],keydb[hero.lvl][keys][2],20+keys)
mset(keydb[hero.lvl][keys][1],(keydb[hero.lvl][keys][2]+1),20)
end
end
-- place doors
for doornum = 1,levels[hero.lvl][3] do
if not (doors[hero.lvl][doornum][3]==0) then -- only if doors closed
fset(4+doornum,59+doornum) -- door sprites from 5, flags from 60
mset(doors[hero.lvl][doornum][1],doors[hero.lvl][doornum][2],4+doornum)
mset(doors[hero.lvl][doornum][1],doors[hero.lvl][doornum][2]+1,4)
mset(doors[hero.lvl][doornum][1],(doors[hero.lvl][doornum][2])+2,3)
end
end
end
-- place treasures
for items = 1,levels[hero.lvl][2] do
if not (booty[hero.lvl][items][3]==0) then
fset(33+btype[hero.lvl][items],33+items)
mset(booty[hero.lvl][items][1],booty[hero.lvl][items][2],btype[hero.lvl][items]+33)
-- fset(49+booty[hero.lvl][items][3],49+items) -- don't need?
mset(booty[hero.lvl][items][1],booty[hero.lvl][items][2]+1,btype[hero.lvl][items]+49)
end
-- set random object to be trap
trap=rnd(levels[hero.lvl][2])
if hero.lvl==21 then trap=3 end -- test
end
-- move travelators - defunct
if not cheat[6]==1 then
for travloop = 1,levels[hero.lvl][8] do
-- if traveling forward (dir=0)
if travs[hero.lvl][travloop][5]==0 then
travs[hero.lvl][travloop][1]+=1 -- increase platform x
end
-- if reach end of path start back the other way (dir=1)
if travs[hero.lvl][travloop][1]==travs[hero.lvl][travloop][4] then
travs[hero.lvl][travloop][5]=1
end
-- if traveling back (dir=1)
if travs[hero.lvl][travloop][5]==1 then
travs[hero.lvl][travloop][1]-=1 -- decrease platform x
end
-- if back at the start go forward again
if travs[hero.lvl][travloop][1]==travs[hero.lvl][travloop][3] then
travs[hero.lvl][travloop][5]=0
end
end
-- move lifts - defunct
for liftloop = 1, levels[hero.lvl][9] do
-- if traveling downward (dir=0)
if lifts[hero.lvl][liftloop][5]==0 then
lifts[hero.lvl][liftloop][2]+=1 -- increase platform y
end
-- if reach end of path start back the other way (dir=1)
if lifts[hero.lvl][liftloop][2]==lifts[hero.lvl][liftloop][4] then
lifts[hero.lvl][liftloop][5]=1
end
-- if traveling back (dir=1)
if lifts[hero.lvl][liftloop][5]==1 then
lifts[hero.lvl][liftloop][2]-=1 -- decrease platform y
end
-- if back at the start go forward again
if lifts[hero.lvl][liftloop][2]==lifts[hero.lvl][liftloop][3] then
lifts[hero.lvl][liftloop][5]=0
end
end
end -- objects end
end
function shuffle(items,num)
for l = 1, num+1 do
local rand1 = flr(rnd(num)+1)
local rand2 = flr(rnd(num)+1)
items[rand1], items[rand2] = items[rand2], items[rand1]
end
return(items)
end
-- unused booty tap code
function bomb(trap)
-- place bomb where object was -
cycle=time()
trapx = booty[hero.lvl][trap][1]+16
trapy = booty[hero.lvl][trap][2]+24
spr(96,trapx,trapy)
-- initial warning sound - 18
sfx(18)
-- wait(45)
if cycle==time()-3 then
-- explosion animation and sound
for l =1,3 do
-- zspr(96,1,1,96-8*l,72-8*l,l)
sfx(16)
zspr(96,1,1,trapx-8*1,trapy-8*1,l)
end
end
-- check for death - player hero.x / hero.y
-- maybe call death as function
end
function zspr(n,w,h,dx,dy,dz)
-- from http://www.lexaloffle.com/bbs/?tid=2429
sx = 8 * (n % 16)
sy = 8 * flr(n / 16)
sw = 8 * w
sh = 8 * h
dw = sw * dz
dh = sh * dz
sspr(sx,sy,sw,sh, dx,dy,dw,dh)
end
function titleinit() -- menu
-- opening menu with thanks to http://pico-8.wikia.com/wiki/multiple_states_system
mode = 0
music(0)
text = "bootyful demake"
speed = 25
height = 10
tim = 0
end
function _draw() -- menu
if (mode == 0) then --title screen mode
titledraw()
elseif (mode == 9) then
deathdraw()
elseif (mode == 6) then
windraw()
elseif (mode == 3) then
helpdraw()
else
gamedraw()
end
end
function titledraw() -- menu
cls()
sspr(56,32,8,8,0,0,128,94) -- sky
circfill (110,48,8,10)-- sun
-- wavy text - thanks to http://www.lexaloffle.com/bbs/?tid=28262
tim += 1
for i=0,#text,1 do -- moving title text
print(sub(text,i,i),
32+(i*4),
16+sin((tim+i)/speed)*height,7)
end
sspr(57,45,22,24,32,40,66,72) -- ship
sspr(64,32,8,8,0,94,128,24) -- water
centre_print("press x to start",100)
if (btn(5)) then
gameinit()
end
color(10)
centre_print("press z for help",108)
color(7)
if (btn(4)) then
mode = 3
helpdraw()
end
centre_print("nct 2017 / jfc 1984",120)
end -- title end
function windraw() -- menu
cls()
text = "congratulations"
sspr(64,32,8,8,0,0,128,94) -- dark sky
circfill (110,48,8,6)-- moon
tim += 1
for i=0,#text,1 do -- moving title text
print(sub(text,i,i),
32+(i*4),
16+sin((tim+i)/speed)*height,7)
end
sspr(57,45,22,14,32,48,66,48) -- sunk ship
sspr(72,32,8,8,0,94,128,24) -- black water
color(10)
centre_print("you have won!",104)
color(7)
end -- title end
function _update() -- menu
if (mode == 0) then --title screen mode
titleupdate()
elseif (mode == 9) then
deathupdate()
elseif (mode == 6) then
winupdate()
elseif (mode == 3) then
helpupdate()
else
gameupdate()
end
end
function deathdraw()
cls()
centre_print("you have died!",16)
zspr(101,2,2,32,32,4)
centre_print("press x to restart",110)
wait(1)
if (btn(5)) then
wait(1)
titleinit()
end
end
-- remind me what these were for again?
function titleupdate() -- menu
end
function deathupdate()
end
function helpupdate()
end
function winupdate()
end
function helpdraw()
cls()
centre_print("collect booty to win the game",8)
for bl=1,10 do
spr(bl+33,16+bl*8,12,1,2) -- 34-44
end
centre_print("use keys to open doors",32)
spr(21,8,28)
spr(20,8,36)
spr(5,112,28)
spr(4,112,36)
centre_print("climb ladders",48)
spr(2,24,40)
spr(2,24,48)
centre_print("press x on exits",64)
spr(61,100,48,2,1)
spr(32,100,56,2,1)
spr(48,100,64,2,1)
centre_print("avoid pirates",80)
spr(109,24,72,1,2,1)
centre_print("cross disappearing platforms",96)
-- stats()
color(10)
centre_print("press x to start",112)
color(7)
wait(1)
if (btnp(5)) then
wait(1)
gameinit()
end
end
function centre_print(strtxt,py) print(strtxt,64-(#strtxt*2),py) end
function _init() -- move to gameinit?
titleinit() -- menu
end -- init end
function gameinit() -- menu
mode = 1
music(-1)
world={mx=0,my=0,w=128,h=128} -- world mx changes according to level
hero={x=70,y=8,w=8,h=16,sx=70,sy=8,ini=77,sp=77,cli=74,clisp=74,ani=2,spd=1,dr=true,
keyheld=0,treas=0,lives=3,lvl=1,rx=0,ron=false,death=false}
climb=false -- state={wlk,clm}
tempon=true
destex=0
levl=99
first=true
levels={{1,6,8,3,2,0,0,0,0,0,70,8,0},
{2,9,7,3,2,16,0,0,0,0,104,8,0},
{3,7,0,3,1,32,0,3,0,3,16,8,0},
{4,2,0,3,2,48,0,0,0,2,48,8,0},
{5,6,6,3,1,64,0,0,0,2,80,80,0},
{6,6,6,3,0,80,0,0,2,2,48,32,3},
{7,10,6,3,0,96,0,0,0,0,24,8,0},
{8,5,3,3,1,112,0,0,0,0,80,56,0},
{9,10,6,3,0,0,16,0,2,8,64,8,3},
{10,7,7,3,0,16,16,0,0,4,80,32,3},
{11,7,5,3,1,32,16,0,0,4,64,8,3},
{12,6,6,3,0,48,16,0,0,5,64,80,3},
{13,7,6,3,1,64,16,0,0,0,48,8,0},
{14,6,5,3,0,80,16,0,0,7,0,8,3},
{15,4,3,3,2,96,16,0,0,3,48,8,2},
{16,8,6,3,0,112,16,0,0,0,32,56,0},
{17,4,5,3,1,0,32,0,0,10,16,32,3},
{18,3,9,3,1,16,32,0,0,4,40,8,3},
{19,7,7,3,1,32,32,0,0,0,48,8,0},
{20,7,6,3,0,48,32,0,0,1,80,8,0},
{21,4,2,2,2,64,32,0,0,4,18,80,0} -- issue with keys/doors & pirates
}
-- ref,booty,keys/doors, exits,pirates,initx, inity,travs,lifts
-- + templatforms & inipx,inipy, alt ladders
keydb={{{12,7,1},{9,10,1},{0,7,1},{6,1,1},{0,10,1},{5,7,1},{6,4,1},{2,1,1},{7,1,1}}, -- 1
{{16,10,1},{31,1,1},{29,10,1},{21,1,1},{31,4,1},{20,1,1},{20,10,1}}, -- 2
{{0,0,0}},{{0,0,0}}, -- 3-4
{{79,4,1},{70,1,1},{68,10,1},{64,10,1},{70,4,1},{68,4,1}}, -- 5
{{86,7,1},{95,4,1},{81,10,1},{85,10,1},{81,1,1},{85,1,1}}, -- 6
{{96,7,1},{109,4,1},{96,10,1},{103,1,1},{111,7,1},{111,1,1}}, -- 7
{{123,4,1},{127,10,1},{121,7,1}}, -- 8
{{15,17,1},{0,23,1},{15,20,1},{0,17,1},{15,26,1},{9,23,1}}, -- 9
{{16,26,1},{27,26,1},{17,17,1},{31,17,1},{16,17,1},{25,17,1},{26,23,1}}, -- 10
{{32,23,1},{47,26,1},{38,20,1},{32,17,1},{40,23,1}}, -- 11
{{63,17,1},{48,23,1},{50,20,1},{48,26,1},{62,20,1},{48,17,1}}, -- 12
{{64,20,1},{79,26,1},{67,17,1},{75,26,1},{71,23,1},{79,23,1}}, -- 13
{{90,23,1},{93,17,1},{95,23,1},{80,23,1},{90,26,1}}, -- 14
{{98,23,1},{111,20,1},{98,20,1}}, -- 15
{{119,17,1},{117,17,1},{126,17,1},{125,26,1},{121,23,1},{118,23,1}}, -- 16
{{13,42,1},{13,39,1},{00,39,1},{15,33,1},{00,33,1}}, -- 17
{{21,39,1},{16,42,1},{19,42,1},{18,39,1},{20,36,1},{31,39,1},{18,33,1},{31,36,1},{31,33,1}}, -- 18
{{32,42,1},{45,39,1},{42,33,1},{47,33,1},{32,33,1},{46,36,1},{34,36,1}}, -- 19
{{54,36,1},{62,39,1},{49,42,1},{48,33,1},{63,36,1},{63,33,1}}, -- 20
{{77,42,1},{73,33,1}} -- 21
} -- key placement - x,y,present
doors={{{5,0,1},{10,0,1},{5,3,1},{10,3,1},{4,6,1},{10,6,1},{5,9,1},{10,9,1}}, -- 1
{{18,0,1},{27,0,1},{19,3,1},{24,3,1},{23,6,1},{19,9,1},{27,9,1}}, -- 2
{{0,0,0}},{{0,0,0}}, -- 3-4
{{69,0,1},{75,0,1},{69,3,1},{73,3,1},{67,9,1},{71,9,1}}, -- 5
{{83,0,1},{88,0,1},{83,6,1},{87,6,1},{84,9,1},{88,9,1}}, -- 6
{{102,0,1},{106,0,1},{107,3,1},{101,6,1},{101,9,1},{109,9,1}}, -- 7
{{123,0,1},{124,6,1},{124,9,1}}, -- 8
{{2,16,1},{12,16,1},{2,19,1},{13,19,1},{2,22,1},{12,25,1}}, -- 9
{{24,16,1},{27,16,1},{29,16,1},{25,22,1},{27,22,1},{26,25,1},{29,25,1}}, -- 10
{{39,19,1},{44,19,1},{33,22,1},{39,22,1},{42,25,1}}, -- 11
{{51,16,1},{61,16,1},{61,19,1},{61,22,1},{50,25,1},{61,25,1}}, -- 12
{{66,16,1},{66,19,1},{76,19,1},{72,22,1},{72,25,1},{76,25,1}}, -- 13
{{90,19,1},{92,19,1},{94,19,1},{89,22,1},{92,22,1}}, -- 14
{{109,16,1},{102,19,1},{100,25,1}}, -- 15
{{118,16,1},{123,16,1},{118,19,1},{119,22,1},{123,22,1},{123,25,1}}, -- 16
{{9,32,1},{11,32,1},{13,32,1},{9,41,1},{11,41,1}}, -- 17
{{30,32,1},{19,35,1},{21,35,1},{30,35,1},{20,38,1},{22,38,1},{30,38,1},{18,41,1},{21,41,1}}, -- 18
{{35,32,1},{43,32,1},{35,35,1},{44,35,1},{39,38,1},{36,41,1},{40,41,1}}, -- 19
{{52,32,1},{61,32,1},{50,35,1},{53,35,1},{59,38,1},{59,41,1}}, -- 20
{{69,32,1},{69,41,1}}
} -- doors x,y,closed/open
exits={{{104,8,2,1},{8,56,13,3},{112,80,5,3}}, -- x,y,lev,door
{{104,8,1,1},{96,32,3,2},{72,80,10,2}}, -- 2
{{72,32,4,3},{96,32,2,2},{16,80,9,3}}, -- 3
{{8,8,10,1},{112,8,11,1},{72,32,3,1}}, -- 4
{{64,8,20,1},{24,32,6,2},{104,80,1,3}}, -- 5
{{8,32,5,2},{104,32,7,2},{72,80,8,3}}, -- 6
{{72,32,8,2},{112,32,6,2},{16,56,12,2}}, -- 7
{{32,32,15,1},{64,32,7,1},{64,80,6,3}}, -- 8
{{64,8,16,1},{112,56,19,2},{16,80,3,3}}, -- 9
{{4,8,4,1},{112,32,20,2},{64,80,2,3}}, -- 10
{{112,8,4,2},{4,32,12,1},{4,80,20,3}}, -- 11
{{4,32,11,2},{16,56,7,3},{112,80,18,3}}, -- 12
{{112,8,14,1},{24,32,17,2},{8,56,1,2}}, -- 13
{{4,32,19,1},{112,8,13,1},{96,80,15,3}}, -- 14
{{24,32,8,1},{24,56,16,2},{96,80,14,3}}, -- 15
{{64,8,9,1},{32,56,15,2},{112,80,17,3}}, -- 16
{{8,8,18,1},{40,32,13,2},{112,80,16,3}}, -- 17
{{4,8,17,1},{48,80,19,3},{112,80,12,3}}, -- 18
{{4,32,14,2},{112,56,9,2},{48,80,18,2}}, -- 19
{{56,8,5,1},{104,32,10,2},{16,80,11,3}}, -- 20
{{4,32,21,2},{112,80,21,1}}
} -- make sure to test whole width - x,y,where leads
booty={{{1,1,4},{0,4,5},{14,4,3},{3,7,2},{6,10,7},{13,10,1}},
{{16,1,3},{26,1,2},{28,1,6},{23,4,9},{30,4,4},{17,7,5},{25,7,8},{18,10,6},{21,10,7}},
{{32,1,1},{45,1,6},{34,4,10},{34,7,2},{45,7,3},{39,10,11},{44,10,9}},
{{58,7,1},{57,10,1}}, -- 4
{{68,1,1},{78,1,2},{71,4,3},{74,4,4},{65,10,5},{70,10,6}}, -- 5
{{82,1,1},{84,1,1},{82,7,1},{85,7,1},{82,10,1},{86,10,1}}, -- 6
{{100,1,1},{108,1,2},{98,4,3},{103,4,4},{108,4,5},{97,7,1},{102,7,1},{100,10,1},{105,10,1},{110,10,1}}, -- 7
{{122,1,1},{127,1,1},{117,4,1},{127,7,1},{126,10,1}}, -- 8
{{1,17,1},{6,17,1},{13,17,1},{1,20,1},{9,20,1},{14,20,1},{1,23,1},{6,23,1},{6,26,1},{1,26,10}}, -- 9
{{26,17,1},{28,17,1},{30,17,1},{28,20,1},{30,23,1},{28,26,1},{30,26,1}}, -- 10
{{34,17,1},{45,17,1},{45,20,1},{34,23,1},{46,23,1},{38,26,1},{45,26,1}}, -- 11
{{50,17,1},{62,17,1},{51,20,1},{49,26,1},{54,26,1},{62,23,1}}, -- 12
{{65,17,1},{65,20,1},{77,20,1},{75,23,1},{77,23,1},{74,26,1},{77,26,1}}, -- 13
{{92,17,1},{91,20,1},{95,20,1},{91,23,1},{80,26,1},{89,26,1}}, -- 14
{{98,17,1},{110,17,1},{110,23,1},{98,26,1}}, -- 15
{{115,17,1},{127,17,1},{116,20,1},{124,20,1},{120,23,1},{124,23,1},{116,26,1},{124,26,1}}, -- 16
{{10,33,1},{14,33,1},{15,39,1},{1,42,1}}, -- 17
{{17,36,1},{19,39,1},{17,42,1}}, -- 18
{{34,33,1},{41,33,1},{45,36,1},{36,39,1},{44,39,1},{33,42,1},{41,42,1}}, -- 19
{{53,33,1},{62,33,1},{48,36,1},{52,36,1},{55,36,1},{48,39,1},{60,42,1}}, -- 20
{{68,33,1},{79,33,1},{75,39,1},{76,42,1}}
} -- treasure placement - x,y,type/taken (0)
-- randomize booty - adds variation & gets over duplicate booty bug
btype={{}} -- booty type
brange={1,2,3,4,5,6,7,8,9,10,11}
for l=1,22 do -- num of lvls = 21
shuffle(brange,#brange)
for m=1,11 do
btype[l]=brange
end
end
-- replacement data for disappearing platforms (in place of moving ones)
templatforms={
{{}}, -- 1
{{}}, -- 2
{{32,24,7,0,0},{32,48,7,0,0},{32,72,7,0,0}}, -- 3
{{40,48,4,2,0},{40,72,4,2,0}}, -- 4
{{32,72,2,1,0},{64,72,1,1,0}}, -- 5
{{88,48,1,1,0},{96,96,1,1,0}}, -- 6
{{}}, -- 7
{{}}, -- 8
{{32,24,1,0,0},{32,48,1,0,0},{32,72,1,0,0},{32,96,1,0,0},{80,24,1,0,0},{80,48,1,0,0},{80,72,1,0,0},{80,96,1,0,0}}, -- 9
{{24,24,5,0,0},{16,48,5,0,0},{16,72,5,0,0},{16,96,5,0,0}}, -- 10
{{32,24,1,0,0},{32,48,1,0,0},{32,72,1,0,0},{32,96,1,0,0}}, -- 11
{{32,24,7,0,0},{32,48,7,0,0},{32,72,7,0,0},{32,96,1,0,0},{80,96,1,0,0}}, -- 12
{{}}, -- 13
{{16,24,1,0,0},{16,48,1,0,0},{16,72,1,0,0},{16,96,1,0,0},{48,24,2,0,0},{48,48,2,0,0},{48,72,2,0,0}}, -- 14
{{64,24,4,0,0},{64,48,4,0,0},{88,72,1,0,0}}, -- 15
-- was {{64,24,1,0,0},{64,48,1,0,0},{88,24,1,0,0},{88,48,1,0,0},{88,72,1,0,0}}
{{}}, -- 16
{{24,24,5,0,0},{24,48,1,0,0},{24,72,1,0,0},{24,96,1,0,0},{56,48,1,0,0},{56,72,1,0,0},{56,96,1,0,0},{96,24,1,0,0},{96,48,1,0,0},{96,72,1,0,0}}, -- 17
{{64,24,4,0,0},{64,48,4,0,0},{64,72,4,0,0},{64,96,4,0,0}}, -- 18
{{}}, -- 19
{{64,72,2,1,0}}, -- 20
{{48,24,3,0,0},{88,24,2,0,0},{16,48,2,1,0},{88,48,2,0,0}}
} -- xstart,y,width,default,state
-- replacement data for abscence of lifts
altladders={
{{}},{{}},{{}},{{}},{{}}, -- 1-5
{{90,3},{88,6},{91,9}}, -- 6b
{{}},{{}}, -- 7-8
{{3,19},{12,22},{7,25}}, -- 9b
{{18,19},{24,22},{17,25}}, -- 10b
{{35,19},{38,22},{34,25}}, -- 11b
{{60,19},{51,22},{55,25}}, -- 12b
{{}}, -- 13
{{89,19},{81,22},{85,25}}, -- 14b
{{103,19},{109,22}}, -- 15b
{{}}, -- 16
{{2,35},{9,38},{12,41}}, -- 17b
{{29,35},{23,38},{29,41}}, -- 18b
{{}},{{}} -- 19-20
}
-- unused data for testing traveling platforms
travs={ {{0,0,0,0,0,0}}, -- 1
{{0,0,0,0,0,0}}, -- 2
{{32,24,32,88,0,1},{88,48,32,88,1,1},{32,72,32,88,0,1}}, --3
{{0,0,0,0,0,0}}, -- 4
{{0,0,0,0,0,0}}, -- 5
{{0,0,0,0,0,0}}, -- 6
{{0,0,0,0,0,0}}, -- 7
{{}}, -- 8
{{}}, -- 9
{{}}, -- 10
{{}}, -- 11
{{}}, -- 12
{{}}, -- 13
{{}}, -- 14
{{}}, -- 15
{{}}, -- 16
{{}}, -- 17
{{}}, -- 18
{{}}, -- 19
{{}}, -- 20
{{72,24,72,70,1,1}} -- 21
} -- x,y,xstart,xend,dir,width
-- unused data for testing lifts
lifts={ {{0,0,0,0,0,0}}, -- 1
{{0,0,0,0,0,0}}, -- 2
{{0,0,0,0,0,0}}, -- 3
{{0,0,0,0,0,0}}, -- 4
{{0,0,0,0,0,0}}, -- 5
{{88,24,24,96,0,1},{96,96,24,96,1,1}}, -- 6
{{0,0,0,0,0,0}}, -- 7
{{0,0,0,0,0,0}}, -- 8
{{32,152,152,200,0,1},{80,200,200,152,1,1}}, -- 9