-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lina_witches_of_the_moon.p8
2590 lines (2302 loc) · 89.6 KB
/
lina_witches_of_the_moon.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 -- luacheck: ignore
version 38 -- luacheck: ignore
__lua__
player = {
x = 8,
y = 64,
moving = false,
life = 3,
maxLife = 4,
shooting = false,
collisionWidth = 8,
collisionHeigth = 8,
flashTime = 0,
invTime = 0,
attackType = 0,
cats = 0
}
ax, ay = 0,0
mode = 0 --0 menu, 1 game, 3 wave clear, 4 game over, 5 tutorial
score = 0
attackFreq = 2
started, canSpawnMoon, won, musicOn = false, false, false, true
stage,wave,splashScreenTime,nextAttack,nextShoot,offset,freeze,catTimer,catZeroIndicator,scoreThousands,highScore, highScoreThousands, moonSpawn, moonGlitch, wonTime, moonX, moonY, boom, propX, propY, propRnd, starTime = 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
bg_elements, scores, player_bullets, pickups, enemy_bullets, enemies, particles, shockwaves, pPos = {}, {}, {}, {}, {}, {}, {}, {}, {}
catX, catY, forceShield, shotCooldown, tutorialChapter, tutorialCd, gauge, t = 0, 0, 0, 0, 0, 0, 0, 0
tutorialBackWard = {
x = 36,
y = 10,
collisionWidth = 8,
collisionHeigth = 8
}
tutorialForward = {
x = 84,
y = 10,
collisionWidth = 8,
collisionHeigth = 8
}
hyper = false
mapString = {
"1, 1, 1, 1, 1, 1, 1, 1, 1 | 1, 1, 1, 1, 1, 1, 1, 1, 1 | 1, 1, 1, 1, 1, 1, 1, 1, 1 | 1, 1, 1, 1, 1, 1, 1, 1, 1 ",
"1, 0, 2, 1, 1, 1, 2, 0, 1 | 1, 0, 2, 1, 1, 1, 2, 0, 1 | 1, 2, 2, 1, 2, 1, 2, 2, 1 | 1, 2, 2, 1, 2, 1, 2, 2, 1 ",
"0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 5, 0, 0, 0, 0, 5, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 ",
"1, 1, 1, 1, 1, 1, 1, 1, 1 | 2, 0, 0, 1, 2, 1, 0, 0, 2 | 2, 5, 0, 1, 2, 1, 5, 0, 2 | 2, 0, 0, 2, 2, 2, 0, 0, 2 ",
"0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 0, 0, 0, 6, 0, 0, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 ",
"7, 7, 7, 7, 7, 7, 7, 7, 7 | 7, 3, 3, 7, 7, 7, 3, 3, 7 | 7, 3, 0, 3, 7, 3, 0, 3, 7 | 7, 0, 3, 0, 7, 0, 3, 0, 7 ",
"7, 0, 8, 0, 7, 0, 8, 0, 7 | 7, 0, 8, 0, 7, 0, 8, 0, 7 | 7, 7, 8, 8, 7, 8, 8, 7, 7 | 7, 7, 8, 8, 7, 8, 8, 7, 7 ",
"0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 10, 0, 0, 0, 0, 0, 10, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 ",
"7, 7, 7, 7, 7, 7, 7, 7 , 7 | 7, 0, 0, 8, 8, 8, 0, 7, 7 | 0, 8, 0, 7, 10, 7, 0, 8, 0 | 0, 8, 8, 7, 7, 7, 8, 8, 0 ",
"0, 0, 0, 0, 0, 0, 0, 0 , 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 0, 0, 0, 9, 0, 0, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 ",
"11, 11, 11, 11, 11, 11, 11, 11, 11 | 11, 11, 11, 11, 11, 11, 11, 11, 11 | 11, 11, 11, 11, 11, 11, 11, 11, 11 | 11, 11, 11, 11, 11, 11, 11, 11, 11 ",
"11, 13, 13, 11, 11, 11, 13, 13, 11 | 11, 13, 13, 11, 11, 11, 13, 13, 11 | 11, 13, 13, 13, 13, 13, 13, 13, 11 | 11, 13, 13, 13, 13, 13, 13, 13, 11 ",
"0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 14, 0, 0, 0, 0, 0, 14, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0",
"11, 11, 0, 13, 13, 13, 0, 11, 11 | 11, 11, 0, 13, 13, 13, 0, 11, 11 | 0 , 14, 0, 13, 13, 13, 0, 14, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0",
"0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 0, 0, 0, 12, 0, 0, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0",
"0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0 | 0, 0, 0, 0, 15, 0, 0, 0, 0 | 0, 0, 0, 0, 0, 0, 0, 0, 0"
}
function toggle_music()
musicOn = not musicOn
if musicOn then
music(0)
else
music(-1,300)
end
end
function _init()
cartdata("lina_witches_of_the_moon")
menuitem(2, "toggle music", toggle_music)
music(0)
for i=1,25 do
local star = {
x = rnd(128),
y = 10+flr(rnd(90)),
clr = 1+flr(rnd(2))*5,
spd = 2,
spr = nil
}
add(bg_elements, star)
local tree = {
x = rnd(128),
y = 120,
clr = nil,
spd = 4,
spr = 60 + (flr(rnd(4)))
}
add(bg_elements, tree)
local pTree = {
x = rnd(128),
y = 116,
clr = nil,
spd = 3,
spr = 58 + (flr(rnd(2)))
}
add(bg_elements, pTree)
end
end
function animate(object,starterframe,framecount,animspeed,flipped,isplayer,isBig,shake)
if isBig == nil then isBig = false end
if shake == nil then shake = false end
if(not object.tickcount) then
object.tickcount=0
end
if(not object.spriteoffset) then
object.spriteoffset=0
end
object.tickcount+=1
if(object.tickcount%(flr(60/animspeed))==0) then
if isBig then
object.spriteoffset+=2
if (object.spriteoffset>=framecount*2) then
object.spriteoffset=0
end
else
object.spriteoffset+=1
if (object.spriteoffset>=framecount) then
object.spriteoffset=0
end
end
end
object.actualframe=starterframe+object.spriteoffset
if not isBig then
if object.actualframe >= starterframe+framecount then
object.actualframe = starterframe
end
else
if object.actualframe >= (starterframe+framecount)*2 then
object.actualframe = starterframe
end
end
local offsetX = 0
local offsetY = 0
if shake then
offsetX = rnd()*3
offsetY = rnd()*3
end
if isBig then
spr(object.actualframe, object.x+offsetX, object.y+offsetY, 2, 2, flipped)
else
spr(object.actualframe, object.x+offsetX, object.y+offsetY, 1, 1, flipped)
end
end
function add_score(_x, _y, _value)
local s = {
x = _x,
y = _y,
value = _value
}
add(scores, s)
end
function add_pickup(_x, _y, _tpe)
local p = {
x = _x,
y = _y,
tpe = _tpe,
collisionWidth = 8,
collisionHeigth = 8
}
add(pickups, p)
end
function add_shockwave(_x, _y, _size, _clr, _spd)
local sw = {
x = _x,
y = _y,
size = 1,
targetSize = _size,
clr = _clr,
spd = _spd
}
add(shockwaves, sw)
end
function add_enemy(_x, _y, _tpe, _wait)
local lives = split("8, 12, 24, 2, 140, 360, 16, 24, 400, 140, 24, 440, 16, 160, 200, 900",",")
local sprites = split("64, 66, 68, 70, 80, 0, 72, 74, 0, 84, 76, 0, 78, 88, 0, 0",",")
local sizes = split("1,1,1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 4",",")
-- "up-down", "stationary", "forward-back", "circle", "spawning"
local bossPhases = { {"up-down", "stationary", "forward-back"}, {"forward-back", "circle", "up-down", "forward-back"}, {"spawning", "up-down", "circle", "spawning"}, {"circle", "up-down", "circle", "spawning"}, {"up-down", "circle", "forward-back", "spawning"} }
-- "single", "double", "trio", "cross", "diagonal", "ortogonal", "aimed", "spiral"
-- spawnrules follow: { number, type, times}
local bossPhaseAttackPattern = {{"single", "trio", "cross"}, {"circle", "aimed", "spiral", "circle"}, {{6, 7, 2}, "spiral", "aimed", {4, 8, 7}}, {"circle", "trio", "aimed", {2, 11, 2}}, {"circle", "aimed", "spiral", {2, 14, 2}}}
local enemy = {
x = _x+40,
y = 110 ,
sx = 0,
sy = 0,
posx = _x,
posy = _y,
life = lives[_tpe],
tpe = _tpe,
spr = sprites[_tpe],
size = sizes[_tpe],
animFrames = 2,
animSpeed = 6,
collisionWidth = sizes[_tpe]*8,
collisionHeigth = sizes[_tpe]*8,
flash = 0,
shoot = 0,
mission = "flyin",
submission = "",
wait = _wait,
isWitch = false,
phaseBegin = 0,
shake = 0,
bossIndex = 0,
phases = nil,
attackPattern = nil,
attackPatterns = nil,
phaseNumber = 0,
indicator = 0,
falling = false,
spawnTime = 0
}
-- small ghost, do not return to spawn
if (_tpe == 4) then
enemy.x = _x-4
enemy.y = _y
end
if (_tpe == 6) or (_tpe == 9) or (_tpe == 12) or (_tpe == 15) or (_tpe == 16) then
enemy.isWitch = true
enemy.bossIndex = _tpe/3-1
if (_tpe == 16) then enemy.bossIndex = 5 end
if (not _tpe == 16) enemy.collisionHeigth = 10
end
if enemy.isWitch then
enemy.phases = bossPhases[enemy.bossIndex]
enemy.attackPatterns = bossPhaseAttackPattern[enemy.bossIndex]
enemy.phaseNumber = #enemy.attackPatterns
enemy.indicator = 0
end
add(enemies, enemy)
end
function add_player_bullet(_x, _y, _tpe, _sx, _sy)
local damages = split("3, 4, 4, 8, 3, 7, 2, 3")
local bul = {
x = _x,
y = _y,
sx = _sx,
sy = _sy,
tpe = _tpe,
speed = _speed,
dmg = damages[_tpe],
collisionWidth = 2,
collisionHeigth = 2
}
add(player_bullets, bul)
end
function add_enemy_bullet(_x, _y, _sx, _sy, _tpe, _speed)
local bul = {
x = _x,
y = _y,
sx = _sx*_speed,
sy = _sy*_speed,
spr = 10+_tpe,
tpe = _tpe,
speed = _speed,
collisionWidth = 3,
collisionHeigth = 3,
spr = 112 + _tpe*2,
animFrames = 2,
animSpeed = 6
}
add(enemy_bullets, bul)
end
function load_wave_string (_idx)
return split(mapString[_idx], "|")
end
function spawn_wave_waves(_wave)
for lineIdx=1,#_wave do
local waveLine = split(_wave[lineIdx], ",", true)
for enemyNumber=1,#waveLine do
if not (waveLine[enemyNumber] == 0) then
add_enemy(80+lineIdx*10, 12+enemyNumber*10,waveLine[enemyNumber], enemyNumber*6)
end
end
end
end
function spawn_wave()
sfx(1)
started = true
stage = 1 + flr(wave/6)
spawn_wave_waves(split(mapString[wave], "|"))
end
function place_enemies(lvl)
for x=1,4 do
for y=1,9 do
if not (lvl[x][y] == 0) then
add_enemy(80+x*10, 12+y*10,lvl[x][y], y*6)
end
end
end
end
function collide(a, b)
if (a.collisionWidth == nil) a.collisionWidth = 0
if (a.collisionHeigth == nil) a.collisionHeigth = 0
if (b.collisionWidth == nil) b.collisionWidth = 0
if (b.collisionHeigth == nil) b.collisionHeigth = 0
local aLeft = a.x
local aTop = a.y
local aRigth = a.x+a.collisionWidth-1
local aBottom = a.y+a.collisionHeigth-1
local bLeft = b.x
local bTop = b.y
local bRigth = b.x+b.collisionWidth-1
local bBottom = b.y+b.collisionHeigth-1
if (aTop > bBottom) return false
if (bTop > aBottom) return false
if (aLeft > bRigth) return false
if (bLeft > aRigth) return false
return true
end
function add_bg(_tick,_speed)
if (t%_tick*2 == 0) then
local star = {
x = 128,
y = 10+flr(rnd(90)),
clr = 1+flr(rnd(2))*5,
spd = 2*_speed,
spr = nil
}
add(bg_elements, star)
local tree = {
x = 128,
y = 120,
clr = nil,
spd = 4*_speed,
spr = 60 + (flr(rnd(4)))
}
add(bg_elements, tree)
local pTree = {
x = 128,
y = 116,
clr = nil,
spd = 3*_speed,
spr = 58 + (flr(rnd(2)))
}
add(bg_elements, pTree)
end
end
function start_game()
mode = 1
player = {
x = 8,
y = 64,
moving = false,
life = 4,
maxLife = 4,
shooting = false,
collisionWidth = 8,
collisionHeigth = 8,
flashTime = 0,
invTime = 0,
cats = 0,
attackType = 0
}
wave, nextAttack, moonSpawn, moonGlitch, t, offset, boom, score, scoreThousands, stage, forceShield, catX, catY, attackFreq, gauge = 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, player.x+8, player.y, 2, 0
started, canSpawnMoon, won = false, false, false
player_bullets, enemy_bullets, pickups, scores, enemies, particles, pPos = {}, {}, {}, {}, {}, {}, {}
end
function count_down(_var)
return max(_var-1, 0)
end
function _update60()
add_bg(4, 0.5)
t+=1
if t>=60 then
t = 0
end
if mode == 0 then
update_menu()
elseif mode == 1 then
update_game()
elseif mode == 2 then
update_splash_screen()
elseif mode == 3 then
update_game_over()
elseif mode == 4 then
start_game()
elseif mode == 5 then
update_tutorial()
end
update_stars()
end
function update_tutorial()
control_player()
update_bullets()
update_particles()
update_pickups()
update_enemies()
tutorialCd = count_down(tutorialCd)
if tutorialCd == 0 then
if collide(player, tutorialForward) then
enemies = {}
tutorialChapter += 1
tutorialCd = 120
end
if collide(player, tutorialBackWard) then
enemies = {}
tutorialChapter -= 1
tutorialCd = 120
end
if tutorialChapter < 0 then
tutorialChapter = 3
end
if tutorialChapter > 2 then
tutorialChapter = 0
end
end
--[[
0 - Main Hub
1 - HP Hub
2 - Shooting Hub
3 - Special Hub
]]--
if (time()%0.5 == 0) then
if tutorialChapter == 1 then
add_pickup(10, 40, 0)
add_pickup(10, 66, 7)
add_pickup(10, 80, 6)
end
if tutorialChapter == 2 then
for i=0,3 do
add_pickup(10, 38+i*10, 1+i)
end
add_pickup(10,78, 8)
add_pickup(10, 88, 5)
end
add_enemy_bullet(127, 104, -1, 0, 0, 1)
end
if (#enemies == 0) then
add_enemy(100, 40, 1, 2)
add_enemy(100, 48, 1, 10)
add_enemy(100, 56, 1, 20)
end
if tutorialChapter == 0 then
if player.x > 120 then
mode = 4
end
end
--[[
0 -> Potion
1 -> Shield
2 -> simple atk
3 -> 2x atk
4 -> 3x atk
5 -> cat bomb
6 -> star
]]--
end
function update_splash_screen()
player.moving = true
splashScreenTime -= 1
if splashScreenTime <= 0 then
mode = 1
spawn_wave()
end
end
function update_menu()
highScore = dget(0)
highScoreThousands = dget(1)
if btnp(4) then
player.x, player.y, catX, catY = 64, 64, 50, 50
mode = 5
end
if propX <= 0 then
propX, propY, propRnd = 130, 20+rnd(90), flr(rnd(2))
else
propX -= 1
end
propY += sin(t)
end
function update_game_over()
if btnp(5) then
start_game()
mode = 0
music(0)
end
update_particles()
end
function update_game()
moonSpawn = count_down(moonSpawn)
moonGlitch = count_down(moonGlitch)
wonTime = count_down(wonTime)
if score > 9999 then
score = score - 9999
scoreThousands+= 1
end
if gauge >= 128 then
hyper = true
end
if gauge <= 0 then
if (hyper) then
starTime = 90
forceShield = 0
end
hyper = false
end
if (hyper) then
if (t%20 == 0) offset = 0.1
forceShield = 100
starTime = 100
gauge -= 0.9
end
update_particles()
if (won) and (wonTime > 0) then
if t%6 == 0 then
explode_part(moonX+rnd(10), moonY+rnd(10), "circle", 7, boom)
sfx(2)
offset=0.2
boom += 0.05
end
end
if (won) and (wonTime == 0) then
mode = 3
end
if freeze > 0 then
freeze -= 1
if freeze <= 0 then
mode = 3
end
player.x += ax
ax = ax * 0.99
player.y += ay
ay = ay * 1.05
else
if ((#enemies == 0) and (#pickups == 0) and (not won)) then
wave+= 1
splashScreenTime = 180
mode = 2
enemy_bullets = {}
particles = {}
shockwaves = {}
player_bullets = {}
pickups = {}
if (wave % 5 == 0) then
music(31)
elseif (wave % 6 == 0) then
music(0)
sfx(5)
end
end
control_player()
update_bullets()
update_enemies()
--select attacker
if (time() > nextAttack) and (#enemies > 0) then
trigger_next_attack()
end
if (time() > nextShoot) and (#enemies > 0) then
local maximum = min(10, #enemies)
-- picker algo
local myIndex = flr(rnd(maximum)+1)
local enemy = enemies[myIndex]
if enemy.mission == "protect" then
enemy.shoot = 10
local pattern = "single"
local ang = 0
if (wave > 5) then
pattern = "double"
angle = 0.5
end
if (wave > 10) pattern = "trio"
attack_with_pattern(enemy, pattern, angle, 0.8)
sfx(4)
end
nextShoot = time() + (attackFreq*0.3)
end
if player.life <= 0 then
freeze = 360
ay = 1
if ax == 0 then
ax = 1
end
end
update_pickups()
for s in all(scores) do
local ang = atan2(s.y, s.x-60)
if (s.y <= 10) then
score += s.value
del(scores,s)
end
s.x -= sin(ang)*2
s.y -= cos(ang)*2
end
end
end
function trigger_next_attack()
local maximum = min(10, #enemies)
-- picker algo
local myIndex = flr(rnd(maximum)+1)
local enemy = enemies[myIndex]
if enemy.mission == "protect" then
enemy.mission = "attack"
enemy.shake = 16
enemy.wait = 16
if enemy.tpe == 2 then
enemy.changed = false
end
end
nextAttack = time() + attackFreq*2
end
function control_player()
local px, py = player.x, player.y
catTimer = count_down(catTimer)
catZeroIndicator = count_down(catZeroIndicator)
player.invTime = count_down(player.invTime)
player.flashTime = count_down(player.flashTime)
starTime = count_down(starTime)
forceShield = count_down(forceShield)
ax = 0
ay = 0
player.shooting = false
player.moving = false
if(btn(⬅️)) then
ax-=1.5
player.moving = true
end
if(btn(➡️)) then
ax+=1.5
player.moving = true
end
if(btn(⬆️)) then
ay-=1.5
player.moving = true
end
if(btn(⬇️)) then
ay+=1.5
player.moving = true
end
if (player.moving) then
local p = {
x = player.x,
y = player.y
}
add(pPos, p)
end
if (#pPos > 10) then
catX = pPos[1].x
catY = pPos[1].y
del(pPos, pPos[1])
end
-- normalize speed
if (ay < 0) and (ay < -2) then ay = -2 end
if (ay > 0) and (ay > 2) then ay = 2 end
if (ax < 0) and (ax < -2) then ax = -2 end
if (ax > 0) and (ax > 2) then ax = 2 end
px += ax
py += ay
if px < 0 then
px = 0
end
if px > 124 then
px = 124
end
if py < 0 then
py = 0
end
if py > 120 then
py = 120
end
if btn(4) then
if (t%10 == 0) add_player_bullet(catX, catY, 1, 2, 0)
if (time() > shotCooldown) then
local damage = player.attackType + 1
local coolDown = 0
if (hyper) damage = 6
local posX, posY = px+6, py+6
if (player.attackType == 0) then
add_player_bullet(posX, posY, damage, 2, 0)
coolDown = 0.05
elseif player.attackType == 1 then
add_player_bullet(posX, posY, damage, 2, 0.15)
add_player_bullet(posX, posY, damage, 2, -0.15)
coolDown = 0.1
elseif player.attackType == 2 then
for i=-0.5,0.5,0.5 do
add_player_bullet(posX, posY, damage, 2, i/2)
end
coolDown = 0.15
elseif player.attackType == 4 then
--for i=-1,1, 0.0625 do
local a = sin((60-t)/50)*2
local b = cos((60-t)/50)*2
add_player_bullet(posX, posY, damage, a, b)
add_player_bullet(posX, posY, damage, -a, -b)
coolDown = 0.02
else
local w = t/10
for i=-w,w,w/4 do
add_player_bullet(posX, posY, damage, cos(i), sin(i/2))
end
coolDown = 0.2
end
sfx(0)
if (hyper) coolDown = coolDown/2
shotCooldown = time() + coolDown
player.shooting = true
end
end
if btnp(5) then
if (player.cats >= 1) and (catTimer <= 0) then
offset = 0.4
for i=0.6,0.9,0.01 do
add_player_bullet(px+6, py+6, 4, sin(i)*4, cos(i)*3)
sfx(7)
player.shooting = true
catTimer = 180
end
for b in all(enemy_bullets) do
explode_part(b.x, b.y, "circle", 3)
del(enemy_bullets, b)
end
else
catZeroIndicator = 20
end
end
player.x, player.y = px, py
end
--[[
0 -> Potion
1 -> Shield
2 -> simple atk
3 -> 2x atk
4 -> 3x atk
5 -> cat bomb
6 -> star
]]--
function update_pickups()
for p in all(pickups) do
if collide(p, player) then
local mult = 1
local pType = p.tpe
if pType == 0 then
if player.life < player.maxLife then
player.life +=1
end
if player.life == player.maxLife then
mult = 10
end
end
if pType == 1 then
player.attackType = 0
end
if pType == 2 then
player.attackType = 1
end
if pType == 3 then
player.attackType = 2
end
if pType == 4 then
player.attackType = 4
end
if pType == 5 then
player.cats += 1
end
if pType == 6 then
starTime = 280
end
if pType == 7 then
forceShield = 360
end
if pType == 8 then
player.attackType = 7
end
sfx(6)
del(pickups, p)
add_score(p.x+4, p.y+4, (pType+1) * 100 * mult)
end
p.x -= 0.5
if p.x <= -8 then
del(pickups,p)
end
end
end
--[[
0 -> Potion
1 -> simple atk
2 -> 2x atk
3 -> 3x atk
4 -> waves
5 -> frog bomb
6 -> star
7 -> shield
8 -> spiral
]]--
function spawn_pickup(_x, _y)
local picks = split("0,0,0,0,0,0,1,1,2,2,3,3,4,4,5,6,7,8,8",",")
local dupes = {}
if (player.life == player.maxLife) then
add(dupes, 0)
end
for i=0,4-player.life do
add(picks, 0)
end
add(dupes, player.attackType)
local randomDrop;
local isDupe = false
repeat
isDupe = false
randomDrop = rnd(picks)
for e in all(dupes) do
if (e == randomDrop) isDupe = true
end
until(not isDupe)
add_pickup(_x, _y, randomDrop)
end
function update_stars()
for element in all(bg_elements) do
if mode == 2 then
element.x -= element.spd*2
else
element.x -= element.spd
end
if element.x < 0 then
del(bg_elements, element)
end
end
end
function player_hit()
player.flashTime = 90
player.invTime = 90
player.life -= 1
offset = 0.2
gauge = 0
explode_part(player.x, player.y, "circle", 14, 1)
--player.shields -= 1
--player.shieldTime = 40
sfx(3)
end
function update_enemies()
for enemy in all(enemies) do
enemy.shake = count_down(enemy.shake)
--[[
if enemy.shake > 0 then
enemy.shake -= 1
end
]]
if enemy.wait > 0 then
enemy.wait -=1
if enemy.tpe == 16 then
sfx(2)
end
else
fulfill_mission(enemy)
-- DEAD
if enemy.life <= 0 then
-- split ghosts
if enemy.tpe == 3 then
add_enemy(enemy.x, enemy.y - 8, 4, 30)
add_enemy(enemy.x, enemy.y + 8, 4, 30)
add_enemy(enemy.x+8, enemy.y, 4, 30)
end
if enemy.isWitch then
if (not (enemy.tpe == 15)) then
enemy.falling = true
enemy.mission = "falling"
enemy.sx = -1
enemy.sy = 0.5
elseif (moonSpawn == 0) and (not enemy.falling) and (enemy.tpe == 15) then
moonSpawn = 180
enemy.falling = true
enemy.mission = "flyin"
canSpawnMoon = true
elseif moonSpawn == 0 then
add_enemy(80, enemy.y, 16, 0)
music(39)
del(enemies, enemy)
moonGlitch = 60
else
if (t%10 == 0) then
explode_part(enemy.x, enemy.y, "circle", 7, 10-(moonSpawn/20))
--enemy.shake = true
offset = 0.45-(moonSpawn/400)
sfx(2)
end
end
end
if not enemy.isWitch then
del(enemies, enemy)
end
if not enemy.falling then
death_trigger(enemy)