-
Notifications
You must be signed in to change notification settings - Fork 26
/
cappy.lua
404 lines (357 loc) · 9.21 KB
/
cappy.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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
cappy = class:new()
local throwdist = 4
local throwspeed = 10
local holdtime = 0.5
local returnspeed = 15
local playery = -1/16
local spintime = 0.12
local releasenotice = false--people keep on asking the same question and it's annoying
function cappy:init(player)
self.player = player
self.num = self.player.playernumber
self.x = self.player.x
self.y = self.player.y
self.active = false
self.static = true
self.speedy = 0
self.speedx = 0
self.width = 12/16
self.height = 13/16
self.category = 4
self.gravity = 0
self.mask = { true,
true, false, false, false, false,
false, true, false, false, false,
false, true, false, false, false,
false, false, false, false, false,
false, false, false, false, false,
false, false, false, false, false,
false, true}
self.rotation = 0
--IMAGE STUFF
self.drawable = false
if self.player.hats then
self.hat = self.player.hats[1]
else
self.hat = 1
end
if not self.hat or self.hat == 0 then
self.hat = 1
end
self.spin = 1
self.dir = "left"
self.spintimer = 0
self.holdtimer = 0
self.thrown = false
self.returning = false
self.button = false --what button was used to trigger it?
self.cooldown = 0
--Possesion
self.host = false
self.jumping = false
end
function cappy:update(dt)
if self.thrown then
if self.returning then
--start returning
local rx, ry = (self.player.x + -self.x), (self.player.y + -self.y)
local dist = math.sqrt(rx*rx+ry*ry)
self.speedx, self.speedy = (rx)/dist*returnspeed, (ry)/dist*returnspeed
elseif math.abs(self.x-self.ox) > throwdist or self.speedx == 0 then
--stay in position when thrown
self.speedx = 0
self.speedy = 0
if ((self.button == "run" and runkey(self.num)) or (self.button == "use" and usekey(self.num))) and self.holdtimer < holdtime then
self.holdtimer = self.holdtimer + dt
else
self.returning = true
self.holdtimer = 0
end
end
--spin animation
self.spintimer = self.spintimer + dt
while self.spintimer > spintime do
self.spin = -self.spin
self.spintimer = self.spintimer-spintime
end
elseif self.host then
self.x = self.host.x
self.y = self.host.y
self.player.x = self.host.x+(self.host.width/2)-(self.player.width/2)
self.player.y = self.host.y+playery
self.player.drawable = false --persist
if self.host.movedist then
self.player.x = self.host.x-3
end
--turn hat
if self.host.speedx then
self.player.speedx = self.host.speedx
self.player.speedy = self.host.speedy
if self.host.speedx < 0 then
self.spin = -1
else
self.spin = 1
end
end
--move
self.cooldown = math.max(0, self.cooldown - dt)
if leftkey(self.num) then
if self.host.speedx then
if self.host.small and self.host.speedx >= 0 then
self.host:stomp(self.x+self.host.width, self)
elseif self.host.speedx >= 0 and self.host.rightcollide then
self.host:rightcollide("spring", self)
end
end
if self.host.startx and self.host.speedx then
self.host.startx = self.host.startx - math.abs(self.host.speedx)*dt
end
if (self.host.gravity and self.host.gravity == 0) then
self.host.speedx = -math.abs(self.host.speedx)
end
self.player.x = self.player.x-0.1
elseif rightkey(self.num) then
if self.host.speedx then
if self.host.small and self.host.speedx <= 0 then
self.host:stomp(self.x-self.host.width, self)
elseif self.host.speedx <= 0 and self.host.leftcollide then
self.host:leftcollide("spring", self)
end
end
if self.host.startx and self.host.speedx then
self.host.startx = self.host.startx + math.abs(self.host.speedx)*dt
end
if (self.host.gravity and self.host.gravity == 0) then
self.host.speedx = math.abs(self.host.speedx)
end
self.player.x = self.player.x+0.1
end
if upkey(self.num) then
if self.host.rotation then
self.host.rotation = self.host.rotation - dt
end
self.player.y = self.player.y-0.2
elseif downkey(self.num) then
if (self.host.small == false) or (self.host.shellanimal and not self.host.small) then
self.host:stomp()
elseif self.host.dead == false and self.host.stomp and self.cooldown <= 0 then
self.host:stomp()
self.cooldown = 0.5
if self.host.dead then
self:release()
return
end
end
if self.host.rotation then
self.host.rotation = self.host.rotation + dt
end
self.player.y = self.player.y+0.1
end
if runkey(self.num) then
self.host:update(dt)
end
if self.host.shot or self.host.dead or self.host.delete or levelfinished then
self:release()
return
end
if self.host.jumptime and self.host.timer2 then
self.host.timer2 = 0
end
if self.jumping and (self.host.speedy == 0 or self.host.speedy == -goombajumpforce) then
self.jumping = false
end
if self.spin == 1 then
self.dir = "right"
else
self.dir = "left"
end
end
end
function cappy:draw()
if self.drawable then
local width, height = self.width, self.height
local offsety = -6
if self.host then
offsety = -5
width, height = self.host.width, self.host.height
end
if self.hat == 1 then
love.graphics.setColor(self.player.colors[1])
else
love.graphics.setColor(255, 255, 255)
end
local graphic = hat[self.hat].graphic
local quad = hat[self.hat].quad[1]
if self.player.size > 1 then
graphic = bighat[self.hat].graphic
quad = bighat[self.hat].quad[1]
end
love.graphics.draw(graphic, quad, math.floor((self.x+width/2-xscroll)*16*scale), ((self.y-yscroll)*16-8-offsety)*scale, 0, (self.spin)*scale, scale, 4, 8)
end
end
function cappy:trigger(dir, button)
if self.host then
if upkey(self.num) then
self:release()
else
self:fire()
end
elseif not self.thrown then
self.button = button
self:throw(dir)
end
end
function cappy:throw(dir)
self.player.drawhat = false
if self.player.jumping or self.player.falling then
self.player.speedy = math.min(-6, self.player.speedy-6) --stall in the air
end
self.drawable = true
self.thrown = true
self.active = true
self.static = false
self.x = self.player.x
self.y = self.player.y
self.returning = false
self.ox = self.x
self.speedy = 0
if dir == "left" then
self.speedx = -throwspeed
else
self.speedx = throwspeed
end
end
function cappy:back()
if self.host then
return
end
self.player.drawhat = true
self.drawable = false
self.thrown = false
self.holdtimer = 0
self.active = false
self.static = true
self.x = self.player.x
self.y = self.player.y
end
function cappy:capture(b, a)
self.host = b
if self.host.portaled then
self.host:portaled()
end
self.player.static = true
self.player.active = false
self.player.drawable = false
self.active = false
self.static = true
self.drawable = true
self.thrown = false
if not releasenotice then
notice.new("to exit enemy: hold up\nthen press the run button", notice.white, 6)
releasenotice = true
end
end
function cappy:release()
self.player.static = false
self.player.active = true
self.player.drawable = true
if self.host then
self.player.x = self.host.x+(self.host.width/2)-(self.player.width/2)
self.player.y = self.host.y-self.player.height
end
if levelfinished then
self.player.active = true
self.player.speedx = 0
self.player.speedy = 0
else
self.player.speedy = -10
self.player.invincible = true
self.player.animationtimer = 2
self.player.animation = "invincible"
end
self.host = false
self.jumping = false
self.cooldown = 0
self:back()
end
function cappy:jump()
if self.host and self.host.speedy then
if self.jumping then
return
end
local force = -jumpforce - (math.abs(self.host.speedx) / maxrunspeed)*jumpforceadd
self.host.speedy = math.max(-jumpforce - jumpforceadd, force)
self.jumping = true
if self.host.width < 0.5 then
playsound(jumptinysound)
elseif self.host.width < 1 then
playsound(jumpsound)
else--if self.host.width < 2 then
playsound(jumpbigsound)
end
end
end
function cappy:fire()
local host = self.host
if self.host and self.host.speedy then
if host.shoot then
host:shoot(self.num)
end
if host.throwhammer then
host:throwhammer(self.dir)
--if host.t == "hammer" and objects["hammer"][#objects["hammer"]] then
-- objects["hammer"][#objects["hammer"]]:portaled()
--end
end
if host.explosion and not host.stomped then
host:stomp()
end
if host.timer then
host.timer = lakitothrowtime
end
end
end
function cappy:floorcollide(a, b)
if self:globalcollide(a, b) then
return false
end
return false
end
function cappy:leftcollide(a, b)
if self:globalcollide(a, b) then
return false
end
return false
end
function cappy:rightcollide(a, b)
if self:globalcollide(a, b) then
return false
end
return false
end
function cappy:ceilcollide(a, b)
if self:globalcollide(a, b) then
return false
end
end
function cappy:globalcollide(a, b)
if self.returning and (not self.host) and a == "player" then
self:back()
end
--capture
if tablecontains(enemies, a) then
self:capture(b, a)
elseif mariohammerkill[a] then
self:capture(b, a)
--[[b:shotted("right")
if a ~= "bowser" then
addpoints(firepoints[a], self.x, self.y)
end]]
elseif a == "enemy" then
self:capture(b, a)
--[[if b:shotted("right", false, false, true) ~= false then
addpoints(b.firepoints or 200, self.x, self.y)
end]]
end
return true
end