-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpandora.p8
1801 lines (1708 loc) · 86.5 KB
/
pandora.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 29
__lua__
-- # pandora
-- cat explore. socky find.
-- to export:
-- fn + f7 to capture label image
-- save pandora.p8.png
-- export pandora.html
function _init()
-- global variables:
game_version = "07"
level = 1
last_level = 16
selected_level = 1 -- used in menu
debug_mode = false -- shows debug info and unfogs each level
debug_text = "debug mode"
win = false
lose = false
in_game = false -- determines whether a level is in progress
title_active = true
levelling_up = false
spotlight = false
hints_active = false
credits_active = false
t = 0 -- game time in frames
unfog_frames = 3 -- how fast the unfogging happens
caption_frames = 3 -- how fast the captions move
cat_frames = 1 -- number of frames between each cat move animation
menu_items = 7
medal_text = {"gold", "silver", "bronze", "none"}
medal_sprite = {12, 13, 14, 15}
anim_frame = 0 -- allows sprites to animate
offset = 0 -- screen offset for shaking
move_step = 9 -- variable governing move animation
moving = false
play_music = true
play_sounds = true
ice = false
x = 64
y = 24
dx = 0
dy = 0
dir = "r"
socky_bonus = 10 -- bonus awarded on collecting socky, in addition to the moves reimbursed for the detour. revisit moves_data if changing this
moves = 9999
mab_small_x = 16
game_get_data()
reset_palette()
title_show()
end
function _update()
-- input and move
t += 1
if moves <= 0 and in_game then game_lose() end
if win and mab_small_x < 16 then -- animate mab at end
mab_retreat_step()
end
if btnp() != 0 or sliding then
-- a button has been pressed
if title_active then
title_active = false
level_reset() -- start current level
elseif level_start_menu then
if btnp(4) then level_start() end
if btnp(5) then
level_start()
menu_open()
end
elseif in_game then
if not moving then
move_process()
end
elseif menu_active then
menu_process_input()
elseif levelling_up then
level_end_process_option()
elseif lose then
if btnp(4) then
lose = false
level_reset()
else return end
elseif win == false and lose == false then -- start new level
level_reset()
elseif win and not credits_active then
draw_credits()
else
_init()
return
end
end
-- check if socky was recently obtained and unfog screen 1 step
if unfog_active then unfog_step() end
if caption_active then caption_step() end
if in_game then
move_catch_up()
if levelling_up and move_step >= 5 then level_up() end
if mab_hit and move_step >= 5 then game_lose() end
end
end
function _draw()
if title_active then draw_pandora() return end
if not in_game and not menu_active and not level_start_menu then return end
shake_screen()
draw_everything()
end
-- conventions: map is zero-based, arrays are 1-based.
-- to do next
-- enhance music
-- animate some background cells eg torch, water
function ar(a)
-- convert 0-based pixel to 1-based array position.
-- 0 maps to 1, 8 maps to 2
return flr(a/8) + 1
end
function px(a)
-- convert 1-based array position to 0-based pixel.
-- 1 maps to 0, 2 maps to 8
return (a-1) * 8
end
function reset_palette()
pal() -- reset palette
palt(13, true) -- set colour 13 transparent
palt(0, false) -- and black not
end
function title_show()
rectfill(0, 0, 127, 127, 1)
local title_colour = {10, 0, 5, 6, 7, 15, 14, 8, 9, 10, 11, 3}
for i=1,12 do
pal(10, title_colour[13-i]) -- swap yellow to different colours
map(0, 32, 8, 128-i*8, 14, 4) -- write pandora
end
reset_palette()
rectfill(34, 78, 94, 106, 0)
rect(33, 77, 93, 105, 14)
print("⬆️⬇️⬅️➡️ move", 36, 80, 15)
draw_controls("z", 36, 88)
draw_controls("x", 36, 96)
print("ok/wait", 64, 88, 14)
print("menu", 76, 96, 8)
print(game_version, 120, 120, 6)
end
function level_reset()
debug_text = "reset level"
x = start_pos[level][1] -- current position in pixels from 0
y = start_pos[level][2]
dx = 0 -- in case character was part way through move
dy = 0
moves = moves_data[level][3]
unfog_active = false
socky_collect = false
caption_active = false
title_active = false
menu_active = false
levelling_up = false
ice = ice_data[level]
sliding = false
hints_active = false
socky_add = 0
move_step = 9 -- to avoid cat sliding back across screen
anim_frame = 0 -- so that each level starts the same way
level_period = #obs_data[level]
dir = "r" -- current direction
selected_level = level
unfog_reset()
obstacle_update()
switch_reset()
unfog_circle()
draw_everything()
in_game = false
level_start_menu = true
end
function level_start()
if level == 16 then level_16_reset() end
if debug_mode then unfog_start() end
level_start_menu = false
in_game = true
sfx(-1) -- stop playing sound
if play_music then music(level_music[level]) end -- main theme
end
function level_16_reset()
mab_reset()
mabx = 0
maby = 0
mab_active = false
end
function level_up()
in_game = false
sliding = false
moving = false
level_end_menu()
end
function level_end_menu()
if level == 16 then
rectfill(56, 0, 63, 7, 12) -- hide mab socky
anim_frame = 0
draw_pandora()
spr(253, 64, 0)
end
draw_menu_outline()
local medal_this_try = 4
-- award medal for this attempt: 1=gold 2=silver 3=bronze 4=none
if moves >= moves_data[level][4] then medal_this_try = 1
elseif moves >= moves_data[level][5] then medal_this_try = 2
elseif moves >= moves_data[level][6] then medal_this_try = 3
end
print("pandora got through level "..tostr(level).."!", 8, 24, 7)
print("medal: "..medal_text[medal_this_try], 8, 40, 7)
spr(medal_sprite[medal_this_try], 36, 40)
print("continue", 32, 56, 11)
print("retry level", 32, 64, 12)
if medal_this_try < best_medal[level] then
best_medal[level] = medal_this_try
end
draw_progress()
level_end_option = 1 -- default is continue to next level
spr(24, 16, 48 + level_end_option * 8)
end
function level_end_process_option()
if btnp(⬆️) or btnp(⬇️) then
level_end_option = 3 - level_end_option
rectfill(16, 48, 23, 71, 0)
spr(24, 16, 48 + level_end_option * 8)
elseif btnp(4) then level_end_choose() end
end
function level_end_choose()
if level_end_option == 1 then -- continue to next level
if level != last_level then
level += 1
level_reset()
else
levelling_up = false
game_win()
end
else
level_reset()
end
end
function game_win()
rectfill(0, 16, 127, 79, 0)
local perfect = true
for k in all(best_medal) do
-- if any medal is not gold then it's not perfect
if k != 1 then perfect = false break end
end
if perfect then
for i=0, 15 do -- draw rainbows
spr(208, i*8, 8)
spr(208, i*8, 112)
end
spr(255, 96, 24) -- trophy
pal(10, 11)
map(0, 40, 0, 32, 16, 4) -- write perfect in green
else
pal(10, 9)
map(0, 36, 4, 32, 15, 4) -- write you win in orange
end
reset_palette()
win = true
mab_retreat_start()
end
function game_lose()
sfx(-1)
music(-1)
local lose_text = "pandora is sleepy - try again"
local lose_colour = 2
in_game = false
if mab_hit then
lose_text = "mab got you"
lose_colour = 8
mab_hit = false
end
rectfill(0, 40, 127, 79, lose_colour)
spr(1, 8, 64, 1, 1, false, true) -- upside down cat
draw_controls("z", 96, 64)
print3d(lose_text, 8, 48, 10, 0)
if play_sounds then sfx(51) end
lose = true
end
-- ## movement functions
-- flag key
-- 0 = all wall
-- 1 = up wall (not used yet)
-- 2 = down wall (not used yet)
-- 3 = left wall (not used yet)
-- 4 = right wall (not used yet)
-- 5 = danger
-- 6 = ice
-- 7 = unassigned
-- music
-- 01 main bass
-- 02 upbeat drum
-- 03 main melody
-- 04 intro drum
-- 05 descending backing
-- 06-10 dark and final boss
-- 11 start of final zone
-- 12-14 ice
-- 15-17 machine
function move_process()
newx = x
newy = y
if not sliding and not btnp(5) then anim_frame += 1 end
obstacle_update()
if btnp(5) then menu_open()
elseif sliding then move_attempt(dir)
elseif btnp(⬆️) then move_attempt("u")
elseif btnp(⬇️) then move_attempt("d")
elseif btnp(⬅️) then move_attempt("l")
elseif btnp(➡️) then move_attempt("r")
end
end
function move_attempt(a)
just_moved = false
dir = a
if a == "u" then newy = y-8
elseif a == "d" then newy = y+8
elseif a == "l" then newx = x-8
elseif a == "r" then newx = x+8
end
if move_possible() then
move_do()
check_current_cell()
else -- hit a wall
if play_sounds then sfx(47) end
sliding = false
end
end
function move_do()
-- start a single move
-- count down moves once if not sliding
-- update new position immediately but don't draw yet
-- start animation 4210
if not sliding then move_sound() end
moving = true
dx = 0 -- temporary x offset
dy = 0 -- temporary y offset
move_step = 1
move_time = t
prevx = x
prevy = y
x = newx
y = newy
just_moved = true
if (ice or check_flag(x, y, 6)) and not sliding then
-- start slide if ice or new cell is icy
sliding = true
moves -= 1 -- only reduce moves once when on ice
mab_step()
elseif sliding and not ice and not check_flag (x, y, 6) then
-- stop sliding
sliding = false
elseif not sliding then
moves -= 1
mab_step()
end
unfog_circle()
end
function move_sound()
if not play_sounds then return end
if dir == "u" then sfx(41)
elseif dir == "d" then sfx(42)
elseif dir == "l" then sfx(43)
elseif dir == "r" then sfx(44)
end
end
function move_catch_up()
-- adds a temp offset to character based on time
if move_step >= 5 then
moving = false -- have finished move cycle
return
end
-- move_pixels shows at each move_step, how many pixels close to the new position the player should be:
if not sliding then move_pixels = {4, 2, 1, 0}
else move_pixels = {6, 4, 2, 0} end -- more linear movement on ice.
if (t - move_time) % cat_frames == 0 then
dx = move_pixels[move_step] * (prevx-x) / 8
dy = move_pixels[move_step] * (prevy-y) / 8
move_step += 1
end
end
function move_possible()
if (newx<0 or newx>120 or newy<0 or newy>120) then return false end
-- return false if 0th flag is set for target cell:
if check_flag(newx, newy, 0) then return false end -- it's a wall
return true
end
function check_flag(a, b, flag)
-- checks if flag 0-7 is set for map at pixel coordinates a, b
return fget(mget(map_data_pos[level][1] + a/8, map_data_pos[level][2] + b/8), flag)
end
function check_current_cell()
-- checks new cell for anything interesting
-- check if you've reached goal
if (level == 16 and x == 56 and y == 0) -- get mab socky
or (x == 120 and y == goal_height[level] * 8) then -- get goal
levelling_up = true
music(-1)
if play_sounds then
if level != 16 then sfx(48)
else sfx(52) end
end -- level end tune
return
end
-- check if you've reached socky
if x/8 == socky_pos[level][1] and y/8 == socky_pos[level][2] and socky_collect == false then
socky_collect = true
if play_sounds then sfx(45) end
-- reimburse extra moves it would have cost to get socky:
socky_add = max(moves_data[level][2] - moves_data[level][1] + 10, 0) -- extra temporary socky boost of 10
moves += socky_add
unfog_start()
end
-- check for moving obstacles
if obstacles[ar(y)][ar(x)] > 0 then obstacle_hit() end
-- check for static obstacles, if flag 5 is set for currrent cell:
if check_flag(x, y, 5) then obstacle_hit() end
-- check for switch
if switch_data[level][1] != 16 then check_switches() end
-- check for mab eyes
if level == 16 then check_mab_eyes() end
end
function check_switches()
-- cycle through all switches
-- landing on a switch permanently opens its door
for k in all(switch_data[level]) do
-- if coordinates match any switch_data[level][1] and [2] and open is false then
if x/8 == k[1] and y/8 == k[2] and not k[6] then
if play_sounds then sfx(49) end
switch_set(k, true)
debug_text = tostr(k[1])..","..tostr(k[2])..","..tostr(k[3])..","..tostr(k[4])..","..tostr(k[5])..","..tostr(k[6]) -- temp
end
end
end
function check_mab_eyes()
for k in all(mab_data) do
if x/8 == k[1] and y/8 == k[2] and k[5] == false then
-- activate eye
k[5] = true
mab_start(k[3], k[4])
debug_text = "mab start"
end
end
end
function switch_set(switch, to_open)
-- set switch to to_open true/false
-- switch is an array: switch x/y, door x/y, start sprite, open state
local switch_sprite_adjust = 0
if to_open then switch_sprite_adjust = 1 end
-- set switch to open/closed and update map
mset(
map_data_pos[level][1] + switch[1],
map_data_pos[level][2] + switch[2],
switch[5] + switch_sprite_adjust -- use sprite + 1 if open
)
-- set door to open/closed and update map
mset(
map_data_pos[level][1] + switch[3],
map_data_pos[level][2] + switch[4],
switch[5] + 2 + switch_sprite_adjust -- use sprite + 1 if open
)
-- set switch to open
switch[6] = to_open -- set switch/door data to open
end
function switch_reset()
-- reset all switches in current level
for k in all(switch_data[level]) do
-- if coordinates match any switch_data[level][1] and [2] and open is false then
if k[1] != 16 then switch_set(k, false) end
end
end
function show_debug_info()
rectfill(0, 0, 64, 7, level_bg[level])
print(debug_text, 0, 0, 15)
end
-- ## fog functions
function unfog_reset()
-- set fog to max value (8) across map.
-- all arrays are 1-based.
fog = {}
local h = fog_height[level]
for j=1,16 do
fog[j] = {}
for i=1,16 do
if j < h-1 then fog[j][i] = 0
-- randomise fog at the rows above fog_height:
elseif j == h-1 then fog[j][i] = flr(rnd(3)) + 2
else fog[j][i] = 8 end
end
end
end
function unfog_circle()
-- shows an area around the player defined by unfog_pattern
for j=-4,4 do
for i=-4,4 do
-- coordinates of fog placement:
local fogx = x+i*8
local fogy = y+j*8
-- don't do anything if fog position isn't in game field:
if fogx >= 0 and fogx <= 120 and fogy >= 0 and fogy <= 120 then
local unfog_amount = unfog_pattern[j+5][i+5]
-- set fog level to minimum of (current level, current - unfog amount) but keep it above 0
old_fog = fog[ar(fogy)][ar(fogx)]
fog[ar(fogy)][ar(fogx)] = max(0, min(8 - unfog_amount, old_fog))
end
end
end
end
function unfog_start()
-- initialises function to unfog the whole screen
offset = 0.125
-- show how many extra points awarded by socky
bonus_caption = ""
ice_adjust = 0
if ice then ice_adjust = 1 end
if socky_add >= 1 then
-- so that display is consistent,
-- subtract one to account for move already started
-- but add back on if on ice, as 1 point will have already been deducted at start of move
bonus_caption = " +"..tostr(socky_add - 1 + ice_adjust)
end
caption_show("socky!"..bonus_caption, 1, 12, 7)
unfog_active = true
unfog_y = fog_height[level] * 8 - 16 -- y coordinate of the start of the unfogging, which moves up-right in strips
unfog_start_time = t
end
function unfog_step()
-- gradually unfogs the whole screen from top left to bottom right
-- in strips from the left or bottom of the screen
if unfog_y == 320 then -- unfog is complete
unfog_active = false
return
end
if t % unfog_frames == 0 then
unfog_strip(0,unfog_y)
unfog_y += 8
end
end
function unfog_strip(lx, ly)
-- unfog strip from lx, ly in up-right direction, last strip starting at (0, 248)
while lx < 256 do
-- set fog to a gradually decreasing strip upwards from lx, ly
for unfog_level = 1,8 do
local ly_offset = ly - unfog_level * 8
if ly_offset >= 0 and ly_offset < 128 then
-- unfog cell is on screen:
unfog_cell(lx, ly_offset, unfog_level)
end
end
lx += 8
ly -= 8
end
end
function unfog_cell(a, b, amt)
old_fog = fog[b/8 + 1][a/8 + 1]
fog[ar(b)][ar(a)] = max(0, min(8 - amt, old_fog))
end
function obstacle_reset()
obstacles = {}
for j=1,16 do
obstacles[j] = {}
for i=1,16 do
obstacles[j][i] = 0
end
end
end
function obstacle_update()
obstacle_reset()
local step = anim_frame % level_period + 1
-- get coordinates of all obstacles from current level at current time:
obs = obs_data[level][step]
for k in all(obs) do -- k is a pair of 0-based coordinates for an obstacle
if k[2] * k[1] != 256 then -- check there is obstacle data
obstacles[k[2] + 1][k[1] + 1] = 1
-- default obstacle value = 1
end
end
end
function obstacle_hit()
offset = 0.5
moves -= 4
if just_moved == false then moves -= 1 end -- ensures score is always subtracted by 5 when obstacle hits you
caption_show("-5", 2, 8, 9)
if play_sounds then sfx(46) end
end
function caption_show(text, col1, col2, col3)
caption_text = text
cstep = ceil(#caption_text/4)
caption_colours = {col1, col2, col3}
caption_data = {}
caption_reset_data()
caption_active = true
-- data for each 8x8 character across bottom of screen with character and colour
end
function caption_reset_data()
for i=1,16 do
caption_data[i] = 16 -- reset caption data to blank
end
end
function caption_step()
-- gradually displays a caption at bottom of screen with colours expanding outwards
-- gradually unfogs the whole screen from top left to bottom right
-- in strips from the left or bottom of the screen
if cstep >= 20 then
caption_active = false
return
end
if t % caption_frames == 0 then
if cstep <= 12 then
-- cycle through caption_pattern and set colour data:
caption_reset_data()
for i=1,#caption_pattern do
local dp = 7-cstep+i -- draw position of left hand bar
if dp >= 1 and dp <= 8 then
caption_data[dp] = caption_colours[caption_pattern[i]]
-- mirror the pattern on right hand side of bar
caption_data[17-dp] = caption_colours[caption_pattern[i]]
end
end
-- remove space from bar for caption
local cells_to_clear = ceil(#caption_text/4)
if cells_to_clear > 0 then
for i=9-cells_to_clear,8+cells_to_clear do
caption_data[i] = 16
end
end
end
cstep += 1
end
end
function mab_start(a, b)
offset = 1
mab_active = true
mab_eyes_open = false
mab_hit = false
debug_text = "mab start"
mabx = a
maby = b
if play_sounds then sfx(50) end
end
function mab_step()
if not mab_active then return end
maby += 1
if maby >= 16 then
mab_active = false
debug_text = "mab inactive"
return
end
-- check if collided with pandora
local xdiff = x/8 - mabx
local ydiff = y/8 - maby
if ((ydiff == 1 or ydiff == 0) and (xdiff >= 0 and xdiff <=3)) -- at eye level
or (ydiff == 2 and (xdiff == 1 or xdiff == 2)) then -- at mouth level
debug_text = "mab hit"
mab_hit = true
end
if ((ydiff >= 0 and ydiff <= 4) and (xdiff >= 0 and xdiff <=3)) then
mab_eyes_open = true
end
end
function mab_reset()
mab_data = {
-- eye position, mab start position, open
{1, 14, 0, 0, false},
{7, 12, 6, 0, false},
{5, 7, 3, -1, false},
{8, 5, 9, 0, false},
{13, 5, 12, -2, false}
}
end
function mab_retreat_start()
mab_start_time = t
mab_small_x = 8
end
function mab_retreat_step()
-- move mab slowly across top right
if (t - mab_start_time) % 30 != 29 then return end
debug_text = "move mab"
mab_small_x += 1
rectfill(64, 0, 127, 7, 12)
map(120, 16, 8, 0, 16, 0)
draw_pandora()
spr(254, mab_small_x*8, 0)
dir="r"
move_sound()
end
-- ## draw functions
function draw_everything()
cls()
draw_level()
draw_obstacles()
draw_mab_eyes()
if mab_active then draw_mab(mabx, maby, mab_eyes_open) end
draw_fog()
draw_hints()
draw_pandora()
draw_level_start_menu()
draw_caption()
draw_moves()
draw_menu()
if debug_mode then show_debug_info() end
end
function draw_level()
rectfill(0,0,127,127,level_bg[level])
-- draw map
map(map_data_pos[level][1], map_data_pos[level][2], 0, 0, 16, 16)
-- draw socky
if socky_collect == false then
spr(28, socky_pos[level][1] * 8, socky_pos[level][2] * 8)
end
if level == 1 then spr(252, 80, 24) end
if level == 16 then
spr(27, 56, 0) -- draw mab socky
else -- draw goal
spr(24, 120, goal_height[level] * 8)
end
end
function draw_level_start_menu()
if level_start_menu == false then return end
debug_text = "level start menu"
rectfill(0, 40, 127, 87, 0)
rect(-1, 40, 128, 87, 10)
print("level "..tostr(level), 8, 48, 7)
print(level_name[level], 8, 56, 14)
print(level_hint[level], 8, 72, 8)
if level_hint_sprites[level] != "" then
draw_controls(level_hint_sprites[level], 8, 72)
end
end
function draw_controls(control, a, b)
-- draw "z/o" or "x/x" at coordinates a, b
if control == "z" then
spr(194, a, b)
spr(193, a+16, b)
elseif control == "x" then
spr(195, a, b)
spr(192, a+16, b)
end
spr(196, a+8, b)
end
function draw_obstacles()
for j=1,16 do
for i=1,16 do
if obstacles[j][i] > 0 then
spr(29, px(i), px(j))
end
end
end
end
function draw_fog()
for j=0,15 do
for i=0,15 do
if fog[j+1][i+1] > 0 then
spr(15 + fog[j+1][i+1], i*8, j*8)
end
end
end
end
function draw_pandora()
if spotlight then
circfill(x+dx+3, y+dy+3, 5, 10)
circfill(x+dx+3, y+dy+3, 4, 9)
end
local blinktime = t % 150
if (blinktime >= 120 and blinktime < 123)
or (blinktime >= 126 and blinktime < 129) then
pal(10, 0) -- make eyes black
end
if dir == "u" then spr(5 + anim_frame%2, x+dx, y+dy)
elseif dir == "d" then spr(3 + anim_frame%2, x+dx, y+dy)
elseif dir == "l" then spr(1 + anim_frame%2, x+dx, y+dy, 1, 1, true, false) -- flip r sprite
elseif dir == "r" then spr(1 + anim_frame%2, x+dx, y+dy) -- dir == "r" or default
end
reset_palette()
end
function draw_caption()
if caption_active == false then return end
for i=1,16 do
if caption_data[i] != 16 then
print("▤", px(i), 120, caption_data[i])
end
end
print3d(caption_text, 64 - #caption_text * 2, 120, 7, 0)
end
function draw_moves()
local m = tostr(moves)
rectfill(120, 0, 126, 5, level_bg[level])
print3d(tostr(moves), 128 - #m*4, 0, level_hint_colour[level], 0)
end
function draw_menu()
if menu_active == false then return end
local music_status = "on"
local sounds_status = "on"
local spotlight_status = "on"
local hint_status = "on"
if not play_music then music_status = "off" end
if not play_sounds then sounds_status = "off" end
if not spotlight then spotlight_status = "off" end
if not hints_active then hint_status = "off" end
draw_menu_outline()
draw_controls("x", 104, 16)
print("retry level", 24, 20, 8)
print("spotlight is "..spotlight_status, 24, 28, 9)
print("hints are "..hint_status.." this level", 24, 36, 10)
print("music is "..music_status, 24, 44, 11)
print("sounds are "..sounds_status, 24, 52, 12)
print("jump to level "..selected_level, 24, 60, 14)
print("close", 24, 68, 8)
spr(24, 8, 11 + menu_option * 8)
spr(25, (selected_level - 1) * 8, 104)
draw_progress()
end
function draw_menu_outline()
rectfill(0, 12, 127, 115, 0)
for i=0,15 do
spr(197, i*8, 8)
spr(198, i*8, 112)
end
end
function draw_progress()
rectfill(16, 88, 23, 95, 3) -- green bit for level 3
rectfill(48, 88, 71, 95, 12) -- blue bit for ice levels
for i=1,last_level do
spr(208, i*8 - 8, 80) -- progress bar
spr(level_sprites[i], i*8 - 8, 88) -- level sprites
spr(medal_sprite[best_medal[i]], i*8 - 8, 96) -- medals
end
rectfill(level*8 - 5, 80, 127, 87, 1) -- cut off progress bar
spr(1, level*8 - 7, 80) -- cat
end
function draw_mab_eyes(a, b)
if level != 16 then return end
for k in all(mab_data) do
local eye_sprite = 244
if k[5] == true then eye_sprite = 245 end
spr(eye_sprite, k[1]*8, k[2]*8)
end
end
function draw_mab(a, b, open)
if open then
eye_sprite_l = 237
eye_sprite_r = 238
mouth_sprite = 251
else
eye_sprite_l = 244
eye_sprite_r = 244
mouth_sprite = 250
end
spr(246, a*8, b*8)
spr(247, a*8 + 24, b*8)
rectfill(a*8, b*8+8, a*8+31, b*8+15, 7)
rectfill(a*8+8, b*8+16, a*8+23, b*8+23, 7)
spr(248, a*8, b*8+16)
spr(249, a*8+24, b*8+16)
spr(eye_sprite_l, a*8+5, b*8+9)
spr(eye_sprite_r, a*8+20, b*8+9)
spr(mouth_sprite, a*8+12, b*8+16)
end
function draw_hints()
if not hints_active then return end
-- draws a sequence of numbers guiding the player
local i = 1
for k in all(level_hints[level]) do
print3d(tostr(i), k[1]*8 + 2, k[2]*8 + 1, level_hint_colour[level], 0)
i += 1
end
end
function draw_credits()
rectfill(0, 16, 127, 111, 0)
print("pandora", 8, 24, 10)
print("by andrew hick .com", 40, 24, 9)
print("tested by:", 8, 40, 15)
print("2bitchuck alan alex clive", 8, 48, 14)
print("dan frieda iris joe", 8, 56, 8)
print("kittycat mum naomi tim", 8, 64, 11)
print("and victoria", 8, 72, 12)
spr(11, 60, 71)
print("thanks for playing :)", 8, 88, 10)
credits_active = true
end
function print3d(text, xpos, ypos, col1, col2)
print(text, xpos+1, ypos+1, col2)
print(text, xpos, ypos, col1)
end
function shake_screen()
-- code from doc robs
local fade = 0.9
local offset_x=16-rnd(32)
local offset_y=16-rnd(32)
offset_x*=offset
offset_y*=offset
camera(offset_x,offset_y)
offset*=fade
if offset<0.05 then
offset=0
end
end
function menu_open()
menu_active = true
menu_option = 1 -- current selected option
-- set menu sprite for each cell
-- allow menu to be opened and closed using button 2
caption_show("menu", 2, 8, 14)
in_game = false
end
function menu_process_input()
if btnp(⬆️) then menu_option -= 1
elseif btnp(⬇️) then menu_option += 1
elseif btnp(4) or btnp(⬅️) or btnp (➡️) then menu_choose()
elseif btnp(5) then menu_close()
end
if menu_option > menu_items then menu_option = 1 end
if menu_option <= 0 then menu_option = menu_items end
end
function menu_choose()