-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpilot8.lua
More file actions
2647 lines (2442 loc) · 62.1 KB
/
pilot8.lua
File metadata and controls
2647 lines (2442 loc) · 62.1 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
---------------------------------------------------
-- pilot 8
-- a simple spaceship game for pico8.
--
-- copyright (c) 2018 bruno oliveira
-- all rights reserved
---------------------------------------------------
#define k_version "v1.1"
#define k_start_lvl 1
#define k_start_coins 0
#define k_debug_allow_kill_all true
-- clip rect shape (width and height) when drawing
-- lit portion of level (this rect is centered on
-- the player).
local k_lit_clip_r={x=-25,y=-30,w=95,h=60}
-- by how much to translate the rect if player is
-- facing left instead of right
#define k_lit_clip_xleft -40
-- lighting falloff. the bigger this number, the
-- smaller the lit area will be around the player
#define k_light_falloff 0.005
-- eccentricity of the lit area (to give it a more
-- oval shape). this hack is too ugly to describe
-- in words, see postproc_light() for how these numbers
-- are haphazardly used
#define k_light_ecc 0.4 -- 1=circle, smaller is more oval
#define k_light_ecc_cutoff 30
-- how long entities remain in the "damaged" state
-- after taking damage
#define k_dmg_dur 3
-- x coordinate where we spawn entities
#define k_spawn_x 128 -- just off the screen
-- y coordinate of water surface
#define k_water_y 96
-- player bounds
#define k_plr_min_x 0
#define k_plr_max_x 120
#define k_plr_min_y 0
#define k_plr_max_y k_water_y-8
-- pre-generated pseudo random numbers for some
-- effects that need stability
local k_rnd=nil
-- interval between executing successive level seq
-- commands
#define k_cmd_int 30
-- how long the player remains in "hurt" mode
#define k_plr_hurt_dur 40
-- maximum shield player can have
#define k_shield_max 3
-- minimum interval between enemy loot drops
-- (without and with the "more powerups" upgrade)
local k_drop_int={300,200}
-- duration of the level title display in seconds
#define k_title_dur_sec 4
-- duration of the "end of level" state, in ticks.
#define k_end_lvl_dur 100
-- zigzag min/max y for enemy zigzagging behavior
#define k_zigzag_min_y 0
#define k_zigzag_max_y 88
-- maximum # of enemy projectiles on the screen
#define k_max_en_projs 8
-- game modes
#define k_mode_title 0
#define k_mode_play 1
#define k_mode_dying 2
#define k_mode_hangar 3
#define k_mode_shop 4
#define k_mode_map 5
#define k_mode_stats 6
#define k_mode_win 7
-- sprites
#define k_sp_plr 3
#define k_sp_hlaser_l 2 -- long laser
#define k_sp_hlaser_s 9 -- short laser
#define k_sp_en_alpha 7
#define k_sp_kaboom 12
#define k_sp_en_boat 22
#define k_sp_fireball 24
#define k_sp_en_beta 10
#define k_sp_weap_laser 17
#define k_sp_weap_dbl 18
#define k_sp_dbl 38 -- double laser
#define k_sp_infty 19
#define k_sp_shield 39
#define k_sp_plr_w_shield 41
#define k_sp_en_gamma 20
#define k_sp_coin 1
#define k_sp_lvl_done 71
#define k_sp_en_spiky 21
#define k_sp_en_delta 43
#define k_sp_weap_mach 47
#define k_sp_lvl_start_mark 113 -- level start mark
-- entity ids that don't correspond to sprites
-- these must be >1000 to avoid conflict with sprites
#define k_eid_plr_laser 1000 -- player laser
#define k_eid_en_laser 1001 -- enemy laser
#define k_eid_mach_laser 1002 -- mach weapon laser
-- meta sprite with value 0. meta sprites indicate
-- numeric data in map rom (like level commands).
-- these are not sprites for display.
#define k_sp_meta0 48
-- collision rectangles
local k_cr_full={x=0,y=0,w=8,h=8}
local k_cr_plr={x=2,y=2,w=6,h=6}
local k_cr_ship={x=2,y=2,w=6,h=6}
local k_cr_hbar={x=2,y=3,w=6,h=2}
local k_cr_hbar_s={x=3,y=3,w=2,h=1}
local k_cr_dbl={x=1,y=2,w=6,h=3}
local k_cr_ball={x=3,y=3,w=2,h=2}
local k_cr_ball4={x=2,y=2,w=4,h=4}
local k_cr_pwup={x=0,y=0,w=8,h=7}
-- sfx
#define k_sfx_fire 10
#define k_sfx_hurt 11
#define k_sfx_kill 12
#define k_sfx_die 13
#define k_sfx_dbl 15
#define k_sfx_pwup 16
#define k_sfx_shield 17
#define k_sfx_lose_shield 18
#define k_sfx_coin 19
-- music
#define k_mus_play_1 0
#define k_mus_title 5
#define k_mus_hangar 7
#define k_mus_die 10
#define k_mus_win 11
#define k_mus_end_level 13
-- buttons
#define k_btn_left 0
#define k_btn_right 1
#define k_btn_up 2
#define k_btn_down 3
#define k_btn_o 4
#define k_btn_x 5
-- music for each mode
-- if not specified, previous music will continue
local k_mus_for_mode={
[k_mode_title]=k_mus_title,
[k_mode_play]=k_mus_play_1,
[k_mode_hangar]=k_mus_hangar,
[k_mode_dying]=k_mus_die,
[k_mode_win]=k_mus_win,
}
-- music that's currently playing
local g_mus=-1
-- probability schedule for enemy powerup drops
-- each entry has equal probability
local k_drop_sched={
k_sp_weap_dbl,
k_sp_shield,
k_sp_weap_mach,
0,
}
-- character colors for hint bar at bottom of screen
local k_hint_char_color={
["\139"]=12,["\145"]=12,["\148"]=12,["\131"]=12,
["\142"]=11,["\151"]=8
}
-- screen transition offsets
local k_scrt_seq={11,7,5,3,2,1}
-- screen transition counter, nil means not doing
-- transition
local g_scrt=nil
-- luminosity mapping table.
-- for each light lvl (1,2,3), g_lum[l][b] maps input
-- byte b (pair of pixels) to an output byte b (pair of
-- pixels) of lit pixels. light level 0 is not stored,
-- as it just maps to 0. light level 4 (max) is not
-- stored, as it maps to itself.
local g_lum=nil
-- animations
-- div: divisor for frame rate
-- fr: sequence of sprites
-- flip: sequence of flips (0=no flip, 1=flip x)
-- loop: true if loops, false or nil if not
-- (default false)
local k_anim_die={div=6,fr={12,13,14,15,16,0}}
local k_anim_beacon={div=10,fr={0,30,31},loop=true}
local k_anim_spiky={div=4,fr={26,27},loop=true}
local k_anim_fireball=
{div=2,fr={24,24},flip={0,1},loop=true}
local k_anim_torch={div=8,fr={122,123,123},loop=true}
local k_anim_lantern={div=8,fr={84,100,116},loop=true}
local k_anim_muzzle={div=2,fr={87,88,103,104},loop=false}
-- height of level data in map rom, in cells
#define k_lvl_rom_h 6
-- level templates (see below for the meaning of
-- each field)
local k_lvl_templ_flood={
title="flood city",
bgc=112,bgr=48,bgh=12,
thc=116,thr=29,
cclr=0,
lit=true,
em={
{anim=k_anim_beacon,x=0,y=88,cmap={[3]=2,[11]=8}},
{anim=k_anim_beacon,x=32,y=88,cmap={[3]=4,[11]=9}},
{anim=k_anim_beacon,x=88,y=88},
},
rip_clrs=0x11,
max_enemies=3,
}
local k_lvl_templ_oasis={
title="oasis city",
lit=false,
cclr=1,
bgc=64,bgr=48,bgh=12,
thc=116,thr=26,
skfx={{sx=0,sy=72,c=64,r=61,w=16,h=3}},
sun={x=64,y=134,r=48,clr=15},
rip_clrs=0xdd,
max_enemies=4,
}
local k_lvl_templ_marshes={
title="marshes",
lit=true,
cclr=0,
bgc=32,bgr=48,bgh=12,
thc=116,thr=23,
rip_clrs=0x00,
em={
{anim=k_anim_lantern,x=8,y=88},
{anim=k_anim_lantern,x=48,y=88},
{anim=k_anim_lantern,x=96,y=88},
},
rain=1,
max_enemies=5,
}
local k_lvl_templ_coast={
title="coast",
lit=false,
cclr=0,
bgc=16,bgr=54,bgh=6,bgy=48,
thc=104,thr=29,
rip_clrs=0x11,
skfx={
{sx=0,sy=48,c=16,r=48,w=16,h=6},
{sx=0,sy=0,c=16,r=61,w=16,h=3},
},
sun={x=64,y=114,r=32,clr=7},
-- beach effect
owfx={sx=0,sy=96,c=16,r=60,w=16,h=1},
max_enemies=5,
}
local k_lvl_templ_canals={
title="canals",
lit=true,
cclr=0,
bgc=0,bgr=48,bgh=12,
thc=104,thr=26,
rip_clrs=0x11,
em={
{anim=k_anim_torch,x=8,y=88},
{anim=k_anim_torch,x=4*8,y=88},
{anim=k_anim_torch,x=7*8,y=88},
{anim=k_anim_torch,x=9*8,y=88},
{anim=k_anim_torch,x=12*8,y=88},
{anim=k_anim_torch,x=13*8,y=88},
},
max_enemies=6,
}
local k_lvl_templ_castle={
title="castle",
lit=true,
cclr=0,
bgc=48,bgr=48,bgh=12,
thc=104,thr=23,
rip_clrs=0x00,
em={
{anim=k_anim_torch,x=8,y=88},
{anim=k_anim_torch,x=40,y=88},
{anim=k_anim_torch,x=56,y=88},
{anim=k_anim_torch,x=88,y=88},
},
max_enemies=7,
}
-- game level definitions.
-- each level has:
-- lit: if true, uses lit mode, if false level
-- if fully lit
-- mc0,mr0: the col/row in map rom where level data
-- begins (this is filled in at runtime)
-- bgc,bgr: col/row of background in map rom
-- bgh: height of background in map tiles
-- thc,thr: col/row of the briefing screen thumbnail
-- for this level.
-- skfx: if not nil, specifies the sky to draw
-- {c,r,w,h,sx,sy} - where to copy from map rom
-- and where to draw on screen (sx,sy)
-- cclr: clear color
-- sun{x,y,rad,clr}: a circle to draw
-- em: (emissive overlays): emissive sprites/anims
-- each is {sp=...,x=..,y=..} or {anim=...,x=..,y=..}
-- title: level title
-- subt: level subtitle
-- mapc,mapr: location on world map (in tiles)
-- rip_clrs: water ripple colors (as a byte
-- with two colors)
-- max_enemies: maximum # of enemies on screen
--
-- how level data is represented:
-- the level starts at a level start mark
-- (k_sp_lvl_start_mark) in map rom. the start mark
-- has the level # it represents right below it
-- using meta sprites. that's the base-cell of the
-- level (mc0,mr0). Each column of k_lvl_rom_h tiles
-- starting at mc0,mr0 represents a 'level command',
-- which are executed in sequence. the top of each
-- column can have a command number, which by default
-- (if missing) is 0x00, meaning 'spawn these enemies'.
-- the level ends at the 'end level' command (0xff).
--
-- for ease of representation, each level can have a
-- template (the templ field) which has common fields
-- that are the same for many levels.
local g_lvls={
-- level 1.
{
templ=k_lvl_templ_flood,
mapc=1,mapr=4,
text="know how to fly? no? well, \nwhat better way to learn than\non a real mission with real \nenemies? good luck! ",
},
-- level 2.
{
templ=k_lvl_templ_flood,
mapc=3,mapr=4,
rain=1,
text="congratulations on not dying.\nyou exceeded our expectations\nplease continue with your \ncurrent strategy of not dying",
},
-- level 3
{
templ=k_lvl_templ_flood,
mapc=5,mapr=4,
text="bob left the gates open last \nnight and enemies returned to\nthe area. bob says sorry.",
},
-- level 4
{
templ=k_lvl_templ_oasis,
mapc=8,mapr=3,
text="the oasis area has strategic \nsignificance to us. we don't \nknow why yet. but go reclaim \nit anyway. use sunscreen. ",
},
-- level 5
{
templ=k_lvl_templ_oasis,
mapc=10,mapr=3,
text="stellar performance! great...\noh? you are pilot 8, not 9. \nsorry, nevermind. how awkward\noff you go. good luck. ",
},
-- level 6
{
templ=k_lvl_templ_oasis,
mapc=12,mapr=3,
text="leadership accepted a statue \nof a horse as a gift from the\nenemy. in an unrelated event,\nsomehow the enemies got in. ",
},
-- level 7
{
templ=k_lvl_templ_marshes,
mapc=1,mapr=8,
rain=1,
text="it's a great night to stay by\nthe fireplace. so leadership \nwill stay by the fireplace \nwhile you go do the work. ",
},
-- level 8
{
templ=k_lvl_templ_marshes,
mapc=3,mapr=8,
text="bad news: the cheap defenses \nwe set up were not waterproof\nso the enemies are back. go \nreclaim the area for us. ",
},
-- level 9
{
templ=k_lvl_templ_marshes,
mapc=5,mapr=8,
text="the last pilot was supposed \nto reclaim this area but got \nrecruited by a startup and \nleft. it's up to you now. ",
},
-- level 10
{
templ=k_lvl_templ_coast,
mapc=10,mapr=9,
text="the pilot we hired turned out\nto be a werewolf so he can't \nfly under a full moon. so \nyou will have to go instead. ",
},
-- level 11
{
templ=k_lvl_templ_coast,
mapc=12,mapr=9,
text="bob sent an email to the \nwrong mailing list and gave \naway our coordinates, so the \nenemies found us. thanks bob.",
},
-- level 12
{
templ=k_lvl_templ_coast,
mapc=14,mapr=9,
text="the ideal vacation spot! \nthe beach, the waves, .... \nexcept there are a bunch of \nenemies, so take care of that",
},
-- level 13
{
templ=k_lvl_templ_canals,
text="we needed the area due to its\ncanals, but remembered we're \na spacefaring society with no\nuse for canals. get it anyway",
mapc=2,mapr=13,
},
-- level 14
{
templ=k_lvl_templ_canals,
mapc=4,mapr=13,
rain=1,
text="we mistook ourselves for the \nenemy so we left the area to \nclear it of enemies. then the\nreal enemies took it from us.",
},
-- level 15
{
templ=k_lvl_templ_canals,
mapc=6,mapr=13,
text="alex set the alarm to 7pm not\n7am so we overslept and lost \nthe area to enemies. they are\nvery punctual, unlike alex. ",
},
-- level 16
{
templ=k_lvl_templ_castle,
mapc=9,mapr=13,
text="leadership wants a castle in \norder to fortify our defenses\nit worked in the middle ages \nso it seems like a good idea.",
},
-- level 17
{
templ=k_lvl_templ_castle,
mapc=11,mapr=13,
text="because they are all spelled \nsimilarly, leadership has \ninvaded the wrong casle. now \ngo conquer the right one. ",
},
-- level 18
{
templ=k_lvl_templ_castle,
mapc=13,mapr=13,
rain=1,
text="okay, that wasn't the right \ncastle either but this time \nwe are really sure. last one!\ngood luck, pilot 8! ",
},
}
-- player weapons
#define k_weap_laser 0 -- default boring weapon
#define k_weap_dbl 1 -- double laser
#define k_weap_mach 2 -- mach weapon (fast shots)
-- info for each weapon
-- init_ammo: initial ammo, -1 means infinite
-- for each possible upgrade level: 0,1,2,3.
-- shot_eid: eid of the shot entity
-- off_x: {l,r} where l is the x offset of
-- the shot entity when shooting left,
-- and r is the offset of the shot entity when
-- shooting right.
-- off_y: y offset of shot entity.
-- sfx: sound to play when shooting
-- hud_icon: icon to use for the hud
-- clr: dominant color (for text effects)
-- fire_cds: interval between shots (ticks),
-- for each possible upgrade level: 0,1,2,3.
local k_weap_info={
[k_weap_laser]={
init_ammo={-1,-1,-1},
shot_eid=k_eid_plr_laser,
off_x={-6,6},off_y=0,
sfx=k_sfx_fire,
fire_cds={12,9,6},
hud_icon=k_sp_weap_laser,
clr=12,
},
[k_weap_dbl]={
init_ammo={5,7,10},
shot_eid=k_sp_dbl,
off_x={-6,6},off_y=0,
sfx=k_sfx_dbl,
fire_cds={20,15,10},
hud_icon=k_sp_weap_dbl,
clr=11,
},
[k_weap_mach]={
init_ammo={50,60,70},
shot_eid=k_eid_mach_laser,
off_x={-6,6},off_y=0,
sfx=k_sfx_dbl,
fire_cds={5,4,3},
hud_icon=k_sp_weap_mach,
clr=14,
},
}
-- current game mode.
local g_mode=k_mode_title
-- mode clock (this counts in "seconds",
-- approximately). resets when the mode changes
local g_clk_sec=0 -- clock in "seconds"
local g_clk=0 -- clock in ticks since mode change
local g_aclk=0 -- clock in ticks since start
-- persistent save data. this is saved and loaded
-- to persistent memory (player progression)
--
-- attention: all data in g_sav must be saved/loaded
-- by load_data() and save_data(). update those
-- functions when adding/removing fields from
-- g_sav.
local g_sav=nil
local g_sav_templ={ -- copied to g_sav
lvl=k_start_lvl, -- next level to play
coins=k_start_coins, -- coins
-- purchased upgrades (bit flags)
-- combination of bit flags k_upf_*
upgrades=0,
-- stats:
coins_collected=0,
coins_spent=0,
enemies_killed=0,
levels_played=0,
deaths=0,
powerups_collected=0,
-- this accumulates fractions during gameplay,
-- but only the integer part is serialized.
gameplay_minutes=0,
}
-- transient game state. this gets wiped every time
-- we play a level.
local g=nil -- copied from k_g_template
local k_g_template={
-- level number
lvl_no=-1, -- initialized later
-- convenience pointer, equiv to g_lvls[g.lvl_no]
lvl=nil, -- initialized later
-- countdown to execute next level command
cmd_cd=0,
-- index of the next command to execute
-- starts at 0 (0th column of level)
next_cmd=0,
-- copy of last g_clk value for play mode (needed
-- because when we switch to "paused" states like
-- k_mode_dying we lose g_clk and need it for
-- drawing.
play_clk=0,
-- clip rectangle of the lit area. updated every
-- frame.
lit_clip={x=0,y=0,w=0,h=0},
-- countdown for next enemy loot drop
drop_cd=k_drop_int[1],
-- player state:
x=10,y=40, -- position
vx=0,vy=0, -- velocity
facing=1, -- facing direction 1=right, -1=left
-- translated collision rectangle, computed
-- after moving the player each frame
xcr=nil,
-- countdown to being ready to fire next shot
fire_cd=0,
-- current weapon
weap=k_weap_laser,
weap_info=k_weap_info[k_weap_laser],
ammo=-1, -- -1 = infinite
-- amount of shield
shield=0,
-- count down to end shield animation
shield_anim_cd=0,
-- if >0 player has just taken damage (lost
-- shield), and this is the count down to end
-- the effect
hurt_cd=0,
-- entities. see k_e_template below.
ents={},
-- number of active enemies, updated every frame
num_enemies=0,
-- number of active powerups, updated every frame
num_pwups=0,
-- number of active enemy projectiles, updated every
-- frame
num_en_projs=0,
-- if this is not nil, we are in "level ended"
-- mode and this is the countdown
end_cd=nil,
-- muzzle flash animation cycle counter, nil means
-- not currently playing
muzzle_cc=nil,
}
-- color map for the damage state (map all to white)
local k_dmg_cmap={}
for i=1,7 do add(k_dmg_cmap,7) end
-- upgrade shop sub-modes
#define k_shop_mode_normal 0 -- displaying list
#define k_shop_mode_buy 1 -- offering to buy
#define k_shop_mode_sorry 2 -- saying "no funds, sorry"
#define k_shop_mode_bought 3 -- just bought it
-- state for the several screens
local g_sstate={
-- currently selected menu item, for the modes that
-- have this
sel=1,
-- map screen
map={
-- currently selected level
sel_lvl=nil,
-- showing confirmation prompt?
prompt=false,
},
-- shop screen
shop={
mode=k_shop_mode_normal,
scr_y=0, -- scroll Y pos
-- list of available upgrades -- computed when
-- entering the shop, each is a reference to
-- an entry of k_upgrade_entries
avail=nil,
}
}
-- height of each upgrade shop item on the screen
#define k_shop_item_h 24
-- coin drop probability
#define k_coin_prob 0.5
-- possible upgrade (bit flags)
--#define k_upf_speed 0x0001 DEPRECATED
#define k_upf_rapid_fire_1 0x0002
#define k_upf_rapid_fire_2 0x0004
--#define k_upf_rapid_fire_3 0x0008 DEPRECATED
#define k_upf_ammo_1 0x0010
#define k_upf_ammo_2 0x0020
--#define k_upf_ammo_3 0x0040 DEPRECATED
#define k_upf_shield_1 0x0080
#define k_upf_shield_2 0x0100
#define k_upf_shield_3 0x0200
#define k_upf_start_dbl 0x0400
#define k_upf_pwup_int 0x0800
-- list of upgrades as they appear in the upgrade
-- shop screen
-- upf: the upgrade flag
-- title: the title of the upgrade
-- desc: description
-- price: price in coins
-- dep: if not nil, this upgrade will only be
-- offered when this other upgrade has already
-- been purchased.
local k_upgrade_entries={
{
upf=k_upf_rapid_fire_1,
title="rapid fire i",
desc="faster lasers",
price=10,
},
{
upf=k_upf_rapid_fire_2,
title="rapid fire ii",
desc="even faster lasers",
price=20,
dep=k_upf_rapid_fire_1,
},
{
upf=k_upf_ammo_1,
title="ammo i",
desc="increased ammo",
price=10,
},
{
upf=k_upf_ammo_2,
title="ammo ii",
desc="even more ammo",
price=20,
dep=k_upf_ammo_1,
},
{
upf=k_upf_shield_1,
title="shield i",
desc="start with shield",
price=15,
},
{
upf=k_upf_shield_2,
title="shield ii",
desc="start with 2x shield",
price=20,
dep=k_upf_shield_1,
},
{
upf=k_upf_shield_3,
title="shield iii",
desc="start with 3x shield",
price=30,
dep=k_upf_shield_2,
},
{
upf=k_upf_start_dbl,
title="green laser",
desc="start with green laser",
price=30,
},
{
upf=k_upf_pwup_int,
title="more powerups",
desc="get powerups more often",
price=15,
},
}
-- template for entities. deep-copied to create
-- a new entity.
local k_e_template={
-- entity id (normally k_sp_... for the main sprite)
eid=0,
sp=nil, -- sprite to draw. if nil, use eid
x=0,y=0, -- position
vx=0,vy=0, -- velocity
age=0, -- age (in ticks)
facing=-1, -- facing dir, -1 is left, 1 is right
face_plr=false, -- automatically turn to face player?
bounce_x=false, -- automatically flip velocity when
-- edge of screen is reached?
vx_div=1,vy_div=1, -- velocity divisor (only moves
-- every this this many frames)
cr=k_cr_full, -- collision rect (non translated)
dead=false, -- if true, ent is pending deletion
-- if not nil, this is an emissive sprite to draw
-- after the lighting pass
em_sp=nil,
-- if not nil, this is how long this entity lives
-- for, after that it's deleted
ttl=nil,
-- if not nil, this is the ttl value below which
-- this entity will start to blink
blink_ttl=nil,
-- if true, this entity shoots projectiles.
fires=false,
-- what kind of projectile does it shoot?
fire_eid=k_eid_en_laser,
-- projectiles to shoot
-- each has:
-- off_x OR off_x_left/off_x_right:
-- x offset of projectile (when facing left
-- and right, respectively)
-- off_y: y offset of projectile
-- vx, vy: x velocity, y velocity
-- vx_facing: if true, adjust sign of x velocity
-- according to facing direction
fire_projs={
{off_x_left=-6,off_x_right=6,off_y=0,vx_facing=true}
},
-- minimum and maximum shooting interval
fire_int_min=60,fire_int_max=100,
-- countdown to next shot, if fires==true
fire_cd=nil,
-- if not nil, this is how much damage this entity
-- causes to the player
dmg_plr=nil,
-- if not nil, this is how much damage this entity
-- causes to enemies.
dmg_en=nil,
-- if >0 this entity was recently damaged
dmg_cd=0,
-- if not nil, this is the # of hitpoints that this
-- entity has
hp=nil,
-- animation for regular drawing pass
anim=nil,
-- animation for emissive drawing pass
em_anim=nil,
-- is it an enemy?
enemy=false,
-- is it an enemy projectile?
en_proj=false,
-- color substitution map
-- maps from_color -> to_color
-- applies to normal and emmissive sprites
cmap=nil,
-- if true, this entity zigzags vertically
zigzags=false,
zigzag_v=1,
-- spawn y. if defined, entity will be spawned
-- at this y coordinate regardless of map data
spawn_y=nil,
}
-- entity definitions. if an entity has a definition
-- in this table, the info there is overlaid on top
-- of the template when creating it. this can
-- override any defaults set in e_template
local g_ent_defs={
-- [0] is used for all entities missing an entry
[0]={},
[1]={em_sp=17},
-- player laser
[k_eid_plr_laser]={
sp=0,
em_sp=k_sp_hlaser_l,
vx=5,
cr=k_cr_hbar,
ttl=25,
dmg_en=1,
},
-- enemy laser (horizontal)
[k_eid_en_laser]={
sp=0,
em_anim={fr={k_sp_hlaser_s,46},div=4,loop=true},
vx=-1,
cr=k_cr_hbar_s,
dmg_plr=1,
ttl=100,
en_proj=true,
},
-- enemy "alpha"
[k_sp_en_alpha]={
em_sp=8,
enemy=true,
cr=k_cr_ship,
vx=-1,
vx_div=2,
vy_div=2,
fire_int_min=30,
fire_int_max=45,
bounce_x=true,
zigzags=true,
dmg_plr=1,
hp=3,
face_plr=true,
},
-- explosion sprite
[k_sp_kaboom]={
sp=0, -- hack: rendering for k_sp_kaboom is hard-coded
ttl=5,
vx=-1,vx_div=2,
},
-- enemy boat
[k_sp_en_boat]={
em_sp=23,
enemy=true,
vx=-1,
vx_div=3,
bounce_x=true,
cr=k_cr_half,
fires=true,
fire_eid=k_sp_fireball,
fire_projs={
{off_x_left=-1,off_x_right=2,off_y=-2,vx_facing=true},
},
fire_int_min=55,
fire_int_max=75,
dmg_plr=1,
hp=3,
face_plr=true,
spawn_y=k_water_y-8, -- on water surface
},
-- enemy fireball (flies diagonally)
[k_sp_fireball]={
em_anim=k_anim_fireball,
vy=-1,
vx=-1,
vx_div=2,
vy_div=2,
cr=k_cr_ball,
dmg_plr=1,
ttl=120,
en_proj=true,
},
-- enemy "beta"
[k_sp_en_beta]={
em_sp=11,
enemy=true,
cr=k_cr_ship,
fires=true,
fire_int_min=40,fire_int_max=60,
laser_clr=10,
bounce_x=true,
zigzags=true,
vx=-1,
vx_div=3,
vy_div=2,
dmg_plr=1,
hp=3,
face_plr=true,
},
-- "double laser" powerup
[k_sp_weap_dbl]={
em_sp=37,
ttl=120,
blink_ttl=60,
pwup=true,
cr=k_cr_pwup,
vx=-1,vx_div=2,
},
-- "mach laser" powerup
[k_sp_weap_mach]={
em_sp=112,
ttl=120,
blink_ttl=60,
pwup=true,
cr=k_cr_pwup,
vx=-1,vx_div=2,
},
-- double laser (projectile)
[k_sp_dbl]={
sp=0,
em_sp=k_sp_dbl,
vx=3,
cr=k_cr_dbl,
ttl=25,
dmg_en=3,
},
-- shield powerup
[k_sp_shield]={
em_sp=40,
ttl=120,
blink_ttl=60,
pwup=true,
cr=k_cr_pwup,
vx=-1,vx_div=2,
},
-- enemy "gamma"
[k_sp_en_gamma]={
em_sp=42,
enemy=true,
cr=k_cr_ship,
fires=true,
fire_int_min=30,fire_int_max=45,
laser_clr=8,
bounce_x=true,
vx=-1,
vx_div=30,
dmg_plr=1,
hp=9,
zigzags=true,
face_plr=true,
},
-- coin
[k_sp_coin]={
em_sp=k_sp_coin,
ttl=120,
blink_ttl=60,
pwup=true,
cr=k_cr_pwup,
vx=-1,vx_div=2,
},
-- enemy "spiky"
[k_sp_en_spiky]={
em_anim=k_anim_spiky,
enemy=true,
cr=k_cr_ball4,
fires=true,
fire_eid=k_sp_fireball,
fire_int_min=30,fire_int_max=45,
fire_projs={
{off_x=-1,off_y=-1,vx=-1,vy=-1},
{off_x=-1,off_y=2,vx=-1,vy=1},
{off_x=2,off_y=-1,vx=1,vy=-1},
{off_x=2,off_y=2,vx=1,vy=1},
},
laser_clr=8,
bounce_x=true,
vx=-1,
dmg_plr=1,
hp=1,
zigzags=true,
},
-- enemy "delta"
[k_sp_en_delta]={
em_sp=45,
anim={fr={43,44},div=2,loop=true},
enemy=true,
cr=k_cr_ship,
fires=true,
fire_int_min=15,fire_int_max=30,
laser_clr=11,