forked from KirbyKid256/mari0_aces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.lua
4070 lines (3743 loc) · 121 KB
/
enemy.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
--Some SE functions (Also keep track of AE ADDITION s)
local function twistdirection(gravitydir, dir) --mario.lua
if not gravitydir or (gravitydir > math.pi/4*1 and gravitydir <= math.pi/4*3) then
if dir == "floor" then
return "floor"
elseif dir == "left" then
return "left"
elseif dir == "ceil" then
return "ceil"
elseif dir == "right" then
return "right"
end
elseif gravitydir > math.pi/4*3 and gravitydir <= math.pi/4*5 then
if dir == "floor" then
return "left"
elseif dir == "left" then
return "ceil"
elseif dir == "ceil" then
return "right"
elseif dir == "right" then
return "floor"
end
elseif gravitydir > math.pi/4*5 and gravitydir <= math.pi/4*7 then
if dir == "floor" then
return "ceil"
elseif dir == "left" then
return "right"
elseif dir == "ceil" then
return "floor"
elseif dir == "right" then
return "left"
end
else
if dir == "floor" then
return "right"
elseif dir == "left" then
return "floor"
elseif dir == "ceil" then
return "left"
elseif dir == "right" then
return "ceil"
end
end
end
local function unwrap(a)
while a < 0 do
a = a + (math.pi*2)
end
while a > (math.pi*2) do
a = a - (math.pi*2)
end
return a
end
local function angles(a1, a2)
local a1 = unwrap(a1)-math.pi
local a2 = unwrap(a2)-math.pi
local diff = a1-a2
if math.abs(diff) < math.pi then
return a1 > a2
else
return diff < 0
end
end
local function anglesdiff(a1, a2)
local a1 = unwrap(a1)-math.pi
local a2 = unwrap(a2)-math.pi
return math.abs(a1-a2) --diff
end
enemy = class:new()
function enemy:init(x, y, t, a, properties)
if not enemiesdata[t] then
return nil
end
self.t = t
if a then
self.a = {unpack(a)}
else
self.a = {}
end
--Some standard values..
self.rotation = 0
self.active = true
self.static = false
self.mask = {}
self.gravitydirection = math.pi/2
self.combo = 1
self.falling = false
self.shot = false
self.outtable = {}
self.speedx = 0
self.speedy = 0
--Get our enemy's properties from the property table
for i, v in pairs(enemiesdata[self.t]) do
self[i] = v
end
if properties then
for i, v in pairs(properties) do
self[i] = v
end
end
-- update qaud if quadno is changed, better than running the same check 10 times
local oldqaudno = (self.quadno or 1)
--right click menu
if self.rightclickmenu and self.a[3] then
local s = tostring(self.a[3])
if self.rightclickmenutable then
if tonumber(self.a[3]) then
self.a[3] = tonumber(self.a[3])
end
if self.rightclickmenumultipleproperties then
local t = self.rightclickmenu[self.a[3]]
if t then
for i, v in pairs(t) do
local name = v[1]
local value = v[2]
if type(value) == "table" then
self[name] = deepcopy(value)
else
self[name] = value
end
end
elseif testinglevel then
notice.new("No rightclickmenu entry\nfor number:" .. tostring(self.a[3]), notice.red, 3)
end
else
if type(self.rightclickmenu[self.a[3]]) == "table" then
self[self.rightclickmenu[1]] = deepcopy(self.rightclickmenu[self.a[3]])
else
self[self.rightclickmenu[1]] = self.rightclickmenu[self.a[3]]
end
end
else
self.a[3] = s:gsub("B", "-")
if tonumber(self.a[3]) then
self.a[3] = tonumber(self.a[3])
end
if self.rightclickmenuboolean then
self[self.rightclickmenu[1]] = (self.a[3] == "true")
else
self[self.rightclickmenu[1]] = self.a[3]
end
end
end
--right click
if self.rightclick and #self.a > 0 then
self.a[3] = tostring(self.a[3]):gsub("B", "-")
local val
-- types
if self.rightclicktypes then
val = convertr(self.a[3], self.rightclicktypes)
else
local types = {}
local index = 0
for i = 1, #self.rightclick do
if self.rightclick[i][1] ~= "text" then
index = index + 1
if self.rightclick[i][1] == "dropdown" or self.rightclick[i][1] == "input" then
local var = self.a[3]:split("|")
if tonumber(var[index]) then
types[index] = "num"
else
types[index] = "string"
end
elseif self.rightclick[i][1] == "checkbox" then
types[index] = "bool"
end
end
end
val = convertr(self.a[3], types)
end
-- actally convert
local index = 0
for i = 1, #self.rightclick do
if self.rightclick[i][1] ~= "text" then
index = index + 1
if type(self.rightclick[i][2]) == "table" then
local var = false
if self.rightclick[i][1] == "dropdown" then -- based on rightclickmenu
for b = 1, #self.rightclick[i][4] do
if self.rightclick[i][4][b] == val[index] or (tonumber(self.rightclick[i][4][b]) and tonumber(self.rightclick[i][4][b]) == val[index]) then
var = b
end
end
elseif self.rightclick[i][1] == "checkbox" then -- first list is for if true, second for if it is false
if val[index] == true then var = 1 else var = 2 end
elseif self.rightclick[i][1] == "input" then
notice.new("you can't use a list\nfor an input!", notice.red, 3)
end
for i, v in pairs(self.rightclick[i][2][var]) do
local name = v[1]
local value = v[2]
if (not self.casesensitive) and (name ~= "offsetX" and name ~= "offsetY" and name ~= "quadcenterX" and name ~= "quadcenterY") then
value = value:lower()
end
if type(value) == "table" then
self[name] = deepcopy(value)
else
self[name] = value
end
end
else
self[self.rightclick[i][2]] = val[index]
end
end
end
table.remove(self.a, 1)
end
-- if quadno is changed in either rightclick
if oldqaudno ~= self.quadno then
self.quad = self.quadgroup[self.quadno]
end
if self.customtimer then
self.customtimertimer = 0
self.currentcustomtimerstage = 1
end
--Decide on a random movement if it's random..
if self.movementrandoms then
self.movement = self.movementrandoms[math.random(#self.movementrandoms)]
end
self.x = x-.5-self.width/2+(self.spawnoffsetx or 0)
self.y = y-self.height+(self.spawnoffsety or 0)
if self.animationtype == "mirror" then
self.animationtimer = 0
self.animationdirection = "left"
elseif self.animationtype == "frames" then
self.quadi = self.animationstart
self.quad = self.quadgroup[self.quadi]
self.animationtimer = 0
if type(self.animationspeed) == "table" then
self.animationtimerstage = 1
end
elseif self.animationtype == "character" then
self.quadi = self.animationstart
self.quad = self.quadgroup[self.quadi]
self.animationtimer = 0
self.runanimationtimer = 0
end
if self.smallanimationstart and self.smallanimationframes then
self.smallanimationtimer = 0
self.smallanimationquadi = self.smallanimationstart
end
if self.stompanimation then
self.deathtimer = 0
end
if self.shellanimal then
self.upsidedown = false
self.resettimer = 0
self.wiggletimer = 0
self.wiggleleft = true
--self.returntilemaskontrackrelease = true
end
if self.customscissor then
self.customscissor = {unpack(self.customscissor)}
self.customscissor[1] = self.customscissor[1] + x - 1
self.customscissor[2] = self.customscissor[2] + y - 1
end
if self.starttowardsplayerhorizontal or self.startawayfromplayerhorizontal then --Prize for best property name
local closestplayer = 1
self.animationdirection = "right"
local closestdist = math.huge
for i = 1, #objects["player"] do
local v = objects["player"][i]
local dist = math.sqrt((v.x-self.x)^2+(v.y-self.y)^2)
if dist < closestdist then
closestdist = dist
closestplayer = i
end
end
if objects["player"][closestplayer] then
if objects["player"][closestplayer].x+objects["player"][closestplayer].width/2 < self.x+self.width/2 then
self.speedx = -math.abs(self.speedx)
if not self.dontmirror then --AE ADDITION
self.animationdirection = "right"
end
if self.movement == "homing" then
self.homingrotation = 0
end
else
self.speedx = math.abs(self.speedx)
if not self.dontmirror then --AE ADDITION
self.animationdirection = "left"
end
if self.movement == "homing" then
self.homingrotation = math.pi
end
end
if self.startawayfromplayerhorizontal then
self.speedx = -self.speedx
end
end
end
if self.killsenemiesonsides == nil then
self.killsenemiesonsides = true
end
if self.killsenemiesontop == nil then
self.killsenemiesontop = true
end
if self.killsenemiesonbottom == nil then
self.killsenemiesonbottom = true
end
if self.killsenemiesonleft == nil then
self.killsenemiesonleft = true
end
if self.killsenemiesonright == nil then
self.killsenemiesonright = true
end
if self.killsenemiesonpassive == nil then
self.killsenemiesonpassive = true
end
self.firstmovement = self.movement
self.firstanimationtype = self.animationtype
self.startoffsetY = self.offsetY
self.startquadcenterY = self.quadcenterY
self.startgravity = self.gravity
self.startx = self.x
self.starty = self.y
self.startactive = self.active
self.startdrawable = self.drawable
self.startkillsenemies = self.killsenemies
self.spawnallow = true
self.spawnedenemies = {}
if self.movement == "piston" then
self.pistontimer = self.pistonretracttime
self.pistonstate = "retracting"
if self.spawnonlyonextended then
self.spawnallow = false
end
elseif self.movement == "flyvertical" or self.movement == "flyhorizontal" then
self.flyingtimer = 0
self.startx = self.x
self.starty = self.y
elseif self.movement == "squid" then
self.squidstate = "idle"
elseif self.movement == "circle" then
self.startx = self.x
self.starty = self.y
if not self.circletimer then
self.circletimer = 0
end
elseif self.movement == "path" then
self.startx = self.x
self.starty = self.y
self.movementpathstep = 1
self.movementpathbackwards = false
elseif self.movement == "crawl" then
if self.crawlfloor == "up" then
self.gravity = -self.crawlgravity
self.gravityx = 0
if self.crawldirection == "left" then self.speedx = self.crawlspeed else self.speedx = -self.crawlspeed end
elseif self.crawlfloor == "left" then
self.gravity = 0
self.gravityx = -self.crawlgravity
if self.crawldirection == "left" then self.speedy = -self.crawlspeed else self.speedy = self.crawlspeed end
elseif self.crawlfloor == "right" then
self.gravity = 0
self.gravityx = self.crawlgravity
if self.crawldirection == "left" then self.speedy = self.crawlspeed else self.speedy = -self.crawlspeed end
else
self.gravity = self.crawlgravity
if self.crawldirection == "left" then self.speedx = -self.crawlspeed else self.speedx = self.crawlspeed end
self.gravityx = 0
end
self.ignorelowgravity = true
self.aroundcorner = false
elseif self.movement == "homing" then
if self.starthomingrotationtowardsplayer then --starting rotation is towards player
local closestplayer = 1 --find closest player
local relativex, relativey, dist
for i = 1, players do
local v = objects["player"][i]
relativex, relativey = (v.x + -self.x), (v.y + -self.y)
distance = math.sqrt(relativex*relativex+relativey*relativey)
if ((not dist) or (distance < dist)) and not v.dead then
closestplayer = i
end
end
local p = objects["player"][closestplayer]
if p then
local angle = -math.atan2((p.x+p.width/2)-(self.x+self.width/2), (p.y+p.height/2)-(self.y+self.height/2))-math.pi/2
self.homingrotation = unwrap(angle)
end
end
if self.upsidedownifhomingrotationright then
if (self.homingrotation >= math.pi*.5 and self.homingrotation <= math.pi*1.5) then
self.upsidedown = true
end
end
elseif self.movement == "chase" then
self.movedirection = "left"
self.movedirectiony = "left"
elseif self.movement == "shadow" then
self.shadowtable = {}
self.shadowrate = self.shadowrate or 0.2 --delay at which position of target is recorded
self.shadowlag = self.shadowlag or 1
self.shadowtimer = 0
if self.shadowinterpolate == nil then self.shadowinterpolate = true end
end
if self.speedxtowardsplayer or self.speedxawayfromplayer then
local closestplayer = 1
local closestdist = math.sqrt((objects["player"][1].x-self.x)^2+(objects["player"][1].y-self.y)^2)
for i = 2, players do
local v = objects["player"][i]
local dist = math.sqrt((v.x-self.x)^2+(v.y-self.y)^2)
if dist < closestdist then
closestdist = dist
closestplayer = i
end
end
if objects["player"][closestplayer].x + objects["player"][closestplayer].width/2 > self.x + self.width/2 then
self:leftcollide("", {}, "", {})
self.speedx = math.abs(self.speedx)
else
self:rightcollide("", {}, "", {})
self.speedx = -math.abs(self.speedx)
end
if self.speedxawayfromplayer then
self.speedx = -self.speedx
end
end
if self.lifetimerandoms then
self.lifetime = self.lifetimerandoms[math.random(#self.lifetimerandoms)]
end
if self.lifetime and self.lifetime >= 0 then
self.lifetimer = self.lifetime
end
if self.flickertime then
self.flickertimer = 0
end
if self.jumps then
self.jumptimer = 0
end
if self.spawnsenemy then
self.spawnenemytimer = 0
self.spawnenemydelay = self.spawnenemydelays[math.random(#self.spawnenemydelays)]
end
if self.bounces and (self.bouncedelay or self.bouncedelays) then
self.bouncetimer = 0
if self.bouncedelays then
if self.bouncedelaysrandoms then
self.bouncedelay = self.bouncedelays[math.random(#self.bouncedelays)]
else
self.bouncetimerstage = 1
self.bouncedelay = self.bouncedelays[self.bouncetimerstage]
end
end
end
self.throwanimationstate = 0
if self.chasetime then
self.chasetimer = 0
end
if self.spawnsound then
self:playsound(self.spawnsound)
end
if self.spawnchildren then
if not (self.a and self.a[1] == "ignorespawnchildren") then
for i = 1, #self.spawnchildren do
local offsetx = self.spawnchildrenoffsetx or 0
if type(self.spawnchildrenoffsetx) == "table" then
offsetx = self.spawnchildrenoffsetx[i]
end
local offsety = self.spawnchildrenoffsety or 0
if type(self.spawnchildrenoffsety) == "table" then
offsety = self.spawnchildrenoffsety[i]
end
local a = {"ignorespawnchildren"}
if self.childrencanspawnchildren then
a = {}
end
local temp = enemy:new(self.x+self.width/2+.5+offsetx, self.y+self.height+offsety, self.spawnchildren[i], a)
if self.spawnchildrenparent then
temp.parent = self
end
if self.supersizechildren and self.supersized then
supersizeentity(temp)
end
table.insert(objects["enemy"], temp)
end
end
end
if self.carryable then
self.rigidgrab = true
self.carryparent = false
self.userect = adduserect(self.x+self.carryrange[1], self.y+self.carryrange[2], self.carryrange[3], self.carryrange[4], self)
if self.throwntime then
self.throwntimer = 0
end
self.pickupready = false
self.pickupreadyplayers = {}
end
if self.jumps or self.noplayercollisiononthrow then
--make copy of mask table, otherwise it modifies it for every enemy
self.mask = deepcopy(self.mask)
end
if self.freezable == nil then
self.freezable = true --AE ADDITION
end
if self.movement == "circle" then
if self.circletimer ~= 0 then
local v = ((self.circletimer/(self.circletime or 1))*math.pi*2)
local newx = math.sin(v)*(self.circleradiusx or self.circleradius or 1) + self.startx
local newy = math.cos(v)*(self.circleradiusy or self.circleradius or 1) + self.starty
self.x = newx
self.y = newy
end
end
--snap position to tile grid
if self.snapxtogrid then
self.x = round(self.x)+(self.snapxtogridoffset or 0)
end
if self.snapytogrid then
self.y = round(self.y)+(self.snapytogridoffset or 0)
end
--platform collision (ignore side collisions without any callbacks)
if self.platformcollisionup then self.PLATFORM = true end
if self.platformcollisiondown then self.PLATFORMDOWN = true end
if self.platformcollisionleft then self.PLATFORMLEFT = true end
if self.platformcollisionright then self.PLATFORMRIGHT = true end
--block portals
if self.blockportaltile then
local t = {math.floor(x), math.floor(y)}
if type(self.blockportaltile) == "table" then
t = {math.floor(x)+math.floor(self.blockportaltile[1]), math.floor(y)+math.floor(self.blockportaltile[2])}
end
self.blockportaltilecoordinate = tilemap(t[1], t[2])
blockedportaltiles[self.blockportaltilecoordinate] = true
end
--trigger animation on spawnn
if self.animationtriggeronspawn or self.triggeranimationonspawn then
self:triggeranimation(self.animationtriggeronspawn or self.triggeranimationonspawn)
end
if self.transformenemyanimationonspawn then
transformenemyanimation(self.transformenemyanimationonspawn)
end
self.outtable = {}
end
function enemy:update(dt)
--Just spawned
if self.justspawned then
self.justspawned = nil
end
--Funnels and fuck
if self.funnel and not self.infunnel then
self:enteredfunnel(true)
end
if self.infunnel and not self.funnel then
self:enteredfunnel(false)
end
self.funnel = false
if self.flickertime and self.flickertimer then
self.flickertimer = self.flickertimer + dt
while self.flickertimer > self.flickertime do
self.flickertimer = self.flickertimer - self.flickertime
self.drawable = not self.drawable
end
end
if self.transformkill then
if self.transformkilldeath then
self:output()
else
self:output("transformed")
end
self.dead = true
return true
elseif self.kill then
self:output()
self.dead = true
return true
end
if self.stompanimation and self.dead then
self.deathtimer = self.deathtimer + dt
if self.deathtimer > (self.stompanimationtime or 0.5) then
self:output()
return true
else
return false
end
end
if (not self.doesntunrotate) and (not self.rotationanimation) and (not self.rollanimation) then
self.rotation = unrotate(self.rotation, self.gravitydirection, dt)
end
if self.shot then
self.speedy = self.speedy + shotgravity*dt
self.x = self.x+self.speedx*dt
self.y = self.y+self.speedy*dt
return false
end
if self.frozen then
return false
end
if self.lifetimer and not self.shot then
self.lifetimer = self.lifetimer - dt
if self.lifetimer <= 0 then
if self.transforms and self:gettransformtrigger("lifetime") then
self:transform(self:gettransformsinto("lifetime"))
end
self:output()
self.dead = true
return true
end
end
if self.rotationanimation then
self.rotation = self.rotation + (self.rotationanimationspeed or 1)*dt
end
if self.rollanimation then
self.rotation = self.rotation + self.speedx*math.pi*dt
end
local oldx, oldy
if self.platform or self.animationtype == "character" then
oldx, oldy = self.x, self.y
end
--water
if self.watergravity or self.waterdamping or (self.transforms and (self:gettransformtrigger("water") or self:gettransformtrigger("notinwater"))) then
--is the enemy in water?
local oldwater = self.water or false
self.water = underwater
if self.risingwater then
--how many frames since in water
self.risingwater = self.risingwater - 1
self.water = true
if self.risingwater < 0 then
self.risingwater = false
end
end
if not self.water then --water tiles
local x1 = math.floor(self.x)+1
local y1 = math.floor(self.y)+1
local dobreak = false
for x2 = math.max(1,x1), math.min(mapwidth,math.floor(self.x+self.width)+1) do
for y2 = math.max(1,y1), math.min(mapheight,math.floor(self.y+self.height)+1) do
if inmap(x2, y2) and tilequads[map[x2][y2][1]] and tilequads[map[x2][y2][1]].water then
dobreak = true
self.water = true
break
end
end
if dobreak then break end
end
end
if oldwater == false and self.water == true then --in water
self:dive(true)
if self.transforms and self:gettransformtrigger("water") then
self:transform(self:gettransformsinto("water"))
return
end
elseif oldwater == true and self.water == false then --not in water
if self.transforms and self:gettransformtrigger("notinwater") then
self:transform(self:gettransformsinto("notinwater"))
return
end
end
if self.watergravity then
if oldwater == false and self.water == true then
self.gravity = self.watergravity
elseif oldwater == true and self.water == false then
self.gravity = self.startgravity
end
end
if self.y+self.height < uwmaxheight and underwater and self.watergravity then
self.speedy = uwpushdownspeed
end
end
if self.float then
self.risingwater = false
end
if self.animationtype == "mirror" then
self.animationtimer = self.animationtimer + dt
while self.animationtimer > self.animationspeed do
self.animationtimer = self.animationtimer - self.animationspeed
if self.animationdirection == "left" then
self.animationdirection = "right"
else
self.animationdirection = "left"
end
end
elseif self.animationtype == "frames" then
self.animationtimer = self.animationtimer + dt
if type(self.animationspeed) == "table" then
while self.animationtimer > self.animationspeed[self.animationtimerstage] do
self.animationtimer = self.animationtimer - self.animationspeed[self.animationtimerstage]
self.quadi = self.quadi + 1
if self.quadi > self.animationstart + self.animationframes - 1 then
self.quadi = self.quadi - self.animationframes
end
self.quad = self.quadgroup[self.quadi]
self.animationtimerstage = self.animationtimerstage + 1
if self.animationtimerstage > #self.animationspeed then
self.animationtimerstage = 1
end
end
else
while self.animationtimer > self.animationspeed do
self.animationtimer = self.animationtimer - self.animationspeed
self.quadi = self.quadi + 1
if self.quadi > self.animationstart + self.animationframes - 1 then
self.quadi = self.quadi - self.animationframes
end
self.quad = self.quadgroup[self.quadi]
end
end
if not self.dontmirror then --AE ADDITION
if self.speedx > 0 then
self.animationdirection = "left"
elseif self.speedx < 0 then
self.animationdirection = "right"
end
end
end
if self.spawnsenemy then
if lakitoend and self.movement == "follow" and (not self.ignorelakitoend) then
self.speedx = -3
return false
end
local playernear = false
if self.dontspawnenemyonplayernear or self.spawnenemyonplayernear then
local dist = self.spawnenemydist or self.dontspawnenemydist or 3
if type(dist) == "table" then
local col = checkrect(self.x+dist[1], self.y+dist[2], dist[3], dist[4], {"player"})
if #col > 0 then
playernear = true
end
else
for i = 1, players do
local v = objects["player"][i]
if inrange(v.x+v.width/2, self.x+self.width/2-(dist), self.x+self.width/2+(dist)) then
playernear = true
break
end
end
end
if self.spawnenemyonplayernear then
playernear = not playernear
end
end
if (not playernear) then
self.spawnenemytimer = self.spawnenemytimer + dt
while self.spawnenemytimer >= self.spawnenemydelay and self.spawnallow and (not self.spawnmax or self:getspawnedenemies() < self.spawnmax) do
if self.spawnsenemyrandoms then
self.spawnsenemy = self.spawnsenemyrandoms[math.random(#self.spawnsenemyrandoms)]
end
self:spawnenemy(self.spawnsenemy)
self.spawnenemytimer = 0
self.spawnenemydelay = self.spawnenemydelays[math.random(#self.spawnenemydelays)]
self.throwanimationstate = 0
if self.animationtype == "frames" then
self.quad = self.quadgroup[self.quadi + self.throwanimationstate]
end
end
if self.throwpreparetime and self.spawnenemytimer >= (self.spawnenemydelay - self.throwpreparetime) then
self.throwanimationstate = self.throwquadoffset
if self.animationtype == "frames" then
self.quad = self.quadgroup[self.quadi + self.throwanimationstate]
end
end
end
end
if self.bounces and self.bouncedelay and (not self.falling) then
self.bouncetimer = self.bouncetimer + dt
if self.bouncetimer > self.bouncedelay then
local force = self.bounceforce
if type(self.bounceforce) == "table" then
if self.bouncetimerstage and not self.bounceforcerandom then
force = self.bounceforce[self.bouncetimerstage]
else
force = self.bounceforce[math.random(#self.bounceforce)]
end
end
self.speedy = -(force or 10)
self.bouncetimer = 0
if self.bouncetimerstage then
self.bouncetimerstage = self.bouncetimerstage + 1
if self.bouncetimerstage > #self.bouncedelays then
self.bouncetimerstage = 1
end
self.bouncedelay = self.bouncedelays[self.bouncetimerstage]
elseif self.bouncedelaysrandoms then
self.bouncedelay = self.bouncedelays[math.random(#self.bouncedelays)]
end
end
end
if self.movement == "truffleshuffle" then
if self.speedx > 0 then
if self.speedx > self.truffleshufflespeed then
self.speedx = self.speedx - self.truffleshuffleacceleration*dt*2
if self.speedx < self.truffleshufflespeed then
self.speedx = self.truffleshufflespeed
end
elseif self.speedx < self.truffleshufflespeed then
self.speedx = self.speedx + self.truffleshuffleacceleration*dt*2
if self.speedx > self.truffleshufflespeed then
self.speedx = self.truffleshufflespeed
end
end
else
if self.speedx < -self.truffleshufflespeed then
self.speedx = self.speedx + self.truffleshuffleacceleration*dt*2
if self.speedx > -self.truffleshufflespeed then
self.speedx = -self.truffleshufflespeed
end
elseif self.speedx > -self.truffleshufflespeed then
self.speedx = self.speedx - self.truffleshuffleacceleration*dt*2
if self.speedx < -self.truffleshufflespeed then
self.speedx = -self.truffleshufflespeed
end
end
end
if self.turnaroundoncliff and self.falling == false then
--check if nothing below
local x, y = math.floor(self.x + self.width/2+1), math.floor(self.y + self.height+1.5)
if inmap(x, y) and (not checkfortileincoord(x, y)) and ((inmap(x+.5, y) and checkfortileincoord(math.ceil(x+.5), y)) or (inmap(x-.5, y) and checkfortileincoord(math.floor(x-.5), y))) and (not (inmap(x,y-1) and objects["tile"][tilemap(x, y-1)] and objects["tile"][tilemap(x, y-1)].SLOPE)) then
if self.speedx < 0 then
self.x = x-self.width/2
else
self.x = x-1-self.width/2
end
self.speedx = -self.speedx
end
end
if edgewrapping then --wrap around screen
local minx, maxx = -self.width, mapwidth
if self.x < minx then
self.x = maxx
elseif self.x > maxx then
self.x = minx
end
end
elseif self.movement == "shell" then
if self.small then
if self.wakesup then
if math.abs(self.speedx) < 0.0001 then
self.resettimer = self.resettimer + dt
if self.resettimer > self.resettime then
self.offsetY = self.startoffsetY
self.quadcenterY = self.startquadcenterY
self.quad = self.quadgroup[self.animationstart]
self.small = false
self.speedx = -self.truffleshufflespeed
self.resettimer = 0
self.upsidedown = false
self.kickedupsidedown = false
self.movement = self.firstmovement
self.animationtype = self.firstanimationtype
if self.chasemarioonwakeup then
local px = objects["player"][getclosestplayer(self.x)].x --AE ADDITION (changed x to self.x)
if px > self.x then
self.speedx = -self.speedx
end
end
elseif self.resettimer > self.resettime-self.wiggletime then
self.wiggletimer = self.wiggletimer + dt
while self.wiggletimer > self.wiggledelay do
self.wiggletimer = self.wiggletimer - self.wiggledelay
if self.wiggleleft then
if self.wigglequad then
self.offsetY = self.wiggleoffsety or self.startoffsetY
self.quadcenterY = self.wigglequadcentery or self.startquadcenterY
if self.upsidedown then
self.offsetY = self.upsidedownwiggleoffsety or self.upsidedownoffsety or 4
self.quadcenterY = self.upsidedownwigglequadcentery or self.wigglequadcentery or self.upsidedownquadcentery or self.startquadcenterY
end
self.quad = self.quadgroup[self.wigglequad]
else
self.x = self.x + 1/16
end
else
if self.wigglequad then
self.offsetY = self.startoffsetY
self.quadcenterY = self.startquadcenterY
if self.upsidedown then
self.offsetY = self.upsidedownoffsety or 4
self.quadcenterY = self.upsidedownquadcentery or self.startquadcenterY
end
self.quad = self.quadgroup[self.smallquad]
else
self.x = self.x - 1/16
end
end
self.wiggleleft = not self.wiggleleft
end
end
else
self.resettimer = 0
end
end
if math.abs(self.speedx) >= 0.0001 then
--shell animation
if self.smallanimationstart and self.smallanimationframes and not self.kickedupsidedown then
self.smallanimationtimer = self.smallanimationtimer + dt
while self.smallanimationtimer > self.smallanimationspeed do
self.smallanimationtimer = self.smallanimationtimer - self.smallanimationspeed
self.smallanimationquadi = self.smallanimationquadi + 1
if self.smallanimationquadi > self.smallanimationstart + self.smallanimationframes - 1 then
self.smallanimationquadi = self.smallanimationquadi - self.smallanimationframes
end
self.quad = self.quadgroup[self.smallanimationquadi]
end
end
end
end
if edgewrapping then --wrap around screen
local minx, maxx = -self.width, mapwidth
if self.x < minx then
self.x = maxx
elseif self.x > maxx then
self.x = minx
end
end
elseif self.movement == "follow" then
local nearestplayer = 1
while objects["player"][nearestplayer] and objects["player"][nearestplayer].dead do
nearestplayer = nearestplayer + 1
end
if objects["player"][nearestplayer] then
local nearestplayerx = objects["player"][nearestplayer].x