1koopa = class:new()
2
3--combo: 500, 800, 1000, 2000, 4000, 5000
4
5function koopa:init(x, y, t)
6	--PHYSICS STUFF
7	self.x = x-6/16
8	self.y = y-11/16
9	self.speedy = 0
10	self.speedx = -koopaspeed
11	self.width = 12/16
12	self.height = 12/16
13	self.static = false
14	self.active = true
15	self.category = 5
16
17	self.mask = {	true,
18					false, false, false, false, true,
19					false, true, false, true, false,
20					false, false, true, false, false,
21					true, true, false, false, true,
22					false, true, true, false, false,
23					true, false, true, true, true}
24
25	self.autodelete = true
26	self.t = t
27	self.flying = false
28	self.startx = self.x
29	self.starty = self.y
30	self.quad = koopaquad[spriteset][1]
31	self.combo = 1
32
33	--IMAGE STUFF
34	self.drawable = true
35	if self.t == "red" then
36		self.graphic = kooparedimage
37	elseif self.t == "redflying" then
38		self.graphic = kooparedimage
39		self.flying = true
40		self.gravity = 0
41		self.quad = koopaquad[spriteset][4]
42		self.speedx = 0
43		self.timer = 0
44	elseif self.t == "flying" then
45		self.flying = true
46		self.quad = koopaquad[spriteset][4]
47		self.graphic = koopaimage
48		self.gravity = koopaflyinggravity
49	elseif self.t == "beetle" then
50		self.graphic = beetleimage
51	else
52		self.graphic = koopaimage
53	end
54	self.offsetX = 6
55	self.offsetY = 0
56	self.quadcenterX = 8
57	self.quadcenterY = 19
58
59	self.rotation = 0
60	self.direction = "left"
61	self.animationdirection = "right"
62	self.animationtimer = 0
63
64	self.small = false
65	self.moving = true
66
67	self.falling = false
68
69	self.shot = false
70end
71
72function koopa:func(i) -- 0-1 in please
73	return (-math.cos(i*math.pi*2)+1)/2
74end
75
76function koopa:update(dt)
77	--rotate back to 0 (portals)
78	self.rotation = math.mod(self.rotation, math.pi*2)
79	if self.rotation > 0 then
80		self.rotation = self.rotation - portalrotationalignmentspeed*dt
81		if self.rotation < 0 then
82			self.rotation = 0
83		end
84	elseif self.rotation < 0 then
85		self.rotation = self.rotation + portalrotationalignmentspeed*dt
86		if self.rotation > 0 then
87			self.rotation = 0
88		end
89	end
90
91	if self.shot then
92		self.speedy = self.speedy + shotgravity*dt
93
94		self.x = self.x+self.speedx*dt
95		self.y = self.y+self.speedy*dt
96
97		return false
98
99	else
100		if self.speedx > 0 then
101			self.animationdirection = "left"
102		else
103			self.animationdirection = "right"
104		end
105		--red koopa turn around
106		if self.falling == false and self.flying == false and (self.t == "red" or self.t == "redflying") and self.small == false then
107			--check if nothing below
108			local x = math.floor(self.x + self.width/2+1)
109			local y = math.floor(self.y + self.height+1.5)
110			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
111				if self.speedx < 0 then
112					self.animationdirection = "left"
113					self.x = x-self.width/2
114				else
115					self.animationdirection = "right"
116					self.x = x-1-self.width/2
117				end
118				self.speedx = -self.speedx
119			end
120		end
121
122		if self.flying == true and self.t == "redflying" then
123			self.timer = self.timer + dt
124
125			while self.timer > koopaflyingtime do
126				self.timer = self.timer - koopaflyingtime
127			end
128			local newy = self:func(self.timer/koopaflyingtime)*koopaflyingdistance + self.starty
129			self.y = newy
130		end
131
132		if self.small == false then
133			self.animationtimer = self.animationtimer + dt
134			while self.animationtimer > koopaanimationspeed do
135				self.animationtimer = self.animationtimer - koopaanimationspeed
136				if not self.flying then
137					if self.quad == koopaquad[spriteset][1] then
138						self.quad = koopaquad[spriteset][2]
139					else
140						self.quad = koopaquad[spriteset][1]
141					end
142				else
143					if self.quad == koopaquad[spriteset][4] then
144						self.quad = koopaquad[spriteset][5]
145					else
146						self.quad = koopaquad[spriteset][4]
147					end
148				end
149			end
150		end
151
152		if self.t ~= "redflying" or self.flying == false then
153			if self.small == false then
154				if self.speedx > 0 then
155					if self.speedx > koopaspeed then
156						self.speedx = self.speedx - friction*dt*2
157						if self.speedx < koopaspeed then
158							self.speedx = koopaspeed
159						end
160					elseif self.speedx < koopaspeed then
161						self.speedx = self.speedx + friction*dt*2
162						if self.speedx > koopaspeed then
163							self.speedx = koopaspeed
164						end
165					end
166				else
167					if self.speedx < -koopaspeed then
168						self.speedx = self.speedx + friction*dt*2
169						if self.speedx > -koopaspeed then
170							self.speedx = -koopaspeed
171						end
172					elseif self.speedx > -koopaspeed then
173						self.speedx = self.speedx - friction*dt*2
174						if self.speedx < -koopaspeed then
175							self.speedx = -koopaspeed
176						end
177					end
178				end
179			else
180				if self.speedx > 0 then
181					if self.speedx > koopasmallspeed then
182						self.speedx = self.speedx - friction*dt*2
183						if self.speedx < koopasmallspeed then
184							self.speedx = koopasmallspeed
185						end
186					elseif self.speedx < koopasmallspeed then
187						self.speedx = self.speedx + friction*dt*2
188						if self.speedx > koopasmallspeed then
189							self.speedx = koopasmallspeed
190						end
191					end
192				elseif self.speedx < 0 then
193					if self.speedx < -koopasmallspeed then
194						self.speedx = self.speedx + friction*dt*2
195						if self.speedx > -koopasmallspeed then
196							self.speedx = -koopasmallspeed
197						end
198					elseif self.speedx > -koopasmallspeed then
199						self.speedx = self.speedx - friction*dt*2
200						if self.speedx < -koopasmallspeed then
201							self.speedx = -koopasmallspeed
202						end
203					end
204				end
205			end
206		end
207
208		return false
209	end
210end
211
212function koopa:stomp(x, b)
213	if self.flying then
214		self.flying = false
215		self.quad = koopaquad[spriteset][1]
216		if self.speedx == 0 then
217			self.speedx = -koopaspeed
218		end
219		self.gravity = yacceleration
220		return false
221	elseif self.small == false then
222		self.quadcenterY = 19
223		self.offsetY = 0
224		self.quad = koopaquad[spriteset][3]
225		self.small = true
226		self.mask = {false, false, false, false, false, true, false, false, false, true}
227		self.speedx = 0
228	elseif self.speedx == 0 then
229		if self.x > x then
230			self.speedx = koopasmallspeed
231			self.x = x+12/16+koopasmallspeed*gdt
232		else
233			self.speedx = -koopasmallspeed
234			self.x = x-self.width-koopasmallspeed*gdt
235		end
236	else
237		self.speedx = 0
238		self.combo = 1
239	end
240end
241
242function koopa:shotted(dir) --fireball, star, turtle
243	playsound(shotsound)
244	self.shot = true
245	self.small = true
246	self.quad = koopaquad[spriteset][3]
247	self.quadcenterY = 19
248	self.offsetY = 0
249	self.speedy = -shotjumpforce
250	self.direction = dir or "right"
251	self.active = false
252	self.gravity = shotgravity
253	if self.direction == "left" then
254		self.speedx = -shotspeedx
255	else
256		self.speedx = shotspeedx
257	end
258end
259
260function koopa:leftcollide(a, b)
261	if self:globalcollide(a, b) then
262		return false
263	end
264
265	if a == "tile" or a == "portalwall" or a == "spring" then
266		if self.small then
267			self.speedx = -self.speedx
268			local x, y = b.cox, b.coy
269			if a == "tile" then
270				hitblock(x, y, {size=2})
271			else
272				playsound(blockhitsound)
273			end
274		end
275	end
276
277	if a ~= "tile" and a ~= "portalwall" and a ~= "platform" and self.small and self.speedx ~= 0 and a ~= "player" and a ~= "spring" then
278		if b.shotted then
279			if self.combo < #koopacombo then
280				self.combo = self.combo + 1
281				addpoints(koopacombo[self.combo], b.x, b.y)
282			else
283				for i = 1, players do
284					if mariolivecount ~= false then
285						mariolives[i] = mariolives[i]+1
286						respawnplayers()
287					end
288				end
289				table.insert(scrollingscores, scrollingscore:new("1up", b.x, b.y))
290				playsound(oneupsound)
291			end
292			b:shotted("left")
293		end
294	end
295
296	if self.small == false then
297		self.animationdirection = "left"
298		self.speedx = -self.speedx
299	else
300		return false
301	end
302end
303
304function koopa:rightcollide(a, b)
305	if self:globalcollide(a, b) then
306		return false
307	end
308	if a == "tile" or a == "portalwall" or a == "spring" then
309		if self.small then
310			self.speedx = -self.speedx
311			local x, y = b.cox, b.coy
312			if a == "tile" then
313				hitblock(x, y, {size=2})
314			else
315				playsound(blockhitsound)
316			end
317		end
318	end
319
320	if a ~= "tile" and a ~= "portalwall" and a ~= "platform" and self.small and self.speedx ~= 0 and a ~= "player" and a ~= "spring" then
321		if b.shotted then
322			if self.combo < #koopacombo then
323				self.combo = self.combo + 1
324				addpoints(koopacombo[self.combo], b.x, b.y)
325			else
326				for i = 1, players do
327					if mariolivecount ~= false then
328						mariolives[i] = mariolives[i]+1
329						respawnplayers()
330					end
331				end
332				table.insert(scrollingscores, scrollingscore:new("1up", b.x, b.y))
333				playsound(oneupsound)
334			end
335			b:shotted("right")
336		end
337	end
338
339	if self.small == false then
340		self.animationdirection = "right"
341		self.speedx = -self.speedx
342	else
343		return false
344	end
345end
346
347function koopa:passivecollide(a, b)
348	self:leftcollide(a, b)
349	return false
350end
351
352function koopa:globalcollide(a, b)
353	if a == "bulletbill" then
354		if b.killstuff ~= false then
355			return true
356		end
357	end
358	if a == "fireball" or a == "player" then
359		return true
360	end
361end
362
363function koopa:emancipate(a)
364	self:shotted()
365end
366
367function koopa:floorcollide(a, b)
368	self.falling = false
369	if self.t == "flying" and self.flying then
370		if self:globalcollide(a, b) then
371			return false
372		end
373		self.speedy = -koopajumpforce
374	end
375end
376
377function koopa:ceilcollide(a, b)
378	if self:globalcollide(a, b) then
379		return false
380	end
381end
382
383function koopa:laser()
384	self:shotted()
385end
386
387function koopa:startfall()
388	self.falling = true
389end