-
Notifications
You must be signed in to change notification settings - Fork 26
/
enemytool.lua
453 lines (436 loc) · 13.4 KB
/
enemytool.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
enemytool = class:new()
function enemytool:init(x, y, r, e)
self.cox = x
self.coy = y
self.x = x-1
self.y = y-1
self.r = r
self.customenemy = true
self.animation = false
self.spawnonlyonscreen = false
if e:find("|") then
local v = convertr(e, {"string", "num", "num", "bool", "string", "bool"}, true)
self.enemy = v[1]
self.xvel = v[2]
self.yvel = v[3]
if v[4] == nil then
self.legacy = true
if tablecontains(customenemies, self.enemy) then
self.customenemy = true
else
self.customenemy = false
end
else
self.customenemy = v[4]
end
if v[5] and v[5] ~= "none" then
self.animation = v[5]
end
if v[6] ~= nil then
self.spawnonlyonscreen = v[6]
end
else
self.enemy = e or "goomba"
self.legacy = true
self.xvel = 0
self.yvel = 0
end
self:translateenemy()
self.drawable = false
self.linked = false
self.pass = false
self.outtable = {}
self.timer = 0
if self.animation == "cannon" then
self.time = math.random(bulletbilltimemin*10, bulletbilltimemax*10)/10
elseif self.animation == "pipeup" or self.animation == "pipedown" or self.animation == "pipeleft" or self.animation == "piperight" then
self.pipe = true
self.spawned = {}
self.spawnmax = math.huge
self.timer = pipespawndelay/2
end
--is it supersized?
if ismaptile(x, y) and map[x][y]["argument"] then
if map[x][y]["argument"] == "b" then --supersized
self:dosupersize()
self.supersized = 2
end
end
end
function enemytool:update(dt)
if (not self.linked) and onscreen(self.x-2, self.y-2, 4, 4) then
--automatic spawning
if self.pipe then
local cx, cy, cw, ch = self.x, self.y, 2, 1
if self.animation == "pipeleft" or self.animation == "piperight" then
cx, cy, cw, ch = self.x, self.y-1, 1, 2
end
if #self.spawned > 0 then
--only have one object spawned
local delete = {}
for i, v in pairs(self.spawned) do
if v.delete then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(self.spawned, v) --remove
end
end
if #self.spawned < self.spawnmax then
local col = checkrect(cx, cy, cw, ch, {"player"}, nil)
if #col == 0 then
self.timer = self.timer + dt
while self.timer > pipespawndelay do
self:spawn()
self.timer = self.timer - pipespawndelay
end
end
end
elseif self.animation == "cannon" then
local cx, cy, cw, ch = self.x-1, self.y-6, 3, 12
local col = checkrect(cx, cy, cw, ch, {"player"}, nil)
if #col == 0 then
self.timer = self.timer + dt
while self.timer > self.time do
self:spawn()
self.timer = self.timer - pipespawndelay
self.time = math.random(bulletbilltimemin*10, bulletbilltimemax*10)/10
end
end
end
end
end
function enemytool:link()
if #self.r > 3 then
for j, w in pairs(outputs) do
for i, v in pairs(objects[w]) do
if tonumber(self.r[5]) == v.cox and tonumber(self.r[6]) == v.coy then
v:addoutput(self)
self.linked = true
end
end
end
end
end
function enemytool:input(t)
if t == "on" then
if not self.pass then
self:spawn()
self.pass = true
end
elseif t == "off" then
self.pass = false
elseif t == "toggle" then
self:spawn()
end
end
function enemytool:spawn()
local i = self.enemy
local x = self.cox
local y = self.coy
local dir = "left"
if self.xvel > 0 then
dir = "right"
end
--if objects["player"][1].x < self.cox then
-- dir = "left"
--end
if i == nil then
return false
end
if self.spawnonlyonscreen and not onscreen(self.x-2, self.y-2, 4, 4) then
return false
end
--backwards compatibility fuck
if (not self.customenemy) and self.legacy then
if i == "red koopa" then
i = "koopared"
elseif i == "buzzy beetle" then
i = "beetle"
elseif i == "flying koopa" then
i = "koopaflying"
elseif i == "cheep cheep" then
i = "cheepred"
elseif i == "white cheep" then
i = "cheepwhite"
elseif i == "spiny" then
i = "spikey"
elseif i == "spiny shell" then
i = "spikeyshell"
elseif i == "lakitu" then
i = "lakito"
elseif i == "blooper" then
i = "squid"
elseif i == "crab" then
i = "sidestepper"
elseif i == "bigicicle" then
i = "iciclebig"
elseif i == "angry sun" or i == "sun" then
i = "angrysun"
elseif i == "pumpkin" then
i = "splunkin"
elseif i == "big goomba" then
i = "biggoomba"
elseif i == "big spikey" then
i = "bigspikey"
elseif i == "big koopa" then
i = "bigkoopa"
elseif i == "dry bones" then
i = "drybones"
elseif i == "big beetle" then
i = "bigbeetle"
elseif i == "dry goomba" then
i = "drygoomba"
elseif i == "bob omb" then
i = "bomb"
elseif i == "boom boom" then
i = "boomboom"
elseif i == "? ball" then
i = "levelball"
elseif i == "blue koopa" then
i = "koopablue"
elseif i == "flying koopa 2" then
i = "koopaflying2"
elseif i == "pink squid" then
i = "pinksquid"
elseif i == "rip van fish" then
i = "sleepfish"
elseif i == "shy guy" then
i = "shyguy"
elseif i == "hammer bro" then
i = "hammerbro"
elseif i == "boomerang bro" then
i = "boomerangbro"
elseif i == "fire bro" then
i = "firebro"
elseif i == "down plant" then
i = "downplant"
elseif i == "venus firetrap" then
i = "fireplant"
elseif i == "torpedo ted" then
i = "torpedolauncher"
elseif i == "podoboo" then
i = "upfire"
elseif i == "dk hammer" then
i = "dkhammer"
elseif i == "bony beetle" then
i = "drybeetle"
elseif i == "beetle shell" then
i = "beetleshell"
elseif i == "smb3 bowser" then
i = "bowser3"
end
end
--actually spawn the enemy
local obj, wasenemy, objtable
if self.customenemy and tablecontains(customenemies, i) then
obj = enemy:new(x, y, i)
--turn in the right direction
if obj and self.animation == "piperight" and (not obj.dontmirror) then
obj.animationdirection = "left"
elseif obj and self.animation == "pipeleft" and (not obj.dontmirror) then
obj.animationdirection = "right"
end
table.insert(objects["enemy"], obj)
elseif i == "groundmole" or i == "ground mole" then
obj = mole:new(x-0.5, y-1/16)
table.insert(objects["mole"], obj)
elseif i == "mole" or i == "monty mole" then
obj = mole:new(x-0.5, y-1/16)
table.insert(objects["mole"], obj)
obj.width = 12/16
obj.height = 12/16
obj.quad = molequad[spriteset][3]
obj.gravity = yacceleration
obj.mask = { true,
false, false, false, false, true,
false, true, false, true, false,
false, false, true, false, false,
true, true, false, false, false,
false, true, true, false, false,
true, false, true, true, true}
obj.inground = false
elseif i == "bowser" then
obj = bowser:new(x-4, y-1/16)
table.insert(objects["bowser"], obj)
elseif i == "bowserfire" then
obj = fire:new(x,y)
table.insert(objects["fire"], obj)
elseif i == "bulletbillsingle" or i == "bulletbill" or i == "bullet bill" then
obj = bulletbill:new(x, y, dir)
table.insert(objects["bulletbill"], obj)
elseif i == "bulletbill right" then
table.insert(objects["bulletbill"], bulletbill:new(x, y, "right"))
elseif i == "bulletbill left" then
table.insert(objects["bulletbill"], bulletbill:new(x, y, "left"))
elseif i == "bigbillsingle" or i == "bigbill" or i == "banzai bill" then
obj = bigbill:new(x, y, dir)
table.insert(objects["bigbill"], obj)
elseif i == "banzai bill left" or i == "bigbillleft" or i == "big bill left" or i == "bigbill left" then
table.insert(objects["bigbill"], bigbill:new(x, y, "left"))
elseif i == "bigbillright" or i == "bigbill right" or i == "banzai bill right" or i == "big bill right" then
table.insert(objects["bigbill"], bigbill:new(x, y, "right"))
elseif i == "kingbill" or i == "king bill" then
table.insert(objects["kingbill"], kingbill:new(xscroll-200/16, y))
elseif i == "cannonballsingle" or i == "cannonball" or i == "cannon ball" then
table.insert(objects["cannonball"], cannonball:new(x, y, "left"))
elseif i == "hammer" then
if dir == "left" then
obj = hammer:new(x-1-5/16, y, "left")
else
obj = hammer:new(x, y, "right")
end
table.insert(objects["hammer"], obj)
elseif i == "brofireball" then
obj = brofireball:new(x-1, y-1, dir)
table.insert(objects["brofireball"], obj)
elseif i == "broboomerang" then
obj = boomerang:new(x-1, y-1, dir)
table.insert(objects["boomerang"], obj)
elseif i == "broiceball" then
obj = brofireball:new(x-1, y-1, dir, "ice")
table.insert(objects["brofireball"], obj)
elseif i == "flyingfish" or i == "jumping fish" then
obj = flyingfish:new()
table.insert(objects["flyingfish"], obj)
elseif i == "meteor" then
obj = meteor:new()
table.insert(objects["meteor"], obj)
elseif i == "turretleft" or i == "turret left" then
table.insert(objects["turret"], turret:new(x, y, "left"))
elseif i == "turretright" or i == "turret" or i == "turret right" then
table.insert(objects["turret"], turret:new(x, y, "right"))
elseif i == "turret2left" or i == "defective turret left" then
table.insert(objects["turret"], turret:new(x, y, "left", "turret2"))
elseif i == "turret2right" or i == "defective turret" then
table.insert(objects["turret"], turret:new(x, y, "right", "turret2"))
elseif i == "spring" then
table.insert(objects["spring"], spring:new(x, y, nil))
elseif i == "moving spring" then
table.insert(objects["spring"], spring:new(x, y, nil, true))
elseif i == "greenspring" or i == "green spring" then
table.insert(objects["spring"], spring:new(x, y, "green"))
elseif i == "moving greenspring" or i == "moving green spring" then
table.insert(objects["spring"], spring:new(x, y, "green", true))
elseif i == "spike snow" then
obj = spike:new(x-0.5, y-1/16, "snow")
table.insert(objects["spike"], obj)
elseif i == "snowball" then
obj = spikeball:new(x-0.5, y, "snow", "left", true)
table.insert(objects["spikeball"], obj)
elseif i == "koopaling" then
table.insert(objects["koopaling"], koopaling:new(x-0.5, y-1/16, 1))
elseif i == "koopaling2" then
table.insert(objects["koopaling"], koopaling:new(x-0.5, y-1/16, 2))
elseif i == "koopaling3" then
table.insert(objects["koopaling"], koopaling:new(x-0.5, y-1/16, 3))
elseif i == "koopaling4" then
table.insert(objects["koopaling"], koopaling:new(x-0.5, y-1/16, 4))
elseif i == "koopaling5" then
table.insert(objects["koopaling"], koopaling:new(x-0.5, y-1/16, 5))
elseif i == "koopaling6" then
table.insert(objects["koopaling"], koopaling:new(x-0.5, y-1/16, 6))
elseif i == "koopaling7" then
table.insert(objects["koopaling"], koopaling:new(x-0.5, y-1/16, 7))
elseif i == "box" then --change to enemy? (be wary of region triggers)
obj = box:new(x, y)
table.insert(objects["box"], obj)
elseif i == "box2" then
obj = box:new(x, y, "box2")
table.insert(objects["box"], obj)
elseif i == "edgelessbox" then
obj = box:new(x, y, "edgeless")
table.insert(objects["box"], obj)
elseif i == "coin" then
if self.animation then
obj = tilemoving:new(x, y, 116)
table.insert(objects["tilemoving"], obj)
else
objects["coin"][tilemap(x, y)] = coin:new(x, y)
end
elseif i == "spikeyfall" then
obj = goomba:new(self.x+6/16, self.y, "spikeyfall")
table.insert(objects["goomba"], obj)
elseif i == "gel1" then
obj = gel:new(self.x+1, self.y+1, 1)
table.insert(objects["gel"], obj)
elseif i == "gel2" then
obj = gel:new(self.x+1, self.y+1, 2)
table.insert(objects["gel"], obj)
elseif i == "gel3" then
obj = gel:new(self.x+1, self.y+1, 3)
table.insert(objects["gel"], obj)
elseif i == "gel4" then
obj = gel:new(self.x+1, self.y+1, 4)
table.insert(objects["gel"], obj)
elseif i == "gelcleanse" then
obj = gel:new(self.x+1, self.y+1, 5)
table.insert(objects["gel"], obj)
else
obj, wasenemy, objtable = spawnenemy(i, x, y, false, "spawner")
--turn in the right direction
if obj and dir == "right" and obj.animationdirection then
if obj.animationdirection == "right" then
obj.animationdirection = "left"
else
obj.animationdirection = "right"
end
end
end
if obj then
if self.supersized and (not self.customenemy) then
for n, t in pairs(entitylist) do
if i == t.t and t.supersize then --is the enemy supersizable?
supersizeentity(obj)
end
end
end
if obj.speedx then
if self.animation == "cannon" and self.xvel == 0 then
--default cannon
local pl = 1
for i = 2, players do
if math.abs(objects["player"][i].x+objects["player"][i].width/2 - (self.cox-.5))
< math.abs(objects["player"][pl].x+objects["player"][pl].width/2 - (self.cox-.5)) then
pl = i
end
end
if objects["player"][pl].x+objects["player"][pl].width/2 > (self.cox-.5) then
obj.speedx = obj.speedx+bulletbillspeed
else
obj.speedx = obj.speedx-bulletbillspeed
end
obj.speedy = obj.speedy+self.yvel
else
obj.speedx = obj.speedx+self.xvel
obj.speedy = obj.speedy+self.yvel
end
end
if self.pipe and obj.pipespawnmax then
self.spawnmax = obj.pipespawnmax
table.insert(self.spawned, obj)
end
if self.animation == "poof" then
makepoof(obj.x+obj.width/2, obj.y+obj.height/2, "powpoof")
elseif self.animation then
if obj.width and obj.height and (not obj.children) and (not obj.child) and not (obj.nospawnanimation) then
table.insert(spawnanimations, spawnanimation:new(self.cox, self.coy, self.animation, obj))
end
else
--track
if objtable and obj.width and obj.height then
trackobject(self.cox, self.coy, obj, objtable)
end
end
end
end
function enemytool:translateenemy()
local t = self.enemy
if t == "? ball" then
self.enemy = "levelball"
end
end
function enemytool:dosupersize()
end