forked from Stabyourself/mari0
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goomba.lua
286 lines (244 loc) · 5.74 KB
/
goomba.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
goomba = class:new()
function goomba:init(x, y, t)
--PHYSICS STUFF
self.x = x-6/16
self.y = y-11/16
self.speedy = 0
self.speedx = -goombaspeed
self.width = 12/16
self.height = 12/16
self.static = false
self.active = true
self.category = 4
self.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}
self.emancipatecheck = true
self.autodelete = true
--IMAGE STUFF
self.drawable = true
self.graphic = goombaimage
self.quad = goombaquad[spriteset][1]
self.offsetX = 6
self.offsetY = 3
self.quadcenterX = 8
self.quadcenterY = 8
self.rotation = 0 --for portals
self.direction = "left"
self.animationtimer = 0
self.t = t or "goomba"
if self.t == "spikeyair" then
self.air = true
self.t = "spikey"
end
if self.t == "goomba" then
self.animationdirection = "left"
elseif self.t == "spikey" or self.t == "spikeyfall" then
self.graphic = spikeyimg
self.fall = true
if self.t == "spikey" then
self.quadi = 1
else
self.mask[21] = true
self.starty = self.y
self.gravity = 30
self.speedy = -10
self.quadi = 3
self.speedx = 0
end
self.quad = spikeyquad[self.quadi]
end
self.falling = false
self.dead = false
self.deathtimer = 0
self.shot = false
end
function goomba:update(dt)
--rotate back to 0 (portals)
if self.t == "spikeyfall" then
self.rotation = 0
else
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
end
if self.dead then
self.deathtimer = self.deathtimer + dt
if self.deathtimer > goombadeathtime then
return true
else
return false
end
elseif 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
self.animationtimer = self.animationtimer + dt
while self.animationtimer > goombaanimationspeed do
self.animationtimer = self.animationtimer - goombaanimationspeed
if self.t == "goomba" then
if self.animationdirection == "left" then
self.animationdirection = "right"
else
self.animationdirection = "left"
end
elseif self.t == "spikey" then
if self.quadi == 1 then
self.quadi = 2
else
self.quadi = 1
end
self.quad = spikeyquad[self.quadi]
elseif self.t == "spikeyfall" then
if self.quadi == 3 then
self.quadi = 4
else
self.quadi = 3
end
self.quad = spikeyquad[self.quadi]
if self.mask[21] and self.y > self.starty+2 then
self.mask[21] = false
end
end
end
if self.t ~= "spikeyfall" then
if self.speedx > 0 then
if self.speedx > goombaspeed then
self.speedx = self.speedx - friction*dt*2
if self.speedx < goombaspeed then
self.speedx = goombaspeed
end
elseif self.speedx < goombaspeed then
self.speedx = self.speedx + friction*dt*2
if self.speedx > goombaspeed then
self.speedx = goombaspeed
end
end
else
if self.speedx < -goombaspeed then
self.speedx = self.speedx + friction*dt*2
if self.speedx > -goombaspeed then
self.speedx = -goombaspeed
end
elseif self.speedx > -goombaspeed then
self.speedx = self.speedx - friction*dt*2
if self.speedx < -goombaspeed then
self.speedx = -goombaspeed
end
end
end
end
--check if goomba offscreen
return false
end
end
function goomba:stomp()--hehe goomba stomp
self.dead = true
self.active = false
self.quad = goombaquad[spriteset][2]
end
function goomba:shotted(dir) --fireball, star, turtle
playsound(shotsound)
self.shot = true
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 goomba:leftcollide(a, b)
if self:globalcollide(a, b) then
return false
end
self.speedx = goombaspeed
if self.t == "spikey" then
self.animationdirection = "left"
end
return false
end
function goomba:rightcollide(a, b)
if self:globalcollide(a, b) then
return false
end
self.speedx = -goombaspeed
if self.t == "spikey" then
self.animationdirection = "right"
end
return false
end
function goomba:ceilcollide(a, b)
if self:globalcollide(a, b) then
return false
end
end
function goomba: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
if self.t == "spikeyfall" and a == "lakito" then
return true
end
end
function goomba:startfall()
end
function goomba:floorcollide(a, b)
if self:globalcollide(a, b) then
return false
end
if self.t == "spikeyfall" then
self.t = "spikey"
self.fall = false
self.quadi = 1
self.quad = spikeyquad[self.quadi]
self.gravity = nil
local nearestplayer = 1
local nearestplayerx = objects["player"][1].x
for i = 2, players do
local v = objects["player"][i]
if math.abs(self.x - v.x) < nearestplayerx then
nearestplayer = i
nearestplayerx = v.x
end
end
if self.x >= nearestplayerx then
self.speedx = -goombaspeed
else
self.speedx = goombaspeed
self.animationdirection = "left"
end
end
end
function goomba:passivecollide(a, b)
self:leftcollide(a, b)
return false
end
function goomba:emancipate(a)
self:shotted()
end
function goomba:laser()
self:shotted()
end