1goomba = class:new()
2
3function goomba:init(x, y, t)
4	--PHYSICS STUFF
5	self.x = x-6/16
6	self.y = y-11/16
7	self.speedy = 0
8	self.speedx = -goombaspeed
9	self.width = 12/16
10	self.height = 12/16
11	self.static = false
12	self.active = true
13	self.category = 4
14
15	self.mask = {	true,
16					false, false, false, false, true,
17					false, true, false, true, false,
18					false, false, true, false, false,
19					true, true, false, false, false,
20					false, true, true, false, false,
21					true, false, true, true, true}
22
23	self.emancipatecheck = true
24	self.autodelete = true
25
26	--IMAGE STUFF
27	self.drawable = true
28	self.graphic = goombaimage
29	self.quad = goombaquad[spriteset][1]
30	self.offsetX = 6
31	self.offsetY = 3
32	self.quadcenterX = 8
33	self.quadcenterY = 8
34
35	self.rotation = 0 --for portals
36
37	self.direction = "left"
38	self.animationtimer = 0
39	self.t = t or "goomba"
40
41	if self.t == "spikeyair" then
42		self.air = true
43		self.t = "spikey"
44	end
45
46	if self.t == "goomba" then
47		self.animationdirection = "left"
48	elseif self.t == "spikey" or self.t == "spikeyfall" then
49		self.graphic = spikeyimg
50		self.fall = true
51		if self.t == "spikey" then
52			self.quadi = 1
53		else
54			self.mask[21] = true
55			self.starty = self.y
56			self.gravity = 30
57			self.speedy = -10
58			self.quadi = 3
59			self.speedx = 0
60		end
61		self.quad = spikeyquad[self.quadi]
62	end
63
64	self.falling = false
65
66	self.dead = false
67	self.deathtimer = 0
68
69	self.shot = false
70end
71
72function goomba:update(dt)
73	--rotate back to 0 (portals)
74	if self.t == "spikeyfall" then
75		self.rotation = 0
76	else
77		self.rotation = math.mod(self.rotation, math.pi*2)
78		if self.rotation > 0 then
79			self.rotation = self.rotation - portalrotationalignmentspeed*dt
80			if self.rotation < 0 then
81				self.rotation = 0
82			end
83		elseif self.rotation < 0 then
84			self.rotation = self.rotation + portalrotationalignmentspeed*dt
85			if self.rotation > 0 then
86				self.rotation = 0
87			end
88		end
89	end
90
91	if self.dead then
92		self.deathtimer = self.deathtimer + dt
93		if self.deathtimer > goombadeathtime then
94			return true
95		else
96			return false
97		end
98
99	elseif self.shot then
100		self.speedy = self.speedy + shotgravity*dt
101
102		self.x = self.x+self.speedx*dt
103		self.y = self.y+self.speedy*dt
104
105		return false
106
107	else
108		self.animationtimer = self.animationtimer + dt
109		while self.animationtimer > goombaanimationspeed do
110			self.animationtimer = self.animationtimer - goombaanimationspeed
111			if self.t == "goomba" then
112				if self.animationdirection == "left" then
113					self.animationdirection = "right"
114				else
115					self.animationdirection = "left"
116				end
117			elseif self.t == "spikey" then
118				if self.quadi == 1 then
119					self.quadi = 2
120				else
121					self.quadi = 1
122				end
123				self.quad = spikeyquad[self.quadi]
124			elseif self.t == "spikeyfall" then
125				if self.quadi == 3 then
126					self.quadi = 4
127				else
128					self.quadi = 3
129				end
130				self.quad = spikeyquad[self.quadi]
131
132				if self.mask[21] and self.y > self.starty+2 then
133					self.mask[21] = false
134				end
135			end
136		end
137
138		if self.t ~= "spikeyfall" then
139			if self.speedx > 0 then
140				if self.speedx > goombaspeed then
141					self.speedx = self.speedx - friction*dt*2
142					if self.speedx < goombaspeed then
143						self.speedx = goombaspeed
144					end
145				elseif self.speedx < goombaspeed then
146					self.speedx = self.speedx + friction*dt*2
147					if self.speedx > goombaspeed then
148						self.speedx = goombaspeed
149					end
150				end
151			else
152				if self.speedx < -goombaspeed then
153					self.speedx = self.speedx + friction*dt*2
154					if self.speedx > -goombaspeed then
155						self.speedx = -goombaspeed
156					end
157				elseif self.speedx > -goombaspeed then
158					self.speedx = self.speedx - friction*dt*2
159					if self.speedx < -goombaspeed then
160						self.speedx = -goombaspeed
161					end
162				end
163			end
164		end
165
166		--check if goomba offscreen
167		return false
168	end
169end
170
171function goomba:stomp()--hehe goomba stomp
172	self.dead = true
173	self.active = false
174	self.quad = goombaquad[spriteset][2]
175end
176
177function goomba:shotted(dir) --fireball, star, turtle
178	playsound(shotsound)
179	self.shot = true
180	self.speedy = -shotjumpforce
181	self.direction = dir or "right"
182	self.active = false
183	self.gravity = shotgravity
184	if self.direction == "left" then
185		self.speedx = -shotspeedx
186	else
187		self.speedx = shotspeedx
188	end
189end
190
191function goomba:leftcollide(a, b)
192	if self:globalcollide(a, b) then
193		return false
194	end
195
196	self.speedx = goombaspeed
197
198	if self.t == "spikey" then
199		self.animationdirection = "left"
200	end
201
202	return false
203end
204
205function goomba:rightcollide(a, b)
206	if self:globalcollide(a, b) then
207		return false
208	end
209
210	self.speedx = -goombaspeed
211
212	if self.t == "spikey" then
213		self.animationdirection = "right"
214	end
215
216	return false
217end
218
219function goomba:ceilcollide(a, b)
220	if self:globalcollide(a, b) then
221		return false
222	end
223end
224
225function goomba:globalcollide(a, b)
226	if a == "bulletbill" then
227		if b.killstuff ~= false then
228			return true
229		end
230	end
231
232	if a == "fireball" or a == "player" then
233		return true
234	end
235
236	if self.t == "spikeyfall" and a == "lakito" then
237		return true
238	end
239end
240
241function goomba:startfall()
242
243end
244
245function goomba:floorcollide(a, b)
246	if self:globalcollide(a, b) then
247		return false
248	end
249
250	if self.t == "spikeyfall" then
251		self.t = "spikey"
252		self.fall = false
253		self.quadi = 1
254		self.quad = spikeyquad[self.quadi]
255		self.gravity = nil
256		local nearestplayer = 1
257		local nearestplayerx = objects["player"][1].x
258		for i = 2, players do
259			local v = objects["player"][i]
260			if math.abs(self.x - v.x) < nearestplayerx then
261				nearestplayer = i
262				nearestplayerx = v.x
263			end
264		end
265
266		if self.x >= nearestplayerx then
267			self.speedx = -goombaspeed
268		else
269			self.speedx = goombaspeed
270			self.animationdirection = "left"
271		end
272	end
273end
274
275function goomba:passivecollide(a, b)
276	self:leftcollide(a, b)
277	return false
278end
279
280function goomba:emancipate(a)
281	self:shotted()
282end
283
284function goomba:laser()
285	self:shotted()
286end