forked from Stabyourself/mari0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
koopa.lua
389 lines (353 loc) · 9.23 KB
/
koopa.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
koopa = class:new()
--combo: 500, 800, 1000, 2000, 4000, 5000
function koopa:init(x, y, t)
--PHYSICS STUFF
self.x = x-6/16
self.y = y-11/16
self.speedy = 0
self.speedx = -koopaspeed
self.width = 12/16
self.height = 12/16
self.static = false
self.active = true
self.category = 5
self.mask = { true,
false, false, false, false, true,
false, true, false, true, false,
false, false, true, false, false,
true, true, false, false, true,
false, true, true, false, false,
true, false, true, true, true}
self.autodelete = true
self.t = t
self.flying = false
self.startx = self.x
self.starty = self.y
self.quad = koopaquad[spriteset][1]
self.combo = 1
--IMAGE STUFF
self.drawable = true
if self.t == "red" then
self.graphic = kooparedimage
elseif self.t == "redflying" then
self.graphic = kooparedimage
self.flying = true
self.gravity = 0
self.quad = koopaquad[spriteset][4]
self.speedx = 0
self.timer = 0
elseif self.t == "flying" then
self.flying = true
self.quad = koopaquad[spriteset][4]
self.graphic = koopaimage
self.gravity = koopaflyinggravity
elseif self.t == "beetle" then
self.graphic = beetleimage
else
self.graphic = koopaimage
end
self.offsetX = 6
self.offsetY = 0
self.quadcenterX = 8
self.quadcenterY = 19
self.rotation = 0
self.direction = "left"
self.animationdirection = "right"
self.animationtimer = 0
self.small = false
self.moving = true
self.falling = false
self.shot = false
end
function koopa:func(i) -- 0-1 in please
return (-math.cos(i*math.pi*2)+1)/2
end
function koopa:update(dt)
--rotate back to 0 (portals)
self.rotation = math.fmod(self.rotation, math.pi*2)
if self.rotation > 0 then
self.rotation = self.rotation - portalrotationalignmentspeed*dt
if self.rotation < 0 then
self.rotation = 0
end
elseif self.rotation < 0 then
self.rotation = self.rotation + portalrotationalignmentspeed*dt
if self.rotation > 0 then
self.rotation = 0
end
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
else
if self.speedx > 0 then
self.animationdirection = "left"
else
self.animationdirection = "right"
end
--red koopa turn around
if self.falling == false and self.flying == false and (self.t == "red" or self.t == "redflying") and self.small == false then
--check if nothing below
local x = math.floor(self.x + self.width/2+1)
local y = math.floor(self.y + self.height+1.5)
if inmap(x, y) and tilequads[map[x][y][1]].collision == false and ((inmap(x+.5, y) and tilequads[map[math.ceil(x+.5)][y][1]].collision) or (inmap(x-.5, y) and tilequads[map[math.floor(x-.5)][y][1]].collision)) then
if self.speedx < 0 then
self.animationdirection = "left"
self.x = x-self.width/2
else
self.animationdirection = "right"
self.x = x-1-self.width/2
end
self.speedx = -self.speedx
end
end
if self.flying == true and self.t == "redflying" then
self.timer = self.timer + dt
while self.timer > koopaflyingtime do
self.timer = self.timer - koopaflyingtime
end
local newy = self:func(self.timer/koopaflyingtime)*koopaflyingdistance + self.starty
self.y = newy
end
if self.small == false then
self.animationtimer = self.animationtimer + dt
while self.animationtimer > koopaanimationspeed do
self.animationtimer = self.animationtimer - koopaanimationspeed
if not self.flying then
if self.quad == koopaquad[spriteset][1] then
self.quad = koopaquad[spriteset][2]
else
self.quad = koopaquad[spriteset][1]
end
else
if self.quad == koopaquad[spriteset][4] then
self.quad = koopaquad[spriteset][5]
else
self.quad = koopaquad[spriteset][4]
end
end
end
end
if self.t ~= "redflying" or self.flying == false then
if self.small == false then
if self.speedx > 0 then
if self.speedx > koopaspeed then
self.speedx = self.speedx - friction*dt*2
if self.speedx < koopaspeed then
self.speedx = koopaspeed
end
elseif self.speedx < koopaspeed then
self.speedx = self.speedx + friction*dt*2
if self.speedx > koopaspeed then
self.speedx = koopaspeed
end
end
else
if self.speedx < -koopaspeed then
self.speedx = self.speedx + friction*dt*2
if self.speedx > -koopaspeed then
self.speedx = -koopaspeed
end
elseif self.speedx > -koopaspeed then
self.speedx = self.speedx - friction*dt*2
if self.speedx < -koopaspeed then
self.speedx = -koopaspeed
end
end
end
else
if self.speedx > 0 then
if self.speedx > koopasmallspeed then
self.speedx = self.speedx - friction*dt*2
if self.speedx < koopasmallspeed then
self.speedx = koopasmallspeed
end
elseif self.speedx < koopasmallspeed then
self.speedx = self.speedx + friction*dt*2
if self.speedx > koopasmallspeed then
self.speedx = koopasmallspeed
end
end
elseif self.speedx < 0 then
if self.speedx < -koopasmallspeed then
self.speedx = self.speedx + friction*dt*2
if self.speedx > -koopasmallspeed then
self.speedx = -koopasmallspeed
end
elseif self.speedx > -koopasmallspeed then
self.speedx = self.speedx - friction*dt*2
if self.speedx < -koopasmallspeed then
self.speedx = -koopasmallspeed
end
end
end
end
end
return false
end
end
function koopa:stomp(x, b)
if self.flying then
self.flying = false
self.quad = koopaquad[spriteset][1]
if self.speedx == 0 then
self.speedx = -koopaspeed
end
self.gravity = yacceleration
return false
elseif self.small == false then
self.quadcenterY = 19
self.offsetY = 0
self.quad = koopaquad[spriteset][3]
self.small = true
self.mask = {false, false, false, false, false, true, false, false, false, true}
self.speedx = 0
elseif self.speedx == 0 then
if self.x > x then
self.speedx = koopasmallspeed
self.x = x+12/16+koopasmallspeed*gdt
else
self.speedx = -koopasmallspeed
self.x = x-self.width-koopasmallspeed*gdt
end
else
self.speedx = 0
self.combo = 1
end
end
function koopa:shotted(dir) --fireball, star, turtle
playsound(shotsound)
self.shot = true
self.small = true
self.quad = koopaquad[spriteset][3]
self.quadcenterY = 19
self.offsetY = 0
self.speedy = -shotjumpforce
self.direction = dir or "right"
self.active = false
self.gravity = shotgravity
if self.direction == "left" then
self.speedx = -shotspeedx
else
self.speedx = shotspeedx
end
end
function koopa:leftcollide(a, b)
if self:globalcollide(a, b) then
return false
end
if a == "tile" or a == "portalwall" or a == "spring" then
if self.small then
self.speedx = -self.speedx
local x, y = b.cox, b.coy
if a == "tile" then
hitblock(x, y, {size=2})
else
playsound(blockhitsound)
end
end
end
if a ~= "tile" and a ~= "portalwall" and a ~= "platform" and self.small and self.speedx ~= 0 and a ~= "player" and a ~= "spring" then
if b.shotted then
if self.combo < #koopacombo then
self.combo = self.combo + 1
addpoints(koopacombo[self.combo], b.x, b.y)
else
for i = 1, players do
if mariolivecount ~= false then
mariolives[i] = mariolives[i]+1
respawnplayers()
end
end
table.insert(scrollingscores, scrollingscore:new("1up", b.x, b.y))
playsound(oneupsound)
end
b:shotted("left")
end
end
if self.small == false then
self.animationdirection = "left"
self.speedx = -self.speedx
else
return false
end
end
function koopa:rightcollide(a, b)
if self:globalcollide(a, b) then
return false
end
if a == "tile" or a == "portalwall" or a == "spring" then
if self.small then
self.speedx = -self.speedx
local x, y = b.cox, b.coy
if a == "tile" then
hitblock(x, y, {size=2})
else
playsound(blockhitsound)
end
end
end
if a ~= "tile" and a ~= "portalwall" and a ~= "platform" and self.small and self.speedx ~= 0 and a ~= "player" and a ~= "spring" then
if b.shotted then
if self.combo < #koopacombo then
self.combo = self.combo + 1
addpoints(koopacombo[self.combo], b.x, b.y)
else
for i = 1, players do
if mariolivecount ~= false then
mariolives[i] = mariolives[i]+1
respawnplayers()
end
end
table.insert(scrollingscores, scrollingscore:new("1up", b.x, b.y))
playsound(oneupsound)
end
b:shotted("right")
end
end
if self.small == false then
self.animationdirection = "right"
self.speedx = -self.speedx
else
return false
end
end
function koopa:passivecollide(a, b)
self:leftcollide(a, b)
return false
end
function koopa:globalcollide(a, b)
if a == "bulletbill" then
if b.killstuff ~= false then
return true
end
end
if a == "fireball" or a == "player" then
return true
end
end
function koopa:emancipate(a)
self:shotted()
end
function koopa:floorcollide(a, b)
self.falling = false
if self.t == "flying" and self.flying then
if self:globalcollide(a, b) then
return false
end
self.speedy = -koopajumpforce
end
end
function koopa:ceilcollide(a, b)
if self:globalcollide(a, b) then
return false
end
end
function koopa:laser()
self:shotted()
end
function koopa:startfall()
self.falling = true
end