-
Notifications
You must be signed in to change notification settings - Fork 28
/
fireball.lua
341 lines (301 loc) · 8.16 KB
/
fireball.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
fireball = class:new()
function fireball:init(x, y, dir, v, t)
--PHYSICS STUFF
self.y = y+4/16
self.speedy = 0
if dir == "right" then
self.speedx = fireballspeed
self.x = x+6/16
else
self.speedx = -fireballspeed
self.x = x
end
self.width = 8/16
self.height = 8/16
self.active = true
self.static = false
self.category = 13
self.mask = { true,
false, true, false, false, true,
false, true, false, true, false,
false, true, false, true, false,
true, true, false, false, false,
false, true, false, false, true,
false, false, false, false, true,
false, true}
self.destroy = false
self.destroysoon = false
self.t = t or "fireball"
--self.gravity = 40
self.releasespeedx = fireballspeed
--IMAGE STUFF
self.drawable = true
if self.t == "superball" then
self.graphic = superballimg
self.quad = superballquad[1]
self.offsetX = 4
self.offsetY = 4
self.quadcenterX = 6
self.quadcenterY = 6
self.gravity = 0
if dir == "right" then
self.speedx = superballspeed
else
self.speedx = -superballspeed
end
self.speedy = superballspeed
self.lifetime = 5
self.light = 2
elseif self.t == "iceball" then
self.graphic = iceballimg
self.quad = fireballquad[1]
self.offsetX = 4
self.offsetY = 4
self.quadcenterX = 4
self.quadcenterY = 4
self.hp = 2
if dir == "right" then
self.speedx = iceballspeed+(v.speedx*.5)
else
self.speedx = -iceballspeed+(v.speedx*.5)
end
self.gravity = 30
else
self.graphic = fireballimg
self.quad = fireballquad[1]
self.offsetX = 4
self.offsetY = 4
self.quadcenterX = 4
self.quadcenterY = 4
self.light = 2
self.lifetime = 10
end
self.fireballthrower = v
self.rotation = 0 --for portals
self.timer = 0
self.quadi = 1
end
function fireball:update(dt)
--rotate back to 0 (portals)
self.rotation = 0
--animate
self.timer = self.timer + dt
if self.t == "superball" then
--collect coins
local x = math.floor(self.x+self.width/2)+1
local y = math.floor(self.y+self.height/2)+1
if inmap(x, y) then
if tilequads[map[x][y][1]].coin then
collectcoin(x, y)
elseif objects["coin"][tilemap(x, y)] and not objects["coin"][tilemap(x, y)].frozen then
collectcoinentity(x, y)
elseif objects["collectable"][tilemap(x, y)] then
getcollectable(x, y)
end
end
elseif self.destroysoon == false then
while self.timer > staranimationdelay do
self.quadi = self.quadi + 1
if self.quadi == 5 then
self.quadi = 1
end
self.quad = fireballquad[self.quadi]
self.timer = self.timer - staranimationdelay
end
else
while self.timer > staranimationdelay do
self.quadi = self.quadi + 1
if self.quadi == 8 then
self.destroy = true
self.quadi = 7
end
self.quad = fireballquad[self.quadi]
self.timer = self.timer - staranimationdelay
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
if self.lifetime then
self.lifetime = self.lifetime - dt
end
if ((self.lifetime and self.lifetime < 0) or self.x < xscroll-1 or self.x > xscroll+width+1 or self.y > mapheight) and self.active then
if self.fireballthrower then
self.fireballthrower:fireballcallback()
end
self.destroy = true
end
if self.destroy then
return true
else
return false
end
end
function fireball:leftcollide(a, b)
if a == "donut" or a == "plantfire" then
return false
end
--if self.t == "fireball" then
--self.x = self.x-.5 --? Remove maybe
--end
self:hitstuff(a, b, "left")
if self.t == "superball" then
self.speedx = math.abs(self.speedx)
elseif self.t == "iceball" then
self:hitstuff(a, b, "left")
else
self.speedx = fireballspeed
end
return false
end
function fireball:rightcollide(a, b)
if a == "donut" or a == "plantfire" then
return false
end
self:hitstuff(a, b, "right")
if self.t == "superball" then
self.speedx = -math.abs(self.speedx)
elseif self.t == "iceball" then
self:hitstuff(a, b, "right")
else
self.speedx = -fireballspeed
end
return false
end
function fireball:floorcollide(a, b)
if self.t == "iceball" and a == "tile" then
self.hp = self.hp - 1
if self.hp <= 0 then
self:explode()
playsound(iciclesound)
return false
end
end
if a ~= "tile" and a ~= "portalwall" and a ~= "flipblock" and a ~= "buttonblock" and a ~= "snakeblock" or a == "frozencoin" then
self:hitstuff(a, b, "floor")
end
if self.t == "superball" then
self.speedy = -math.abs(self.speedy)
elseif self.t == "iceball" then
self.speedy = -iceballjumpforce
else
self.speedy = -fireballjumpforce
end
if b.SLOPE then
self.speedy = self.speedy -b.incline*10
end
return false
end
function fireball:ceilcollide(a, b)
if a == "donut" then
return false
end
self:hitstuff(a, b, "ceil")
if self.t == "superball" then
self.speedy = math.abs(self.speedy)
if a == "flipblock" then
b:hit()
end
end
end
function fireball:passivecollide(a, b)
if self.t == "superball" then
if a == "tile" then
if self.x+self.width/2 > b.x+b.width/2 then
self.speedx = math.abs(self.speedx)
else
self.speedx = -math.abs(self.speedx)
end
return true
end
end
if a ~= "clearpipesegment" and a ~= "plantfire" then
self:ceilcollide(a, b)
end
return false
end
function fireball:hitstuff(a, b, hitdir)
local dir = "right"
if self.x+self.width/2 > b.x+b.width/2 then
dir = "left"
end
if self.t == "iceball" then
if a == "tile" or a == "portalwall" or a == "spring" or a == "kingbill" or a == "angrysun" or a == "springgreen" or a == "thwomp" or a == "fishbone" or a == "muncher" or (a == "bigkoopa" and b.t == "bigbeetle") or a == "meteor" or a == "parabeetle" or a == "boo" or a == "torpedoted" then
playsound(iciclesound)
elseif iceballfreeze[a] then
if b.freezable and (not b.frozen) and (not b.resistseverything) then
self:explode()
table.insert(objects["ice"], ice:new(b.x+b.width/2, b.y+b.height, b.width, b.height, a, b))
end
end
if not (a == "clearpipesegment" and (b.entrance or b.exit)) then
self:explode()
end
return
end
if self.t == "fireball" and (a == "tile" or a == "bulletbill" or a == "portalwall" or a == "spring" or a == "bigbill" or a == "kingbill" or a == "barrel" or a == "angrysun" or a == "springgreen" or a == "thwomp" or a == "fishbone" or a == "drybones" or a == "muncher" or (a == "bigkoopa" and b.t == "bigbeetle") or a == "meteor" or (a == "goomba" and (b.t == "drygoomba" or b.t == "spiketop")) or (a == "downplant" and b.t == "dryplant") or a == "parabeetle" or a == "boo" or a == "torpedoted" or (a == "plant" and b.t == "dryplant") or a == "chainchomp" or a == "buttonblock" or a == "flipblock" or a == "frozencoin" or a == "snakeblock" or a == "spikeball") then
self:explode()
playsound(blockhitsound)
elseif a == "enemy" then
if b.reflectsfireballs then
if hitdir and (hitdir == "left" or hitdir == "right") then
self.speedx = -self.speedx
end
else
if b:shotted(dir, false, false, true) ~= false then
addpoints(b.firepoints or 200, self.x, self.y)
end
self:explode()
end
elseif (a == "koopa" and (b.t == "beetle" or b.t == "beetleshell" or b.t == "bigbeetle" or b.t == "downbeetle")) or a == "spikeball" or a == "amp" then
self:explode()
elseif fireballkill[a] then
local shot = b:shotted(dir)
if a ~= "bowser" and (a ~= "koopaling" or shot) then
addpoints(firepoints[a] or 200, self.x, self.y)
end
self:explode()
elseif a == "bomb" then
if not b.explosion then
local dir = "right"
if self.x > b.x then
dir = "left"
end
b:shotted2(dir)
self:explode()
else
self:explode()
end
elseif a == "boomboom" then
if not b.ducking then
b:shotted("right")
self:explode()
else
self:explode()
end
end
end
function fireball:explode()
if self.active then
if self.fireballthrower then
self.fireballthrower:fireballcallback()
end
if self.t == "superball" then
self.destroy = true
self.active = false
makepoof(self.x+self.width/2, self.y+self.height/2, "makerpoof")
else
self.destroysoon = true
self.quadi = 5
self.quad = fireballquad[self.quadi]
self.active = false
self.quadcenterX = 8
self.quadcenterY = 8
end
end
end