-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameoff2021.lua
1908 lines (1856 loc) · 161 KB
/
gameoff2021.lua
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
-- title: AntVania
-- author: Muhammad Fauzan
-- desc: Metroidvania Month 14
-- script: lua
scn=0
zClick=false
tim={--time
inv=0,--invisible
an=0--animation
}
pla={--player
an=0,--animation
f=0,--flip
x=0,
y=0,
vx=0,
vy=0,
sp=1,--speed
hl=3,--health
wp=0,--weapon
ab=0,--ability
td=0,--time dead
inv=false,--invisible
eup=false,--power up effect
grv=true,--gravity
}
swo={--sword
x=0,
y=0,
t=0,
ac=true--active
}
bwo={--bow
x=0,
y=0,
t=0,
sp=193,
am=0,--amount
ac=true--active
}
cam={--camera
mx=0,
my=0,
x=0,
y=0,
a=1,
ll=0,--left limit
lr=0,--right limit
lu=0,--up limit
ld=0,--down limit
sh=false--shake
}
shake=0
sav={--save
px=0,
py=0,
hl=0,
wp=0,
bw=0,
ab=0,
ded=0
}
isHeal=false
isSave=false
cir={}--circle
slh={}--sword slash
arw={}--arrow
eup={}--effect power up
edm={}--effect damage
exp={}--effect explosion
spw={}--spawn enemy
ebg={}--enemy bug
efl={}--enemy fly
ehg={}--enemy hedgehog
bhg={}--bullet hedgehog
ssl={}--spawn banaspati
esl={}--banaspati
glm={}--golem
clm={}--crimson golem
gpw={}--cGolem power
bos1={}--boss 1
bos1Ded=false
bos2={}--boss 2
bos2Ded=false
ston={}--falling stone
dbg=false
function debug()
local d=dbg local p=pla local c=cam local sv=sav local sav=isSave
if keyp(4) then
if not d then dbg=true
else dbg=false end
end
if d then
print("playerX: "..p.x.."",8,16,12)
print("playerY: "..p.y.."",8,24,12)
print("cameraX: "..c.x.."",8,32,12)
print("cameraY: "..c.y.."",8,40,12)
print("camLimL: "..c.ll.."",8,48,12)
print("camLimR: "..c.lr.."",8,56,12)
print("camLimU: "..c.lu.."",8,64,12)
print("camLimD: "..c.ld.."",8,72,12)
print(sav,8,80,12)
print("pmem0(pX): "..pmem(0).."",8,88,12)
print("pmem1(pY): "..pmem(1).."",8,96,12)
print("pmem2(hl): "..pmem(2).."",8,104,12)
print("pmem3(wp): "..pmem(3).."",8,112,12)
print("pmem4(ab): "..pmem(4).."",8,120,12)
print("pmem5(bw): "..pmem(5).."",8,128,12)
--
print("slash: "..#slh.."",96,16,12)
print("arrow: "..#arw.."",96,24,12)
print("effUp: "..#eup.."",96,32,12)
print("effdm: "..#edm.."",96,40,12)
print("irisS: "..#cir.."",96,48,12)
print(p.inv,96,56,12)
print("explosion: "..#exp.."",96,64,12)
print("death: "..sv.ded.."",96,80,12)
--
print("spawn: "..#spw.."",176,16,12)
print("bug: "..#ebg.."",176,24,12)
print("fly: "..#efl.."",176,32,12)
print("fly: "..#efl.."",176,32,12)
print("hedge: "..#ehg.."",176,40,12)
print("hedgeBul: "..#bhg.."",176,48,12)
print("sSoul: "..#ssl.."",176,56,12)
print("soul: "..#efl.."",176,64,12)
print("golem: "..#glm.."",176,72,12)
print("cGolem: "..#clm.."",176,80,12)
print("golemPow: "..#gpw.."",176,88,12)
print("boss 1: "..#bos1.."",176,104,12)
print("boss 2: "..#bos2.."",176,112,12)
print("stone: "..#ston.."",176,120,12)
end
end
function TIC()
render()--debug()
end
pMusic=false
function _music(tr,lo)
if not pMusic then
music(tr,-1,-1,lo)
pMusic=true
end
end
--save & load
function save()
local p=pla local sv=sav local bw=bwo
local flr=math.floor
sv.px=flr(p.x) sv.py=flr(p.y)
sv.hl=p.hl
sv.wp=p.wp sv.bw=bw.am sv.ab=p.ab
pmem(0,sv.px)pmem(1,sv.py)
pmem(2,sv.hl)
pmem(3,sv.wp)pmem(5,sv.bw)pmem(4,sv.ab)
pmem(6,sv.ded)
isSave=true
end
function load()
local p=pla local bw=bwo
fade(32,-1)
p.x=pmem(0)p.y=pmem(1)
p.hl=pmem(2)
p.wp=pmem(3)bw.am=pmem(5)p.ab=pmem(4)
sav.ded=pmem(6)
end
function newGame()
local p=pla local bw=bwo
fade(32,-1)
pmem(0,0)
p.x=56 p.y=112
p.grv=true
p.hl=3
p.wp=0 bw.am=0 p.ab=0
sav.ded=0
end
------------
function render()
local s=scn
--title
if s==0 then sTitle()
--game
elseif s==1 then sGame()
--game over
elseif s==2 then sOver()
end
end
function sTitle()
--music
_music(0,true)
-------
map(210,102)
spr(240,56,40,0,2,0,0,8,1)
print("Game by MFauzan",92,60,8,false,1,true)
if not zClick then
if time()%1000>500 then
print("PRESS TO START",74,98,8)
print("PRESS TO START",74,97,12)
spr(188,109,96)
end
if btnp(4) then sfx(48,'c-3',30) zClick=true end
else
local coC=14--continue color
if pmem(0)>0 then coC=12 end
spr(184,84,87)print("TO CONTINUE",96,88,coC)
spr(185,84,103)print("TO NEW GAME",96,104,12)
--continue
if pmem(0)>0 and btnp(0) then sfx(48,'c-3',30)
load()
scn=1
end
--new game
if btnp(1) then sfx(48,'c-3',30)
newGame()
scn=1
end
end
end
init=false
function sInit()
--music
pMusic=false
_music(2,true)
-------
Spawn(39,12,0)Spawn(15,29,0)Spawn(104,10,0)Spawn(169,6,0)Spawn(82,44,0)Spawn(156,45,0)Spawn(171,60,0)
Spawn(84,56,1)Spawn(191,71,1)Spawn(145,73,1)Spawn(106,75,1)Spawn(75,74,1)Spawn(56,74,1)
Spawn(224,64,2)Spawn(216,57,2)Spawn(233,57,2)Spawn(224,41,2)Spawn(226,31,2)
Spawn(67,11,3)Spawn(101,28,3)Spawn(184,45,3)Spawn(126,79,3)
Spawn(50,96,4)Spawn(83,96,4)
SSoul(128,96)SSoul(154,96)SSoul(184,96)SSoul(64,113)
EBos1(194,115)
EBos2(217,123)
end
function sGame()
local p=pla local c=cam local bw=bwo
local rnd=math.random
if not init then sInit()init=true end
--change area
if p.x>0 and p.x<1680 and ((p.y>0 and p.y<816) or (p.y>952 and p.y<1088)) then
c.ll=0 c.lr=-1440 c.lu=(p.y//136)*-136 c.ld=c.lu
elseif p.x>0 and p.x<1440 and p.y>816 and p.y<952 then
c.ll=0 c.lr=-1200 c.lu=-816 c.ld=c.lu
elseif (p.x>1440 and p.x<1680 and p.y>816 and p.y<952) or (p.x>1680 and p.x<1920 and p.y>952 and p.y<1088) then
c.ll=(p.x//240)*-240 c.lr=c.ll c.lu=(p.y//136)*-136 c.ld=c.lu
elseif p.x>1680 and p.x<1920 and p.y>0 and p.y<816 then
c.ll=-1680 c.lr=c.ll c.lu=0 c.ld=-680
end
--camera
c.x=112-p.x c.y=68-p.y
if c.x>c.ll then c.x=c.ll end
if c.x<c.lr then c.x=c.lr end
if c.y>c.lu then c.y=c.lu end
if c.y<c.ld then c.y=c.ld end
map(0,0,240,136,c.x,c.y)
--camera shake
if c.sh then d=2
if shake>0 then
poke(0x3FF9,rnd(-d,d))
poke(0x3FF9+1,rnd(-d,d))
shake=shake-1
if shake==0 then memset(0x3FF9,0,2) c.sh=false end
end
end
--object
drawEBos1()
drawEBos2()
drawSpawn()
drawEBug()
drawEFly()
drawEHedg()
drawSSoul()
drawESoul()
drawEGolem()
drawECGolem()
drawEGPower()
drawEHgBul()
drawEStone()
if p.wp==0 then getSword(32,240) end
if bw.am==0 then getBow(1708,160) end
if bos1Ded then getGrav(1556,928) end
hud()player()
drawSlash()
drawArrow()
drawEffUp()
drawEffDam()
drawEffExplode()
drawFade()
--the end
if bos2Ded then sEnd() end
end
function sEnd()
local c=cam
print("THE END",1752+c.x,1008+c.y,6,true,2)
print("DEATHS : "..sav.ded.."",1760+c.x,1032+c.y,12,true)
end
function sOver()
init=false
mset(210,126,81)mset(210,127,81)
cls()
print("GAME OVER",68,56,2,false,2)
if time()%1000>500 then
spr(188,90,87,0)print("CONTINUE",104,88,12)
end
if btnp(4) then sfx(48,'c-3',30)
pmem(6,sav.ded)
if pmem(0)>0 then load()
else newGame() end
scn=1
end
end
function solid(x,y)
return mget(x//8,y//8)<80
end
function saveArea(x,y)
local saveA={[160]=true,[161]=true}
return saveA[(mget(x//8,y//8))]
end
function healArea(x,y)
local healA={[162]=true,[163]=true}
return healA[(mget(x//8,y//8))]
end
function shroom(x,y)
local shrmA={[77]=true,[78]=true,[79]=true}
return shrmA[(mget(x//8,y//8))]
end
function spike(x,y)
local spikA={[97]=true,[98]=true}
return spikA[(mget(x//8,y//8))]
end
function water(x,y)
local watrA={[99]=true,[144]=true}
return watrA[(mget(x//8,y//8))]
end
function dart(x,y)
return mget(x//8,y//8)==64
end
function hud()
local p=pla local h=p.hl*8
--bg
rect(0,0,240,14,0)
--health
for x=8,24,8 do spr(177,x,2,0) end
for x=8,h,8 do spr(176,x,2,0) end
--weapon
spr(178,160,2,0)
spr(179,176,2,0)
if p.wp==0 then
spr(183,168,2,0)--?
elseif p.wp==1 then
spr(189,152,2,0)--button
spr(180,168,2,0)--sword
elseif p.wp==2 then
spr(189,152,2,0)--button
spr(181,168,2,0)--bow & arrow
else
end
--power
spr(178,208,2,0)
spr(179,224,2,0)
if p.ab>0 then
spr(190,200,2,0)--button
spr(182,216,2,0)--power up
else spr(183,216,2,0)
end
--save
local sav=isSave
if saveArea(p.x+4,p.y+4) then
spr(164,48,2,0)
if not sav then
sfx(49,'e-6',30)
effUp(12)
save()isSave=true
end
else isSave=false end
--frame
rectb(0,14,240,122,1)
end
--weapon
function getSword(x,y)
local c=cam local p=pla
spr(180,x+c.x,y+c.y,0)
if p.x+4>x and p.x+4<x+8 and p.y+4>y and p.y+4<y+8 then
sfx(49,'f-5',30)effUp(4)p.wp=1
end
end
function sword(x,y,f)
local c=cam local sw=swo
if f==0 then sw.x=3 sw.y=-2
elseif f==1 then sw.x=-3 sw.y=-2
elseif f==2 then sw.x=3 sw.y=2
elseif f==3 then sw.x=-3 sw.y=2
end
if sw.ac then
sw.t=0
spr(192,x+sw.x+c.x,y+sw.y+c.y,0,1,f)
else
sw.t=sw.t+1
if sw.t>20 then sw.ac=true end
end
--attack
if btnp(5) then
if sw.ac then
sfx(54,'c-5',10)
slash(x+sw.x*3,y,f)
sw.ac=false
end
end
end
function slash(mx,my,mf)
local s={x=mx,y=my,f=mf,t=0}
slh[#slh+1]=s
end
function drawSlash()
local t=tim local c=cam local sl=slh
for i,s in pairs(sl) do
s.t=s.t+1
spr(200+t.an%12//3,s.x+c.x,s.y+c.y,0,1,s.f)
if s.t==12 then table.remove(slh,i) end
end
end
function getBow(x,y)
local p=pla local c=cam local bw=bwo
spr(181,x+c.x,y+c.y,0)
if p.x+4>x and p.x+4<x+8 and p.y+4>y and p.y+4<y+8 then
sfx(49,'f-5',30)effUp(2)bw.am=1
end
end
function bow(x,y,f)
local c=cam local bw=bwo
if f==0 then bw.x=3 --bw.y=-1
elseif f==1 then bw.x=-3 --bw.y=-1
elseif f==2 then bw.x=3 --bw.y=1
elseif f==3 then bw.x=-3 --bw.y=1
end
if bw.ac then bw.t=0 bw.sp=193
else bw.t=bw.t+1 if bw.t>15 then bw.ac=true end
end
spr(bw.sp,x+bw.x+c.x,y+bw.y+c.y,0,1,f)
--attack
if btnp(5) and bw.ac then
sfx(53,'c-5',20)
arrow(x+bw.x,y+4,bw.x)
bw.sp=194 bw.ac=false
end
end
function arrow(mx,my,mvx)
local ar={x=mx,y=my,vx=mvx,t=0}
arw[#arw+1]=ar
end
function drawArrow()
local c=cam local ar=arw
for i,ar in pairs(ar) do
ar.t=ar.t+1
ar.x=ar.x+ar.vx
pix(ar.x+c.x,ar.y+c.y,12)
if ar.t==20 or solid(ar.x,ar.y) then table.remove(arw,i) end
if dart(ar.x,ar.y) then mset(ar.x//8,ar.y//8,81) end
end
end
function getGrav(x,y)
local p=pla local c=cam
spr(165,x+c.x,y+c.y,0)
if p.x+4>x and p.x+4<x+8 and p.y+4>y and p.y+4<y+8 then
sfx(49,'f-5',30)effUp(3)p.ab=1
bos1Ded=false
end
end
-----
function player()
local p=pla local t=tim local c=cam local bw=bwo local sv=sav
local tn=t.an%28//7
t.an=t.an+1
--movement
if btn(2) then--left
p.vx=-p.sp
p.an=tn
if p.grv then p.f=1
else p.f=3 end
elseif btn(3) then--right
p.vx=p.sp
p.an=tn
if p.grv then p.f=0
else p.f=2 end
else p.an=0 p.vx=0 end
--change weapon
if btnp(7) and bw.am>0 then
if p.wp==1 then p.wp=2
else p.wp=1 end
end
--active gravity ability
if btnp(6) and p.ab==1 then
if p.grv then p.f=2 p.vy=-1 p.grv=false
else p.f=0 p.grv=true end
end
--collision
u=p.y+p.vy d=p.y+p.vy+8 l=p.x+p.vx r=p.x+p.vx+7
if solid(l,u+1) or solid(l,d-1) or solid(r,u+1) or solid(r,d-1) then p.vx=0 end
--gravity
if solid(l+1,d) or solid(r-1,d) then p.vy=0
else
if p.grv then p.vy=p.vy+0.2
else p.vy=p.vy-0.1 end
end
--jump
if p.vy==0 and btnp(4) then sfx(50,'c-3',30)p.vy=-3 end
if shroom(l,d) or shroom(r,d) then p.vy=-4 end
--collision up
if p.vy<0 and (solid(l+2,u) or solid(r-2,u)) then p.vy=0 end
--update movement
p.x=p.x+p.vx
p.y=p.y+p.vy
--limit health
if p.hl<0 then p.hl=0 end
if p.hl>3 then p.hl=3 end
--heal
local heal=isHeal
if healArea(l+4,u+4) then
if not heal then sfx(49,'e-6',30)effUp(5)p.hl=3 isHeal=true end
else isHeal=false end
--weapon
if p.wp==1 then sword(l,u,p.f)
elseif p.wp==2 then bow(l,u,p.f) end
--invisible
if p.inv then
t.inv=t.inv+1
--blink
if time()%200>100 then
spr(208+p.an,p.x+c.x,p.y+c.y,0,1,p.f)
end
if t.inv==60*2 then t.inv=0 p.inv=false end
--draw
else
spr(208+p.an,p.x+c.x,p.y+c.y,0,1,p.f)
end
--damage by spike and water
if not p.inv and spike(l+4,u+4) then EAtt2() end
if water(l+4,u+4) then EAtt2() end
--dead
if p.hl<1 then
if #cir==0 then p.td=0 fade(0,1) end
p.td=p.td+1 if p.td==32 then
--music
pMusic=false
_music(1,false)
-------
sv.ded=sv.ded+1
scn=2
end
end
end
--enemy
function ESolid(l,r,u,d)--enemy collision
return solid(l-1,u+4) or solid(r+1,u+4) or not solid(l,d) or not solid(r,d)
end
function EAtt(l,r,u,d)--enemy attack
local p=pla local c=cam
if not p.inv and p.x+4>l and p.x+4<r and p.y+4>u and p.y+4<d then
sfx(52,'e-4',10)
shake=20 c.sh=true
effDam(p.x+4,p.y+4)
p.hl=p.hl-1
p.inv=true
return true
end
end
function EAtt2()
local p=pla local c=cam
sfx(52,'e-4',10)
shake=20 c.sh=true
effDam(p.x+4,p.y+4)
p.hl=p.hl-1
p.inv=true
end
function EDam(x,y,w,h,dam)--enemy damage
local u=y local d=y+h local l=x local r=x+w
--sword
local sl=slh
for i,sw in pairs(sl) do
return not dam and sw.x-2<r and sw.x+10>l and sw.y<d and sw.y+8>u
end
--arrow
local ar=arw
for j,ar in pairs(ar) do
if not dam and ar.x>l and ar.x<r and ar.y>u and ar.y<d then
table.remove(arw,j)return true
end
end
end
function EDed(mx,my)--enemy dead
local c=cam
sfx(51,'d-3',30)
shake=20 c.sh=true
for i=0,360,45 do effExplod(mx,my,i) end
end
function EWipe(x,y,h)--wipe enemy
local p=pla
return h<0 or p.x<x-240 or p.x>x+240 or p.y<y-136 or p.y>y+136
end
function Spawn(mx,my,me)
local s={
x=mx*8,
y=my*8,
e=me,--enemy
a=false--active
}
spw[#spw+1]=s
end
function drawSpawn()
local p=pla local c=cam local sp=spw
for j,s in pairs(sp) do
if p.x>s.x-240 and p.x<s.x+240 and p.y>s.y-136 and p.y<s.y+136 then
if not s.a then
if s.e==0 then EBug(s.x,s.y)
elseif s.e==1 then EFly(s.x,s.y)
elseif s.e==2 then EHedg(s.x,s.y)
elseif s.e==3 then EGolem(s.x,s.y)
elseif s.e==4 then ECGolem(s.x,s.y)
end
s.a=true
end
else s.a=false end
if p.hl==0 then spw[j]=nil end
end
end
function EBug(mx,my)
local e={
x=mx,
y=my,
vx=.3,
sp=212,--sprite
an=0,--animation
h=1,--health
t=0,--time
d=false--damage
}
ebg[#ebg+1]=e
end
function drawEBug()
local t=tim local p=pla local c=cam local bg=ebg
for i,e in pairs(bg) do
local u=e.y local d=e.y+9 local l=e.x local r=e.x+8
--movement
if ESolid(l,r,u,d) then e.vx=e.vx*-1 end
e.x=e.x+e.vx
--draw
spr(e.sp+e.an,e.x+c.x,e.y+c.y,0)
--attack
EAtt(l,r,u,d)
--damage
if EDam(l,u,8,8,e.d) then e.h=e.h-1 e.d=true end
if e.d then
e.t=e.t+1 e.an=0 e.sp=214
if e.t>12 then e.d=false end
else e.an=t.an%24//12 e.sp=212 e.t=0
end
--dead
if e.h<0 then EDed(l,u) end
if EWipe(e.x,e.y,e.h) then table.remove(ebg,i) end
if p.hl==0 then ebg[i]=nil end
end
end
function EFly(mx,my)
local e={x=mx,y=my,an=0,h=1,d=false}
efl[#efl+1]=e
end
function drawEFly()
local t=tim local p=pla local c=cam local fl=efl
for i,e in pairs(fl) do
local u=e.y+2 local d=e.y+6 local l=e.x+4 local r=e.x+6
--movement
local dx=p.x-e.x local dy=p.y-e.y local sqrt=math.sqrt
local dist=sqrt((dx*dx)+(dy*dy))
if p.x>e.x-96 and p.x<e.x+96 and p.y>e.y-16 and p.x<e.x+96 then
e.x=e.x+(dx/dist*.5)e.y=e.y+(dy/dist*.5)
e.an=t.an%10//5
end
--draw
spr(215+e.an,e.x+c.x,e.y+c.y,0)
--attack
EAtt(l,r,u,d)
--damage
if EDam(l,u,8,8,e.d) then e.h=e.h-1 EDed(l,u) end
--dead
if EWipe(e.x,e.y,e.h) then table.remove(efl,i) end
if p.hl==0 then efl[i]=nil end
end
end
function EHgBul(mx,my,ma)
local b={x=mx,y=my,a=ma,t=0}
bhg[#bhg+1]=b
end
function drawEHgBul()
local t=tim local c=cam local bg=bhg local p=pla
local rad=math.rad local sin=math.sin local cos=math.cos
for i,l in pairs(bg) do
local u=l.y-1 local d=l.y+3 local le=l.x-1 local r=l.x+3
--movement
local dir=rad(l.a)
l.x=l.x+sin(dir)*.7
l.y=l.y-cos(dir)*.7
--draw
circ(l.x+c.x,l.y+c.y,2,11)
--attack
EAtt(le,r,u,d)
--remove
if solid(l.x,l.y) then table.remove(bhg,i) end
if p.hl==0 then bhg[i]=nil end
end
end
function EHedg(mx,my)
local e={x=mx,y=my,vx=.3,f=0,h=1,t=0}
ehg[#ehg+1]=e
end
function drawEHedg()
local t=tim local p=pla local c=cam local hg=ehg
for i,e in pairs(hg) do
local u=e.y-1 local d=e.y+9 local l=e.x local r=e.x+8
if solid(l,u) then f=2
elseif solid(l,d) then f=0 end
--movement
if f==2 and ESolid(l,r,u,u) then e.vx=e.vx*-1 end
if f==0 and ESolid(l,r,u,d) then e.vx=e.vx*-1 end
e.x=e.x+e.vx
--draw
spr(232+t.an%24//12,e.x+c.x,e.y+c.y,0,1,f)
--attack
e.t=e.t+1
if e.t==60*5 then
for i=0,360,45 do EHgBul(l+4,u+4,i) end
e.t=0
end
EAtt(l,r,u,d)
--damage
if EDam(l,u,8,8,e.d) then e.h=e.h-1 EDed(l,u) end
--dead
if EWipe(e.x,e.y,e.h) then table.remove(ehg,i) end
if p.hl==0 then ehg[i]=nil end
end
end
function SSoul(mx,my)
local s={x=mx*8,y=my*8,t=0,a=false}
ssl[#ssl+1]=s
end
function drawSSoul()
local p=pla local c=cam local ss=ssl
for j,s in pairs(ss) do
--spawn soul
if p.x>s.x-120 and p.x<s.x+120 and p.y>s.y-64 and p.y<s.y+32 then
if not s.a then ESoul(s.x,s.y) end
s.a=true
else a=false end
if s.a then s.t=s.t+1
if s.t==60*5 then ESoul(s.x,s.y) s.t=0 end
else s.a=false end
--draw
spr(217,s.x+c.x,s.y+c.y,0)
--remove
if p.hl==0 then ssl[j]=nil end
end
end
function ESoul(mx,my)
local e={x=mx,y=my,h=1,f=0,d=false}
esl[#esl+1]=e
end
function drawESoul()
local t=tim local p=pla local c=cam local sl=esl
for i,e in pairs(sl) do
local u=e.y+2 local d=e.y+6 local l=e.x+4 local r=e.x+6
--movement
local dx=p.x-e.x local dy=p.y-e.y local sqrt=math.sqrt
local dist=sqrt((dx*dx)+(dy*dy))
e.x=e.x+(dx/dist)
e.y=e.y+(dy/dist)
--draw
if p.x>e.x+4 then e.f=0
else e.f=1 end
spr(228+t.an%24//6,e.x+c.x,e.y+c.y,0,1,e.f)
--attack
if EAtt(l,r,u,d) then table.remove(esl,i) end
--damage
if EDam(l,u,8,8,e.d) then e.h=e.h-1 EDed(l,u) end
--dead
if EWipe(e.x,e.y,e.h) then table.remove(esl,i) end
if p.hl==0 or bos2Ded then esl[i]=nil end
end
end
function EGolem(mx,my)
local e={
x=mx,
y=my,
sp=256,--sprite
f=0,--flip
h=55,--health
ta=0,--time attack
td=0,--time damage
te=0,--time explode
c=0,--collision
d=false--damage
}
glm[#glm+1]=e
end
function drawEGolem()
local t=tim local p=pla local c=cam local gl=glm
for i,e in pairs(gl) do
local u=e.y local d=e.y+32 local l=e.x local r=e.x+32
--draw
if p.x>l+16 then e.f=0 e.c=32
else e.f=1 e.c=0 end
spr(e.sp,e.x+c.x,e.y+c.y,6,1,e.f,0,4,4)
--attack
if p.x+4>l+14 and p.x+4<r-14 and p.y+4>u and p.y+4<d then EAtt2()end
e.ta=e.ta+1
if e.ta>60*2 and e.ta<60*3 then e.sp=260
elseif e.ta>60*3 and e.ta<60*3.5 then e.sp=264 EAtt(l-8,r+8,u,d)
elseif e.ta==60*3.5 then e.ta=0
else e.sp=256 end
--damage
if EDam(l+8,u,16,32,e.d) then effDam(l+16,u+16) e.h=e.h-1 e.d=true end
if e.d then
e.td=e.td+1
if e.td>12 then e.d=false end
else e.td=0 end
--dead
if e.h<0 then
e.te=e.te+1
if e.te==15 then EDed(l+16,u+16)
elseif e.te==30 then EDed(l+16,u+16)
elseif e.te==45 then EDed(l+16,u+16)table.remove(glm,i)
end
end
if p.x<l-240 or p.x>l+240 or p.y<u-136 or p.y>u+136 then table.remove(glm,i) end
if p.hl==0 then glm[i]=nil end
end
end
function EGPower(mx,my,mf)
local e={x=mx,y=my,vx=0,f=mf,t=0}
gpw[#gpw+1]=e
end
function drawEGPower()
local t=tim local p=pla local c=cam local pw=gpw
for i,e in pairs(pw) do
local u=e.y+8 local d=e.y+17 local l=e.x local r=e.x+16
if e.f==0 then e.vx=2
else e.vx=-2 end
e.x=e.x+e.vx
--draw
spr(364+t.an%10//5*2,e.x+c.x,e.y+c.y,0,1,e.f,0,2,2)
--attack
EAtt(l,r,u,d)
--remove
e.t=e.t+1
if e.t==60*2 or solid(l,u+1) or solid(r,u+1) or not solid(l,d) or not solid(r,d) then
table.remove(gpw,i)
end
if p.hl==0 then gpw[i]=nil end
end
end
function ECGolem(mx,my)
local e={
x=mx,
y=my,
sp=320,--sprite
f=0,--flip
h=55,--health
ta=0,--time attack
td=0,--time damage
te=0,--time explode
c=0,--collision
d=false--damage
}
clm[#clm+1]=e
end
function drawECGolem()
local t=tim local p=pla local c=cam local gl=clm
for i,e in pairs(gl) do
local u=e.y local d=e.y+32 local l=e.x local r=e.x+32
--draw
if p.x>l+16 then e.f=0 e.c=32
else e.f=1 e.c=0 end
spr(e.sp,e.x+c.x,e.y+c.y,6,1,e.f,0,4,4)
--attack
if p.x+4>l+14 and p.x+4<r-14 and p.y+4>u and p.y+4<d then EAtt2()end
e.ta=e.ta+1
if e.ta>60*2 and e.ta<60*3 then e.sp=324
elseif e.ta==60*3 then EGPower(l+16,u+16,e.f)
elseif e.ta>60*3 and e.ta<60*3.5 then e.sp=328 EAtt(l-8,r+8,u,d)
elseif e.ta==60*3.5 then e.ta=0
else e.sp=320 end
--damage
if EDam(l+8,u,16,32,e.d) then effDam(l+16,u+16) e.h=e.h-1 e.d=true end
if e.d then
e.td=e.td+1
if e.td>12 then e.d=false end
else e.td=0 end
--dead
if e.h<0 then
e.te=e.te+1
if e.te==15 then EDed(l+16,u+16)
elseif e.te==30 then EDed(l+16,u+16)
elseif e.te==45 then EDed(l+16,u+16)table.remove(clm,i)
end
end
if p.x<l-240 or p.x>l+240 or p.y<u-136 or p.y>u+136 then table.remove(clm,i) end
if p.hl==0 then clm[i]=nil end
end
end
function EBos1(mx,my)
local e={
x=mx*8,
y=my*8,
vx=.7,
vy=0,
dx=1,
sp=218,--sprite
f=0,--flip
h=33,--health
ts=0,--time shoot
tg=0,--time gravity
te=0,--time explode
a=false,--active
d=false,--damage
gr=true--gravity
}
bos1[#bos1+1]=e
end
function drawEBos1()
local t=tim local p=pla local c=cam local bo=bos1
for i,e in pairs(bo) do
if p.x>1440 and p.x<1680 and p.y>816 and p.y<952 then
local u=e.y local d=e.y+16 local l=e.x local r=e.x+16
--movement
if solid(l,u+8) or solid(r,u+8) then e.vx=e.vx*-1 end
e.x=e.x+e.vx
if e.vx>0 then e.dx=1
elseif e.vx<0 then e.dx=-1
else e.dx=e.dx end
--gravity
e.tg=e.tg+1
if e.tg==60*12 then
if e.gr then e.f=2 e.y=e.y-5 e.gr=false
else e.f=0 e.y=e.y+5 e.gr=true end
e.tg=0
end
if solid(l+8,d) or solid(l+8,u-4) then e.vy=0
else
if e.gr then e.vy=e.vy+0.1
else e.vy=e.vy-0.1 end
end
e.y=e.y+e.vy
--draw
spr(e.sp+t.an%18//6*2,e.x+c.x,e.y+c.y,0,1,e.f,0,2,2)
--attack
e.ts=e.ts+1
if e.ts>60*7 and e.ts<60*7.9 then e.vx=0
elseif e.ts==60*8 then
for i=0,360,45 do EHgBul(l+8,u+12,i) end
elseif e.ts>60*9 then e.vx=.7*e.dx e.ts=0
end
EAtt(l+2,r-2,u+2,d)
--damage
if EDam(l,u,16,16,e.d) then effDam(l+8,u+8)e.h=e.h-1 e.d=true end
if e.d then
e.td=e.td+1
if e.td>12 then e.d=false end
else e.td=0 end
--dead