-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoonshot.p8
3623 lines (3139 loc) · 90.7 KB
/
moonshot.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__
--shoot for the moon
--by goncalossilva,jgradim,pkoch
---------------
---constants---
---------------
fps=60
map_width=1024
map_height=256
--downward movement per cycle
gravity=.1
--movement multiplier per cycle
inertia=.125
-------------
---sprites---
--------------
sp_player_idle=1
sp_player_run_start=2
sp_player_run_length=3
sp_player_jump=3
sp_player_glide=5
sp_spark_start=39
sp_spark_length=4
sp_platform_start=48
sp_platform_length=4
sp_door_opened=0
sp_door_closed=11
sp_screen=8
sp_button_left=9
sp_button_right=10
sp_tiny_font=128
sp_laser_h=182
sp_laser_v=186
sp_checkpoint=63
sp_hole=190
sp_ship_s=55
sp_ship_m=27
sp_ship_l=16
-----------------------
---sprite animations---
-----------------------
anim_platform=split(
"23,24,25,26"
)
anim_door_open=split(
"11,12,13,14,15,0"
)
anim_door_close=split(
"0,15,14,13,12,11"
)
anim_door_jammed=split(
"11,11,11,12,11,12"
)
anim_bolt=split(
"39,40,41,42"
)
anim_screen_warn=split(
"57,58"
)
anim_screen_ok={59}
anim_checkpoint=split(
"63,63,63,63,63,62,63,63,"..
"62,63,63,63,63,63,63"
)
anim_player_unlocker=split(
"5,1,5,1,5,1,3,1"
)
------------------
---rect sprites---
------------------
function xywh(x,y,w,h)
return {x=x,y=y,w=w,h=h}
end
rect_tooltip=xywh(
112,8,12,11
)
rect_escape_pod_l=xywh(
0,8,32,20
)
rect_escape_pod_m=xywh(
96,7,23,15
)
rect_escale_pod_s=xywh(
48,64,11,8
)
rect_laser_v_u=xywh(
96,28,5,4
)
rect_laser_v_d=xywh(
101,28,5,4
)
rect_laser_h_l=xywh(
96,23,4,5
)
rect_laser_h_r=xywh(
100,23,4,5
)
rect_title=xywh(
0,96,58,26
)
rect_moon=xywh(
96,96,32,32
)
rect_ship_s=xywh(
56,24,10,7
)
rect_ship_m=xywh(
88,8,22,14
)
rect_ship_l=xywh(
0,8,31,19
)
function ssprrect(box,dx,dy)
sspr(box.x,box.y,box.w,box.h,dx,dy)
end
-------------------
---palette swaps---
-------------------
pal_default={}
pal_button_off={
[3]=8,
[11]=14
}
pal_button_disabled={
[3]=9,
[11]=10
}
pal_checkpoint_on={
[14]=12,
[15]=13,
}
pal_checkpoint_off={
[14]=12,
[15]=12,
[12]=13,
[1]=13
}
pal_screen_blank={
[8]=1,
[10]=1,
[3]=1,
}
pal_screen_error={
[3]=1,
[10]=8,
}
pal_screen_ok={
[8]=1,
[10]=3,
}
p_colors={
red={[8]=8},
yellow={[1]=0,[12]=5,[8]=9},
blue={[8]=1,[12]=14,[6]=5},
green={[8]=3,[10]=11}
}
--------------
---messages---
--------------
msg_close_scren=
" press 🅾️/z to exit"
msg_dbljmp=
" thank you for saving me!\n"..
" let me help you,i can\n"..
" double jump!"..
"\n\n"..
" great! we can switch\n"..
" between us with ⬆️/⬇️!"
--msg_glider=
-- "check out my sweet jetpack!"..
-- "not a fire hazard"..
-- "\nor anything"..
-- "\n\n\n\n"..
-- "that's nice. don't burn"..
-- "your ankles, dearie"
-----------------
---wall labels---
-----------------
--{text,x,y,color}
wall_labels={
{
"diagnostics",
62*8+4,23*8+4,14
},
{
"lvl 1",
44*8+4,26*8+4,14
},
{
"< engine room",
15*8,29*8+2,14
},
{
"< lab",
38*8,20*8
},
{
"escape pods >",
50*8+4,11*8+4
},
{
"thank you for playing",
61*8+4,14*8+2
},
}
-----------------------
---credits formation---
-----------------------
credits_formation={
[1]={
-rect_ship_l.w-16,
64-rect_ship_l.h/2
},
[2]={
(-rect_ship_l.w-16)*2,
64-rect_ship_l.h/2-32
},
[3]={
(-rect_ship_l.w-16)*2,
64-rect_ship_l.h/2+32
},
[4]={
(-rect_ship_l.w-16)*3,
64-rect_ship_l.h/2
}
}
------------------
---sprite flags---
------------------
--obstacles that are rigid and
--block in all directions
flag_block=0
--obstacles that move the player
--to the last checkpoint
flag_spawn=1
---------------------
---custom hitboxes---
---------------------
--[sprite]={{x,y,w,h},(...)}
custom_hitboxes={
-------------------
---interactables---
-------------------
--doors
"11|1,0,6,8",
"12|1,0,6,8",
"13|1,0,6,8",
"14|1,0,6,8",
--moving platforms
"23|0,0,8,3",
"24|0,0,8,3",
"25|0,0,8,3",
"26|0,0,8,3",
--horizontal lasers
"182|0,1,8,3",
"183|0,1,8,3;8,1,8,3",
"184|0,1,8,3;8,1,8,3;16,1,8,3",
"185|0,1,8,3;8,1,8,3;16,1,8,3;24,1,8,3",
--vertical lasers
"186|1,0,3,8",
"187|1,0,3,8;1,8,3,8",
"188|1,0,3,8;1,8,3,8;1,16,3,8",
"189|1,0,3,8;1,8,3,8;1,16,3,8;1,24,3,8",
--pressure plates
"20|0,0,8,2",
"36|0,0,8,2",
--sparks
"52|2,2,4,4",
---------------
---map tiles---
---------------
--left endpiece
"112|1,0,7,6;0,1,8,4",
"180|1,0,7,6;0,1,8,4",
--right endpiece
"113|0,0,7,6;0,1,8,4",
"181|0,0,7,6;0,1,8,4",
--top endpiece
"97|2,1,4,7;1,2,6,6",
--bottom endpiece
"96|1,0,6,6;2,0,4,7",
--walls
"80|1,0,6,8",
"83|1,0,6,8",
"84|1,0,6,8",
"85|1,0,6,8",
"86|1,0,6,8",
"101|1,0,6,8",
"102|1,0,6,8",
"117|1,0,6,8",
"118|1,0,6,8",
"162|1,0,6,8",
"163|1,0,6,8",
--top left corner
"98]2,0,6,6;1,1,6,7",
"130|2,0,6,6;1,1,6,7",
"132|2,0,6,6;1,1,6,7",
--top right corner
"99|0,0,6,6;1,1,6,7",
"131|0,0,6,6;1,1,6,7",
"133|0,0,6,6;1,1,6,7",
--bottom left corner
"114|1,0,7,5;2,0,6,6",
"146|1,0,7,5;2,0,6,6",
"148|1,0,7,5;2,0,6,6",
--bottom right corner
"115|0,0,7,5;0,0,6,6",
"147|0,0,7,5;0,0,6,6",
"149|0,0,7,5;0,0,6,6",
--floor
"64|0,0,8,6",
"66|0,0,8,6",
"67|0,0,8,6",
"68|0,0,8,6",
"69|0,0,8,6",
"70|0,0,8,6",
"164|0,0,8,6",
"165|0,0,8,6",
--reverse "t" shape
"66|0,0,8,6",
"165|0,0,8,6",
--"t" shape
"65|0,0,8,6;1,0,6,8",
"176|0,0,8,6;1,0,6,8",
"177|0,0,8,6;1,0,6,8",
--branch left
"81|0,0,7,6;1,0,6,8",
"100|0,0,7,6;1,0,6,8",
"179|0,0,7,6;1,0,6,8",
--branch right
"82|1,0,6,8;1,0,7,6",
"116|1,0,6,8;1,0,7,6",
"178|1,0,6,8;1,0,7,6",
--broken endpiece left
"172|4,0,4,6",
"174|4,0,4,6",
--broken endpiece right
"173|0,0,5,6",
"175|0,0,5,6",
}
------------------
---map elements---
------------------
function init_mechanics()
---------------
--diagnostics--
---------------
--cosmetics
local diag_jammed_door=
init_animated({
x=68*8,
y=29*8,
w=8,
h=8,
anim=anim_door_jammed,
anim_freq=6,
collide=block,
})
local diag_screen_warn=
init_animated({
x=62*8,
y=29*8,
anim=anim_screen_warn,
anim_freq=8,
})
--doors
local diag_door=
init_door(
56*8,28*8,false
)
--platforms
local diag_plt=
init_platform(
60*8,26*8,
60*8,28*8,
false
)
--buttons
local diag_door_btn=init_button(
sp_button_right,67*8,25*8,
false,false,
function(b)
toggle_door(diag_door,b.active)
end
)
local diag_plt_btn=init_button(
sp_button_left, 58*8,29*8,
true,false,
function()
play_sfx("platform_on")
diag_screen_warn.anim=
anim_screen_ok
diag_plt.moving_since=t()
end
)
--screens
local diag_screen_high=
init_interactable({
sp=sp_screen,
x=65*8,
y=25*8,
tooltip="🅾️",
msg=
"> status report:\n\n"..
"-heavy damage to hull\n"..
"-remaining crew: 3\n"..
"-escape pods: 4\n"..
"-disabled platforms: 5\n"..
"-shocking hazards\n\n"..
"objective: open door\n"..
"objective: rescue crew\n"..
"objective: escape to moon\n\n"..
msg_close_scren,
})
-------------------
--broken corridor--
-------------------
local shaft_l1_plt=
init_platform(
47*8,22*8,
47*8,28*8,
false
)
local shaft_l1_btn=init_button(
sp_button_right,42*8,25*8,
true,false,function()
play_sfx("platform_on")
shaft_l1_plt.moving_since=t()
end
)
local shaft_l2_plt=
init_platform(
45*8,13*8,
45*8,21*8,
false
)
local shaft_l2_btn=init_button(
sp_button_right,42*8,15*8,
true,false,function()
play_sfx("platform_on")
shaft_l2_plt.moving_since=t()
end
)
local shaft_l2_laser=
init_laser(
{41*8+2,12*8+1},{41*8+2,12*8+1},
"v",4
)
local shaft_l2_screen=
init_animated({
x=38*8,
y=18*8,
anim=anim_screen_ok,
anim_freq=8,
})
--------------------------
---double jumper unlock---
--------------------------
dbljmp_plt=init_platform(
9*8,16*8,
9*8,26*8,
true
)
dbljmp_door=
init_door(
6*8,18*8,false
)
dbljump_btn=
init_interactable({
sp=sp_button_left,
sp_pal=pal_button_off,
x=7*8,
y=15*8,
tooltip="🅾️",
active=false,
on_button_press=function(b)
b.tooltip=nil
b.active=not b.active
b.sp_pal=b.active
and pal_default
or pal_button_off
toggle_door(
dbljmp_door,
b.active
)
end,
})
dbljmp_player_unlock=
init_player_unlocker(
3,18,
msg_dbljmp,
"yellow",double_jump
)
---------
---lab---
---------
local lab_door=init_door(
33*8,21*8,false
)
local lab_press_plate=
init_press_plate(
36*8,22*8,true,
function(p)
toggle_door(lab_door,p.pressed)
end
)
local lab_shaft_laser_btn=
init_button(
sp_button_left,42*8,9*8,
false,true,function(b)
shaft_l2_laser.on=
b.active
shaft_l2_screen.anim=
anim_screen_warn
end
)
local lab_laser_l_1=init_laser({25*8,17*8+1},{25*8,17*8+1},"v",4,function(l) l.on=t()%4>=1 end)
local lab_laser_l_2=init_laser({21*8,17*8+1},{21*8,17*8+1},"v",4,function(l) l.on=t()%4<=2 end)
local lab_laser_l_3=init_laser({17*8,17*8+1},{17*8,17*8+1},"v",4,function(l) l.on=t()%4>=1 end)
local lab_plt=
init_platform(
12*8,13*8,
12*8,19*8,
true
)
local lab_laser_h_1=init_laser({27*8,12*8+1},{27*8,12*8+1},"v",4,function(l) l.on=t()%4<=2 end)
local lab_laser_h_2=init_laser({22*8,12*8+1},{22*8,12*8+1},"v",4,function(l) l.on=t()%4>=1 end)
local lab_laser_h_3=init_laser({17*8,12*8+1},{17*8,12*8+1},"v",4,function(l) l.on=t()%4<=2 end)
---------
---end---
---------
local end_screen=
init_interactable({
sp=sp_screen,
x=83*8,
y=14*8,
tooltip="🅾️",
msg=
"\n"..
" congratulations!\n\n"..
"thank you for playing\n"..
"shoot for the moon, our\n"..
"entry in\n"..
"github's game off 2020\n\n"..
"it is unfinished, but we\n"..
"hope you enjoyed it!\n\n\n"..
msg_close_scren,
on_msg_end=function(s)
players[1].saved=true
players[2].saved=true
set_scene(scene_credits)
end,
})
-------------------
---glider unlock---
-------------------
--glider_player_unlock=
-- init_player_unlocker(
-- 0,0,
-- msg_glider,
-- "green",glide
-- )
------------------------
---hover boots unlock---
------------------------
return {
--checkpoints
init_checkpoint(45,29),
init_checkpoint(1,18),
init_checkpoint(14,20),
-- dianostics
diag_jammed_door,
diag_screen_warn,
diag_screen_high,
diag_door,
diag_door_btn,
diag_plt,
diag_plt_btn,
--shaft
shaft_l1_plt,
shaft_l1_btn,
shaft_l2_plt,
shaft_l2_btn,
shaft_l2_laser,
shaft_l2_screen,
-- corridor
corridor_btn,
-- double jumper
dbljmp_plt,
dbljmp_door,
dbljump_btn,
dbljmp_player_unlock,
-- lab
lab_door,
lab_press_plate,
lab_shaft_laser_btn,
lab_laser_l_1,
lab_laser_l_2,
lab_laser_l_3,
lab_plt,
lab_laser_h_1,
lab_laser_h_2,
lab_laser_h_3,
lab_p,
-- end
end_screen,
}
end
-->8
--scenes,loop,camera,utils
----------
---loop---
----------
function set_scene(s)
_update60=s.update
_draw=s.draw
s.init()
end
function _init()
--starting scene
set_scene(scene_title)
end
-----------------
---title scene---
-----------------
start_game_at=nil
repeat_music_at=nil
scene_title={
init=function()
start_game_at=nil
--background fx
add_bg_fxs()
--music
music(0,5000)
repeat_music_at=t()+17
end,
update=function()
--handle input
if btnp(❎) then
if not start_game_at then
--crossfade scenes and start
play_sfx("start_game")
start_game_at=t()+1
music(-1)
else
--start immediately
start_game_at-=2
end
end
--fxs
foreach(bg_particles,update)
update_fxs()
--start game when ready
if start_game_at
and t()>=start_game_at
then
set_scene(scene_game)
end
--music
if repeat_music_at<=t() then
music(0)
repeat_music_at=t()+17
end
end,
draw=function()
cls()
pal()
--fxs
foreach(bg_particles,draw)
draw_fxs()
--top left title
ssprrect(rect_title, 8,8)
--center text
local txt=
"press ❎/x to play"
print(
txt,hcenter(txt),72,
time()%0.4<0.2 and 7 or 10
)
--bottom commands
print_footer(
"⬅️➡️:run ❎/x:jump 🅾️/z:use "
)
--fade out if starting game
if start_game_at then
fadepal(1-(start_game_at-t()),1)
end
end,
}
----------------
---game scene---
----------------
players={}
scene_game={
init=function()
--btnp never repeats
poke(0x5f5c,255)
set_checkpoint(65*8,28*8)
--players
players={
init_player{
🅾️=jump,
color="red",
x=65*8,-- diagnostics
y=28*8,
--x=7*8, -- dbljump
--y=14*8,
--x=48*8, -- shaft
--y=29*8,
--x=40*8, -- lab
--y=9*8,
--x=82*8, -- end
--y=14*8,
},
}
--background fx and thrusters
add_bg_fxs()
thruster:add(1,22.5)
thruster:add(1,8.5)
--mechanics
mcns=init_mechanics()
--camera
cam:move(player(),true)
end,
update=function()
--input
local p=player()
if player_input then
player_btns={[0]="⬅️",[1]="➡️",[5]="❎"}
for n, b in pairs(player_btns) do
if btn(n) then
fn=p[b]
if (fn) fn(p,btnp(n))
end
end
if btnp(⬆️) then
focus_next_player()
end
if btnp(⬇️) then
focus_prev_player()
end
end
--players
--path:update()
foreach(players,update)
--mechanics
foreach(mcns,update)
--fxs
fire_fxs()
foreach(bg_particles,update)
update_fxs()
--camera
cam:move(p)
end,
draw=function()
cls()
pal()
--fxs
foreach(bg_particles, draw)
animate_map()
map(0,0)
draw_fxs()
--tiny text
for wl in all(wall_labels) do
print_tiny(
wl[1],wl[2],wl[3],wl[4]
)
end
--mechanics
foreach(mcns,draw)
--players
foreach(players,draw)
--modals from interactables
foreach(mcns,function(m)
if m.draw_modal then
m:draw_modal()
end
end)
--camera
cam:draw()
--start game fade-in effect
if start_game_at
and start_game_at+1>t() then
fadepal(1-(t()-start_game_at),1)
end
end,
}
-------------------
---credits scene---
-------------------
saved_players={}
show_credits_at=nil
scene_credits={
init=function()
show_credits_at=nil
--reset draw state
pal()
--gather saved players
saved_players={}
local i=1
for p in all(players) do
if p.saved then
add(
saved_players,
instance(p,{
x=credits_formation[i][1],
y=credits_formation[i][2],
dx=0.25,
})
)
i+=1
end
end
--background fx
add_bg_fxs()
end,
update=function()
--handle input
if btnp(❎) then
set_scene(scene_title)
return
end
--fxs
foreach(bg_particles,update)
update_fxs()
--player ships
for i,p in ipairs(saved_players) do
p.x+=p.dx
if p.x>(32-i*8) then
p.dx+=rnd(0.3)
end
end
--reset camera
cam:move()
end,
draw=function()
cls()
pal()
cam:draw()
--fxs
foreach(bg_particles,draw)
draw_fxs()