-
Notifications
You must be signed in to change notification settings - Fork 1
/
patrick.p8
1637 lines (1579 loc) · 71.5 KB
/
patrick.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 16
__lua__
-- patrick's cyberpunk challenge
-- by tobiasvl
modes={
title_screen=1,
play=2,
win=3,
game_over=4,
tutorial=5,
story=6,
custom=7,
win_custom=8,
game_over_custom=9,
custom_list=10,
ending=11,
}
play_modes={
challenge=1,
infinite=2,
custom=3
}
balls={
{id=1,color=7,pos=0},
{id=2,color=9,pos=0},
{id=3,color=8,pos=0},
{id=4,color=11,pos=0},
{id=5,color=1,pos=0},
{id=6,color=12,pos=0},
{id=7,color=10,pos=0}
}
function _init()
n=15
w=127
t=0
mode=modes.title_screen
menu_selection=1
score=0
run=0
last_mouse,last_x,last_y=0,0,0
cartdata("tobiasvl_patrick")
high_reldni=dget(0)
high_score=dget(1)
high_run=dget(2)
high_custom=dget(3)
poke(0x5f2d,1)
emulated=stat(102)!=0
keyboard=stat(102)!=0 and stat(102)!="www.lexaloffle.com" and stat(102)!="www.playpico.com"
buttons={o=keyboard and "z" or "🅾️",x=keyboard and "x" or "❎"}
story_scroll=127
kill=false
mouse_pointer=0
fred=0
music(0)
title_lines={
{64,90,64,127,14},
{50,90,40,127,14},
{36,90,10,127,14},
{22,90,-30,127,14},
{8,90,-80.5,127,14},
{120,90,127+65,127,14},
{106,90,127+30,127,14},
{92,90,127-10.5,127,14},
{78,90,127-40.5,127,14},
}
custom_score=0
custom_levels=load_custom()
custom_list_selected=1
custom_page=flr(custom_list_selected/20)
load_progress()
levels={}
level_number=0
main_menu={
{function()
menu=play_menu
end, "play"},
{function()
init_board(true)
page=1
mode=modes.tutorial
music(-1)
end, "tutorial"},
{function()
story_scroll=127
mode=modes.story
end, "story"},
{function()
init_board(true,true)
mode=modes.custom_list
music(-1)
end, "edit custom"}
}
play_menu={
{function()
levels=preset_levels
level_number=1
play_mode=play_modes.challenge
init_board(false,false,levels[level_number])
mode=modes.play
music(-1)
end, "challenge mode"},
{function()
init_board()
play_mode=play_modes.infinite
mode=modes.play
music(-1)
end, "infinite mode"},
}
menu=main_menu
keys={
[1]=function(x,y) return x>1 and x>patrick.x-1 and x-1 or x,y end,
[2]=function(x,y) return x<7 and x<patrick.x+1 and x+1 or x,y end,
[4]=function(x,y) return x,y>1 and y>patrick.y-1 and y-1 or y end,
[8]=function(x,y) return x,y<4 and y<patrick.y+1 and y+1 or y end,
}
end
kls=cls
function cls()
if (not kill) kls()
end
-->8
-- _update()
function _update()
local mouse=stat(34)==1
local temp_mouse=mouse
mouse=mouse!=last_mouse and mouse or false
last_mouse=temp_mouse
if mode==modes.title_screen then
menuitem(1)
play_menu[3]=#custom_levels>0 and {function()
levels=custom_levels
level_number=1
play_mode=play_modes.custom
init_board(false,false,levels[level_number])
mode=modes.play
music(-1)
end, "custom levels"} or nil
if (btnp(2)) menu_selection=menu_selection==1 and #menu or menu_selection-1
if (btnp(3)) menu_selection=(menu_selection%#menu)+1
if (btnp(4)) menu_selection=1 menu=main_menu
if (btnp(5)) menu[menu_selection][1]()
local x,y=stat(32),stat(33)
if x!=old_x or y!=old_y or mouse then
old_x,old_y=x,y
if x>=47 and x<=69 and y>=30 and y<=34 then
menu_selection=1
elseif x>=47 and x<=85 and y>=36 and y<=40 then
menu_selection=2
elseif x>=47 and x<=73 and y>=42 and y<=46 then
menu_selection=3
elseif x>=47 and x<=77 and y>=48 and y<=52 then
menu_selection=4
end
end
if mouse then
if x>=15 and x<=20 and y>=3 and y<=10 then
fred+=1
if fred==4 then
add(main_menu,{function()
story_scroll=127
mode=modes.ending
end, "ending"})
elseif fred==7 then
kill=true
end
else
menu[menu_selection][1]()
end
mouse=false
end
elseif mode==modes.play then
local button=btnp()
menuitem(1,"title screen",function() mode=modes.title_screen music(0) end)
if play_mode==play_modes.infinite and button==0x10 and destroyed==0 then
init_board(false,false,levels[level_number])
end
if destroyed==27 then
sfx(25)
if play_mode==play_modes.challenge then
local status=1
for i=1,2 do
if (steps<=stars[level_number][i]) status+=1
end
preset_levels[level_number].status=status
save_progress()
end
mode=modes.win
elseif get_tile(patrick.x-1,patrick.y)==-1 and get_tile(patrick.x+1,patrick.y)==-1 and get_tile(patrick.x-1,patrick.y-1)==-1 and get_tile(patrick.x,patrick.y-1)==-1 and get_tile(patrick.x+1,patrick.y-1)==-1 and get_tile(patrick.x-1,patrick.y+1)==-1 and get_tile(patrick.x,patrick.y+1)==-1 and get_tile(patrick.x+1,patrick.y+1)==-1 then
sfx(8)
mode=modes.game_over
end
new_highlight={}
new_highlight.x,new_highlight.y=highlight.x,highlight.y
if button!=0 then
for mask in all({1,2,4,8}) do
if band(button,mask)!=0 then
new_highlight.x,new_highlight.y=keys[mask](new_highlight.x,new_highlight.y)
end
end
else
local x,y=stat(32),stat(33)
if x!=old_x or y!=old_y or mouse then
old_x,old_y=x,y
x,y=ceil(x/18),ceil((y-10)/18)
new_highlight.x=(x==patrick.x-1 or x==patrick.x or x==patrick.x+1) and x or 0
new_highlight.y=(y==patrick.y-1 or y==patrick.y or y==patrick.y+1) and y or 0
end
end
if get_tile(new_highlight.x,new_highlight.y)>=0 then
highlight=new_highlight
end
if (button==0x20 or mouse) and not (highlight.x==patrick.x and highlight.y==patrick.y) then
steps+=1
mouse=false
destroy_tile(patrick.x,patrick.y)
patrick.x,patrick.y=highlight.x,highlight.y
local tile=get_tile(highlight.x,highlight.y)
if tile>0 then
sfx(33)
if tile==7 or tile==2 then
destroy_tile(highlight.x-1,highlight.y-1)
destroy_tile(highlight.x,highlight.y-1)
destroy_tile(highlight.x+1,highlight.y-1)
end
if tile==3 or tile==2 then
destroy_tile(highlight.x-1,highlight.y+1)
destroy_tile(highlight.x,highlight.y+1)
destroy_tile(highlight.x+1,highlight.y+1)
end
if tile==4 or tile==5 then
destroy_tile(highlight.x-1,highlight.y-1)
destroy_tile(highlight.x-1,highlight.y)
destroy_tile(highlight.x-1,highlight.y+1)
end
if tile==6 or tile==5 then
destroy_tile(highlight.x+1,highlight.y-1)
destroy_tile(highlight.x+1,highlight.y)
destroy_tile(highlight.x+1,highlight.y+1)
end
set_tile(highlight.x,highlight.y,0)
elseif destroyed!=27 then
sfx(60)
end
end
elseif mode==modes.win then
if btnp(5) or mouse then
if play_mode==play_modes.challenge then
if level_number<#levels then
level_number+=1
else
mode=modes.ending
end
else
score+=60-steps
if play_mode==play_modes.infinite then
run+=1
if (score>high_score) dset(1,score) dset(2,run)
end
end
init_board(false,false,levels[level_number])
mode=modes.play
mouse=false
end
elseif mode==modes.game_over then
if btnp(5) or mouse then
if (play_mode!=play_modes.challenge) score=max(0,score-60+steps)
if play_mode==play_modes.infinite then
run+=1
if (score>high_score) dset(1,score) dset(2,run)
end
init_board(false,false,levels[level_number])
mode=modes.play
mouse=false
end
elseif mode==modes.win_custom or mode==modes.game_over_custom then
if btnp(5) or mouse then
mode=modes.custom
mouse=false
end
elseif mode==modes.tutorial then
menuitem(1,"title screen",function() mode=modes.title_screen music(0) end)
if btnp(5) or mouse then
page+=1
if (page==6) init_board()
if (page==12) mode=modes.play
end
if page==5 then
for y=1,4 do
for x=1,7 do
if (not (patrick.x==x and patrick.y==y)) board[y][x]=-1
end
end
elseif page==3 then
local new_patrick={x=patrick.x,y=patrick.y}
mask=flr(rnd(15))+1
for i in all({band(mask,1),band(mask,2)}) do
local should_break=false
for j in all({band(mask,4),band(mask,8)}) do
if (i!=0) new_patrick.x,new_patrick.y=keys[i](patrick.x,patrick.y)
if (j!=0) new_patrick.x,new_patrick.y=keys[j](new_patrick.x,new_patrick.y)
if get_tile(new_patrick.x,new_patrick.y)==0 then
if (not (new_patrick.x==patrick.x and new_patrick.y==patrick.y)) destroy_tile(patrick.x,patrick.y) patrick=new_patrick should_break=true break
end
end
if (should_break) break
end
end
elseif mode==modes.story then
menuitem(1,"title screen",function() mode=modes.title_screen music(0) end)
if btn(2) then
story_scroll-=1
elseif btn(3) then
story_scroll+=1
elseif btnp(4) or btnp(5) then
mode=modes.title_screen
else
if not kill then
story_scroll-=0.2
else
if (story_scroll>-364) story_scroll-=1
end
end
elseif mode==modes.custom then
menuitem(1,"title screen",function() mode=modes.title_screen music(0) end)
if patrick.x>0 and btnp(5) then
if not custom_levels[custom_list_selected] then
custom_levels[custom_list_selected]={}
end
custom_levels[custom_list_selected][1]=balls[1].pos
for i=2,7 do
custom_levels[custom_list_selected][7-(i-2)]=balls[i].pos
end
save_custom()
mode=modes.custom_list
end
if mouse then
local x,y=stat(32),stat(33)
if old_x!=x or old_y!=y or mouse then
old_x,old_y=x,y
cell_x,cell_y=ceil(x/18),ceil((y-10)/18)
if mouse_pointer!=0 and get_tile(cell_x,cell_y)==-1 then
mouse_pointer=0
elseif patrick.x==-1 and x>=0 and x<=15 and y>=94 and y<=110 then
mouse_pointer=1
elseif patrick.x==cell_x and patrick.y==cell_y then
patrick={x=-1,y=-1}
balls[1].pos=0
mouse_pointer=1
elseif balls[2].pos==0 and x>=16 and x<=24 and y>=94 and y<=102 then
mouse_pointer=2
elseif balls[3].pos==0 and x>=26 and x<=34 and y>=94 and y<=102 then
mouse_pointer=3
elseif balls[4].pos==0 and x>=36 and x<=44 and y>=94 and y<=102 then
mouse_pointer=4
elseif balls[5].pos==0 and x>=16 and x<=24 and y>=104 and y<=112 then
mouse_pointer=5
elseif balls[6].pos==0 and x>=26 and x<=34 and y>=104 and y<=112 then
mouse_pointer=6
elseif balls[7].pos==0 and x>=36 and x<=44 and y>=104 and y<=112 then
mouse_pointer=7
elseif get_tile(cell_x,cell_y)==0 and mouse_pointer>0 then
if mouse_pointer==1 then
patrick.x,patrick.y=cell_x,cell_y
elseif mouse_pointer>0 then
set_tile(cell_x,cell_y,balls[mouse_pointer].id)
end
balls[mouse_pointer].pos=cell_x+(7*(cell_y-1))
mouse_pointer=0
elseif get_tile(cell_x,cell_y)>0 then
local pick_up=get_tile(cell_x,cell_y)
set_tile(cell_x,cell_y,0)
balls[pick_up].pos=0
if (pick_up==1) patrick.x,patrick.y=-1,-1
if mouse_pointer==1 then
patrick.x,patrick.y=cell_x,cell_y
balls[mouse_pointer].pos=cell_x+(7*(cell_y-1))
elseif mouse_pointer>0 then
set_tile(cell_x,cell_y,balls[mouse_pointer].id)
balls[mouse_pointer].pos=cell_x+(7*(cell_y-1))
end
mouse_pointer=pick_up
end
end
end
elseif mode==modes.custom_list then
if btnp(2) then
if (custom_list_selected>1) custom_list_selected-=1
if (custom_list_selected<(custom_page*20)+1) custom_page-=1
end
if btnp(3) then
if (custom_list_selected<50 and custom_levels[custom_list_selected]!=nil) custom_list_selected+=1
if (custom_list_selected>(custom_page*20)+20) custom_page+=1
end
if (btnp(4)) mode=modes.title_screen
if btnp(5) then
local empty_level=custom_levels[custom_list_selected]==nil
init_board(empty_level,empty_level,custom_levels[custom_list_selected])
mode=modes.custom
end
elseif mode==modes.ending then
menuitem(1,"title screen",function() mode=modes.title_screen music(0) end)
if btn(2) then
story_scroll-=1
elseif btn(3) then
story_scroll+=1
elseif btnp(4) or btnp(5) then
mode=modes.title_screen
else
story_scroll-=0.2
end
end
end
-->8
-- _draw()
function _draw()
if mode==modes.title_screen then
local x,y=stat(32),stat(33)
cls()
if (fred==1) print("fred?",15,3)
if (fred==2) print("fred\nwho?",15,3)
if (fred==3) print("freddie\nfinkle?",15,3)
if (fred==4) print("that\nbastard",15,3)
outline("patrick's",0,2,11,7,true)
outline("cyberpunk",0,9,3,11,true)
outline("challenge",0,16,8,0,true)
cursor(35,45)
for i=1,#menu do
color(menu_selection==i and 10 or 14)
if (menu_selection==i) then
print(">"..menu[i][2].."_")
else
print(menu[i][2])
end
end
cursor(0,73)
if menu==main_menu then
if (flr(time())%2==0) center("\npress "..buttons.x,6)
else
color()
if menu_selection==2 then
center("high score: "..high_score,7)
center("(run: "..high_run.." levels)",7)
else
center("high score: "..(menu_selection==2 and high_reldni or high_custom),7)
end
end
cursor(0,107)
center("by",5)
center("tobiasvl",5)
local title_y=90
t-=.5
for i=0,n do
local z=(i*n+t%n)
local y=w*n/z+32
line(0,title_y-5,127,title_y-5,1)
line(0,title_y-4,127,title_y-4,2)
line(0,title_y-3,127,title_y-3,13)
line(0,title_y-2,127,title_y-2,9)
line(0,title_y-1,127,title_y-1,10)
line(0,title_y,127,title_y,14)
line(0,title_y+6,127,title_y+6,14)
line(0,title_y+16,127,title_y+16,14)
line(0,title_y+28,127,title_y+28,14)
line(0,title_y+46,127,title_y+46,14)
local v=i+t%n/n-n/2
line(v*9+64,title_y,v*60+64,w,14)
end
if x>=15 and x<=18 and y>=3 and y<=6 then
spr(15,x,y,1,2)
else
if (not emulated) spr(16,x,y)
end
elseif mode==modes.tutorial then
cls()
local s=buttons.x..": next"
print(s,128-((keyboard and 7 or 8)*4),0,7)
local offset=10
for y=1,4 do
for x=1,7 do
local tile=get_tile(x,y)
if tile>=0 then
rect(18*(x-1),offset+(18*(y-1)),18*(x),offset+(18*(y)),14)
local bg=2
if (page==2 and (x==patrick.x-1 or x==patrick.x or x==patrick.x+1) and (y==patrick.y-1 or y==patrick.y or y==patrick.y+1)) bg=5
if (patrick.x==x and patrick.y==y) bg=6
rectfill(18*(x-1)+1,offset+(18*(y-1))+1,18*(x)-1,offset+(18*(y))-1,bg)
if (tile>0) circfill(18*(x-1)+9,offset+(18*(y-1))+9,4,balls[tile].color)
end
end
end
palt(0,false)
palt(6,true)
spr(1,(18*(patrick.x-1))+2,offset+(18*(patrick.y-1))+2,2,2)
palt()
rectfill(0,83,127,127,0)
cursor(0,88)
color(11)
if page==1 then
print("the object of the game is to")
print("remove all 28 squares.")
elseif page==2 then
cursor(0,86)
print("patrick can move to any square")
print("that is adjacent to where he is.")
print("(even diagonally!)")
print(" ⬆️")
print("select square: ⬅️⬇️➡️ move: "..buttons.x)
print(" (or mouse)")
elseif page==3 then
print("each time patrick moves, the")
print("square he was on will disappear.")
elseif page==4 then
oh_no()
color(11)
cursor(0,88)
print("you will lose when patrick can")
print("no longer move to any remaining")
print("squares.")
elseif page==5 then
all_right()
color(11)
cursor(0,88)
print("if you make all the squares")
print("disappear, you win the level.\n")
print("either way, a new level will")
print("automatically be generated.")
elseif page==6 then
print("moving patrick to a")
print("colored ball will")
print("make the correspon-")
print("ding squares (see")
print("legend) disappear.")
print_legend()
elseif page==7 then
cursor(36,88)
print("for each level you win")
print("you get 60 points minus")
print("the number of squares")
print("you landed on.")
print("level "..run+1,1,88,7)
print("score "..score,1,94,7)
print("win +"..60-steps,1,100,11)
print("lose -"..60+steps,1,106,5)
elseif page==8 then
cursor(36,88)
print("for each level you lose,")
print("you get 60 points plus")
print("the number of squares")
print("you landed on deducted")
print("from your score.")
print("level "..run+1,1,88,7)
print("score "..score,1,94,7)
print("win +"..60-steps,1,100,5)
print("lose -"..60+steps,1,106,8)
elseif page==9 then
cursor(0,86)
color(11)
print("each level has a seven-numbered")
print("code, which you can write down")
print("to play later, or give to a")
print("friend. use the \"custom\" mode")
print("to input codes and play a single")
print("level.")
elseif page==10 then
cursor(0,86)
print("each number says what square a")
print("ball occupies, 1-28 (or 0 for")
print("none). duplicate numbers are")
print("overridden from left to right.")
print("the white number is patrick and")
print("can't be 0 or overridden.")
elseif page==11 then
cursor(0,86)
print("it is unknown at this time")
print("whether it is possible to have")
print("or create an unsolvable level.")
print("you can skip a level without")
print("penalty if you have not made any")
print("moves and think it's impossible.")
end
if page==9 or page==10 or page==11 then
print_code()
end
elseif mode==modes.play or mode==modes.win or mode==modes.game_over then
cls()
print_code()
if destroyed==0 and play_mode==play_modes.infinite then
local s=buttons.o..": skip"
print(s,128-((keyboard and 7 or 8)*4),0,7)
end
local offset=10
for y=1,4 do
for x=1,7 do
local pos={x=18*(x-1),y=offset+(18*(y-1))}
local tile=get_tile(x,y)
if tile>=0 then
rect(pos.x,pos.y,18*(x),offset+(18*(y)),14)
local bg=2
if (not kill and (x==patrick.x-1 or x==patrick.x or x==patrick.x+1) and (y==patrick.y-1 or y==patrick.y or y==patrick.y+1)) bg=5
if (patrick.x==x and patrick.y==y) bg=0
if (highlight.x==x and highlight.y==y) bg=6
local highlighted_tile=get_tile(highlight.x,highlight.y)
if not kill and highlighted_tile>0 then
if highlighted_tile==7 or highlighted_tile==2 then
if (y==highlight.y-1 and (x==highlight.x-1 or x==highlight.x or x==highlight.x+1)) bg=0
end
if highlighted_tile==3 or highlighted_tile==2 then
if (y==highlight.y+1 and (x==highlight.x-1 or x==highlight.x or x==highlight.x+1)) bg=0
end
if highlighted_tile==4 or highlighted_tile==5 then
if (x==highlight.x-1 and (y==highlight.y-1 or y==highlight.y or y==highlight.y+1)) bg=0
end
if highlighted_tile==6 or highlighted_tile==5 then
if (x==highlight.x+1 and (y==highlight.y-1 or y==highlight.y or y==highlight.y+1)) bg=0
end
end
rectfill(pos.x+1,pos.y+1,18*(x)-1,offset+(18*(y))-1,bg)
if tile>0 then
circfill(pos.x+9,pos.y+9,4,balls[tile].color)
local beams=function(dir,pos)
local dirs={
u={pos.x+9,pos.y+2,pos.x+9,pos.y+3},
ur={pos.x+14,pos.y+4,pos.x+15,pos.y+3},
r={pos.x+15,pos.y+9,pos.x+16,pos.y+9},
dr={pos.x+14,pos.y+14,pos.x+15,pos.y+15},
d={pos.x+9,pos.y+15,pos.x+9,pos.y+16},
dl={pos.x+3,pos.y+15,pos.x+4,pos.y+14},
l={pos.x+2,pos.y+9,pos.x+3,pos.y+9},
ul={pos.x+3,pos.y+3,pos.x+4,pos.y+4}
}
return dirs[dir][1],dirs[dir][2],dirs[dir][3],dirs[dir][4]
end
if flr(time())%2==0 then
if tile==7 or tile==2 then
for dir in all({"ul","u","ur"}) do
line(beams(dir,pos))
end
end
if tile==3 or tile==2 then
for dir in all({"dl","d","dr"}) do
line(beams(dir,pos))
end
end
if tile==4 or tile==5 then
for dir in all({"ul","l","dl"}) do
line(beams(dir,pos))
end
end
if tile==6 or tile==5 then
for dir in all({"dr","r","ur"}) do
line(beams(dir,pos))
end
end
end
end
end
end
end
palt(0,false)
palt(6,true)
local sprite=1
if kill then
local foo=run%balls[1].pos
if (foo==3) sprite=3
if (foo==5) sprite=39
if (foo==7) sprite=41
if (foo==9) sprite=46
if (foo==13) sprite=64
if (foo==15) sprite=66
end
spr(sprite,(18*(patrick.x-1))+2,offset+(18*(patrick.y-1))+2,2,2)
palt()
if play_mode==play_modes.infinite then
print("level"..(kill and "-" or " ")..run+1,1,88,7)
else
print("level"..(kill and "-" or " ")..level_number,1,88,7)
end
if play_mode==play_modes.challenge then
print("steps "..steps,40,88,7)
outline("\146",40,95,levels[level_number].status>0 and 11 or 7,9)
local x=50
for i=1,2 do
outline("\146",x,95,levels[level_number].status>=i+1 and 11 or 7,steps<=stars[level_number][i] and 9 or 0)
x+=10
end
else
print("score "..score,1,94,7)
print("win +"..60-steps,1,100,5)
print("lose -"..60+steps,1,106,5)
end
print_legend()
if (not emulated) spr(16,stat(32),stat(33))
end
if mode==modes.win then
local s=buttons.x..": next"
print(s,128-((keyboard and 7 or 8)*4),0,7)
if play_mode!=play_modes.challenge then
print("score "..score,1,94,5)
print("win +"..60-steps,1,100,11)
print("score="..score+(60-steps),1,114,7)
else
local x=40
for i=1,3 do
outline("\146",x,95,levels[level_number].status>=i and 11 or 7,levels[level_number].status>=i and 9 or 0)
x+=10
end
end
all_right()
elseif mode==modes.game_over then
if play_mode!=play_modes.challenge then
local s=buttons.x..": next"
print(s,128-((keyboard and 7 or 8)*4),0,7)
print("score "..score,1,94,5)
print("lose -"..60+steps,1,106,8)
print("score="..max(0,score-(60+steps)),1,114,7)
else
local s=buttons.x..": retry"
print(s,128-((keyboard and 8 or 9)*4),0,7)
local x=40
for i=1,3 do
outline("\146",x,95,levels[level_number].status>=i and 11 or 7,0)
x+=10
end
end
oh_no()
elseif mode==modes.win_custom then
local s=buttons.x..": edit"
print(s,128-((keyboard and 7 or 8)*4),0,7)
print("score "..60-steps,1,100,11)
all_right()
elseif mode==modes.game_over_custom then
local s=buttons.x..": edit"
print(s,128-((keyboard and 7 or 8)*4),0,7)
print("lose -"..60+steps,1,106,8)
oh_no()
elseif mode==modes.story then
if (kill) cls(5) else cls()
story={
"it is the year 2077.",
"",
"the evil ernie york, former",
"electronic store owner and",
"cryogenics innovator, now",
"mutated multibillionaire ceo of",
"the sinister zebra corporation,",
"rules fun land with his army of",
"advanced robots - beings dis-",
"similar to humans - known as",
"tomb bots",
"",
"",
"",
"",
"",
"the immortal spirit of the",
"leprechaun patrick magee - now",
"clad in sunglasses and a black",
"coat - is the last vestige of",
"the jackie gleason appreciation",
"society, an ancient underground",
"rebel alliance.",
"",
"",
"",
"",
"",
"now patrick must traverse and",
"dismantle the mazes of szc's",
"virtual reality system to shut",
"down the tomb bot factories.",
"hindering his quest are digital",
"versions of the szc's neon",
"\"shine 'n glow\" energy balls;",
"but perhaps they can help too?",
"",
"",
"",
"",
"",
"are you ready for the challenge?",
}
local scroll_offset=0
if kill then
cursor(0,story_scroll)
else
spr(39,56,12*6+story_scroll,2,2)
palt(0,false)
palt(6,true)
spr(story_scroll<-50 and 1 or 3,56,24*6+story_scroll,2,2)
palt()
local ball_x=40
for ball in all(balls) do
if ball.id!=1 then
circfill(ball_x,38*6+story_scroll,4,ball.color)
ball_x+=10
end
end
if (story_scroll<-300) local str="press "..buttons.x print(str,64-(#str*2),64,7)
end
for str in all(story) do
if (scroll_offset==6*10) color(8) else color(7)
if not kill then
print(str,64-(#str*2),story_scroll+scroll_offset)
local x,y=flr(rnd(127)),flr(rnd(127))
line(x,y,x-3,y-3,7)
else
if (story_scroll<-300) cls=kls
if (str!="") center(str)
palt(0,false)
palt(6,true)
spr(41,story_scroll+427,40,2,2)
spr(43,story_scroll+427,40+16,2,1)
spr(story_scroll%12!=0 and 59 or 45,story_scroll+427,40+24)
spr(story_scroll%10!=0 and 60 or 61,story_scroll+427+8,40+24)
palt()
if (story_scroll==-364) spr(36,54,25,3,2,true) print("where\nam i?",56,26,0)
end
scroll_offset+=6
end
elseif mode==modes.custom then
cls()
print_code()
if (patrick.x>0) local s=buttons.x..": save" print(s,128-((keyboard and 7 or 8)*4),0,7)
print_legend()
local offset=10
for y=1,4 do
for x=1,7 do
local tile=get_tile(x,y)
if tile>=0 then
rect(18*(x-1),offset+(18*(y-1)),18*(x),offset+(18*(y)),14)
local bg=2
rectfill(18*(x-1)+1,offset+(18*(y-1))+1,18*(x)-1,offset+(18*(y))-1,bg)
if (tile>0) circfill(18*(x-1)+9,offset+(18*(y-1))+9,4,balls[tile].color)
end
end
end
palt(0,false)
palt(6,true)
if mouse_pointer==1 then
spr(1,stat(32),stat(33),2,2)
elseif patrick.x==-1 then
spr(1,0,94,2,2)
else
spr(1,(18*(patrick.x-1))+2,offset+(18*(patrick.y-1))+2,2,2)
end
palt()
local x,y=20,98
for i=2,7 do
if mouse_pointer==i then
circfill(stat(32)+4,stat(33)+4,4,balls[i].color)
elseif balls[i].pos==0 then
circfill(x,y,4,balls[i].color)
end
x+=10
if (x==50) x,y=20,108
end
if (not emulated) spr(16,stat(32),stat(33))
elseif mode==modes.ending then
cls()
if (story_scroll<-150 and story_scroll>-155) or (story_scroll<-160 and story_scroll>-165) or (story_scroll<-170 and story_scroll>-175) then
rectfill(0,0,128,128,8)
palt(0,false)
palt(6,true)
pal(0,13)
pal(10,13)
pal(7,13)
pal(8,13)
spr(41,56,80,2,2)
spr(43,56,96,2,2)
pal()
palt()
elseif story_scroll<-180 then
if story_scroll>-190 then
pal(6,1)
pal(0,13)
pal(10,13)
pal(7,13)
pal(8,13)
elseif story_scroll>-200 then
pal(6,5)
pal(0,6)
pal(10,6)
pal(7,6)
pal(8,6)
end
rectfill(0,0,128,128,6)
palt(0,false)
palt(6,true)
if story_scroll>-250 then
spr(41,56,80,2,2)
spr(43,56,96,2,1)
spr(59,56,96+8,2,1)
elseif story_scroll<-250 then
spr(41,story_scroll+250+56,80,2,2)
spr(43,story_scroll+250+56,96,2,1)
spr(flr(story_scroll)%2==0 and 59 or 45,story_scroll+250+56,96+8)
spr(flr(story_scroll)%2!=0 and 60 or 61,story_scroll+250+56+8,96+8)
end
pal()
palt()
if story_scroll<-200 then
--trapdoor
line(56,0,40,8,0)
line(72,0,88,8,0)
--sign
rect(68,12,114,30,0)
rectfill(69,13,113,29,5)
pset(70,14,0)
pset(70,28,0)
pset(112,28,0)
pset(112,14,0)
print("vinnie's",80,16,6)
print("tomb",88,22,6)
--arrow
line(74,16,74,26,6)
line(74,16,70,20,6)
line(74,16,78,20,6)
line(0,112,128,112,0)
--screen
rectfill(14,43,112,57,0)
rectfill(15,42,111,58,0)
--ground and drops
rectfill(0,113,128,128,5)
local x,y=flr(rnd(127)),flr(rnd(127))
line(x,y,x,y+3,12)
end
if story_scroll<-220 and story_scroll>-240 then
spr(36,50,65,3,2,true)
print("where\nam i?",52,66,0)
end
if story_scroll<-150 and story_scroll>-325 then
if flr(story_scroll)%3!=0 then
cursor(0,45)
center("warning:",8)
center("power failure in cryo #1",8)
end
elseif story_scroll<-325 and story_scroll>-350 then
cursor(0,45)
center("a game by",11)
center("tobias v. langhoff",11)
elseif story_scroll<-350 and story_scroll>-375 then
cursor(0,45)
center("based on a game by",11)
center("reldni productions",11)
elseif story_scroll<-375 and story_scroll>-400 then
cursor(0,45)
center("dedicated to",11)
center("troy scott 1970-2000",11)
elseif story_scroll<-400 then
cursor(0,48)
center("press "..buttons.x)
end
end
local story={
"patrick has made it.",
"",
"",
"he has hacked the sinister zebra",
"corporation's virtual reality",
"system, and gained access to",
"their mainframe.",
"",
"",
"as the tomb bot factories shut",
"down all over fun land, ernie",
"york's electronic weather",
"systems also lose power, and",
"the rain finally ends after",
"several decades.",
"",
"",