forked from alesan99/mari0_ae
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathice.lua
308 lines (276 loc) · 7.83 KB
/
ice.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
ice = class:new()
function ice:init(x, y, w, h, a, enemy)
self.width = (math.ceil(w) or 1)+.5
self.height = (math.ceil(h) or 1)+.5
self.x = x-self.width/2
self.y = y-self.height
self.speedx = 0
self.speedy = 0
self.active = true
self.static = false
self.activestatic = false
self.category = 32
self.mask = {true}
self.rotation = 0
self.timer = 0
self.offsetX = 0
self.shaketimer = 0
self.a = a
self.enemy = enemy
self.oldenemystatic = self.enemy.static
self.oldenemyactive = self.enemy.active
self.oldenemyresistsyoshitounge = self.enemy.resistsyoshitounge
self.oldenemycustomscissor = self.enemy.customscissor
if self.enemy.freeze then
self.enemy:freeze()
end
if enemy.static or math.abs(enemy.speedy) > 2 or (enemy.gravity and enemy.gravity == 0) then
self.static = true
self.activestatic = true
self.y = enemy.y+enemy.height/2-self.height/2
self.dontfallafterfreeze = enemy.dontfallafterfreeze
end
if enemy.dontfallafterfreeze then
self.oldenemytrackspeed = enemy.trackspeed
end
enemy.iceblock = self
self.falling = false
self:hold()
end
function ice:update(dt)
if (not self.enemy) or self.enemy.shot or self.enemy.delete then
self:meltice()
return true
end
self:hold()
if self.funnel then
if self.static then
self.static = false
self.activestatic = false
end
self.gravity = yacceleration
self.funnel = false
end
if edgewrapping then --wrap around screen
local minx, maxx = -self.width, mapwidth
if self.x < minx then
self.x = maxx
elseif self.x > maxx then
self.x = minx
end
end
if math.abs(self.speedx) < 1 then
self.timer = self.timer + dt
end
if self.static and (not self.dontfallafterfreeze) then
--start falling if static
if self.timer > iceblockairtime then
self.static = false
self.activestatic = false
self.falling = true
elseif self.timer > iceblockairtime-1 then
self.shaketimer = (self.shaketimer + 8*dt)%1
self.offsetX = math.floor(math.abs(self.shaketimer-.5)*4+.5)
end
else
--unfreeze
if self.timer > freezetime then
self:meltice()
elseif self.timer > freezetime-1 then
self.shaketimer = (self.shaketimer + 8*dt)%1
self.offsetX = math.floor(math.abs(self.shaketimer-.5)*4+.5)
end
end
--[[hold player if falling
if self.falling then
local ydiff = self.speedy*dt
local condition = false
if ydiff < 0 then
condition = "ignoreplatforms"
end
for j, w in pairs(objects["player"]) do
if inrange(w.x, self.x-w.width, self.x+self.width) then --vertical carry
if ((w.y == self.y - w.height) or ((w.y+w.height >= self.y-0.1 and w.y+w.height < self.y+0.1)))
and (not w.jumping) then
if not checkintile(w.x, w.y+ydiff, w.width, w.height, tileentities, w) then
w.y = self.y-w.height
w.falling = false
w.jumping = false
w.speedy = 0
--w.speedy = b.speedy
end
end
end
end
end]]
end
function ice:draw(enemylayer)
if (not enemylayer) and self.enemy and self.enemy.drawable then
return false
end
for x = 1, self.width*2 do
for y = 1, self.height*2 do
local q = 5
if x == 1 and y == 1 then
q = 1
elseif x == self.width*2 and y == 1 then
q = 3
elseif x == 1 and y == self.height*2 then
q = 7
elseif x == self.width*2 and y == self.height*2 then
q = 9
elseif y == 1 then
q = 2
elseif x == 1 then
q = 4
elseif y == self.height*2 then
q = 8
elseif x == self.width*2 then
q = 6
end
love.graphics.draw(iceimg, icequad[q], math.floor(((self.x-xscroll)*16+8*(x-1)+self.offsetX)*scale), math.floor(((self.y-yscroll)*16-8+8*(y-1))*scale), 0, scale, scale)
end
end
end
function ice:rightcollide(a, b)
if self:globalcollide(a, b) then
return false
end
if (not self.static) and self.speedx == 0 and a == "player" and b.speedx <= -iceblockkickminspeed then
--kick
self.speedx = -iceblockspeed
playsound(shotsound)
end
if self.speedx > 0 then
--kill enemies
if mariohammerkill[a] then
b:shotted("right")
if a ~= "bowser" then
addpoints(firepoints[a], self.x, self.y)
end
return false
elseif a == "enemy" and b:shotted("right", false, false, true) ~= false and (not (b.resistsenemykill or b.resistseverything)) then
addpoints(b.firepoints or 200, self.x, self.y)
return false
else
self:meltice("destroy")
end
end
end
function ice:leftcollide(a, b)
if self:globalcollide(a, b) then
return false
end
if (not self.static) and self.speedx == 0 and a == "player" and b.speedx >= iceblockkickminspeed then
--kick
self.speedx = iceblockspeed
playsound(shotsound)
end
if self.speedx < 0 then
--kill enemies
if mariohammerkill[a] then
b:shotted("right")
if a ~= "bowser" then
addpoints(firepoints[a], self.x, self.y)
end
return false
elseif a == "enemy" and b:shotted("right", false, false, true) ~= false and (not (b.resistsenemykill or b.resistseverything)) then
addpoints(b.firepoints or 200, self.x, self.y)
return false
else
self:meltice("destroy")
end
end
end
function ice:ceilcollide(a, b)
if self:globalcollide(a, b) then
return false
end
end
function ice:floorcollide(a, b)
if self:globalcollide(a, b) then
return false
end
if self.falling and (not (self.speedy > 0 and self.speedy <= yacceleration*gdt)) then
self:meltice("destroy")
return false
end
if (a == "player" and b.gravitydir == "down") then
self:meltice("destroy")
return false
end
end
function ice:passivecollide(a, b)
if self:globalcollide(a, b) then
return false
end
end
function ice:globalcollide(a, b)
if a == "screenboundary" or a == "checkpointflag" then
return true
elseif (a == "fireball" and b.t == "fireball") or a == "castlefirefire" or a == "longfire" or a == "fire" or a == "plantfire" or (a == "brofireball" and b.t ~= "ice") or a == "upfire" or a == "angrysun" or b.meltsice then
self:meltice()
end
end
function ice:hold()
--hold enemy
local b = self.enemy
b.static = true
b.active = false
b.resistsyoshitounge = true
b.x = self.x+self.width/2-b.width/2
b.y = self.y+self.height/2-b.height/2
b.frozen = true
b.customscissor = {self.x, self.y, self.width, self.height}
if b.dontfallafterfreeze then
b.trackspeed = 0
else
b.trackable = false
end
end
function ice:release()
--release enemy
local b = self.enemy
b.static = self.oldenemystatic
b.active = self.oldenemyactive
b.resistsyoshitounge = self.oldenemyresistsyoshitounge
b.customscissor = self.oldenemycustomscissor
b.frozen = false
b.iceblock = nil
if b.dontfallafterfreeze then
b.trackspeed = self.oldenemytrackspeed
end
end
function ice:meltice(destroy)
self:release()
self.active = false
if destroy then
playsound(iciclesound)
local debris = rgbaToInt(80,210,250,255)
if blockdebrisquads[debris] then
table.insert(blockdebristable, blockdebris:new(self.x+self.width/2, self.y+self.height/2, 3.5, -23, blockdebrisimage, blockdebrisquads[debris][spriteset]))
table.insert(blockdebristable, blockdebris:new(self.x+self.width/2, self.y+self.height/2, -3.5, -23, blockdebrisimage, blockdebrisquads[debris][spriteset]))
table.insert(blockdebristable, blockdebris:new(self.x+self.width/2, self.y+self.height/2, 3.5, -14, blockdebrisimage, blockdebrisquads[debris][spriteset]))
table.insert(blockdebristable, blockdebris:new(self.x+self.width/2, self.y+self.height/2, -3.5, -14, blockdebrisimage, blockdebrisquads[debris][spriteset]))
end
local b = self.enemy
b.frozen = true
if mariohammerkill[self.a] then
b:shotted("right")
if a ~= "bowser" then
addpoints(firepoints[a], self.x, self.y)
end
elseif self.a == "enemy" then
if (not b.resistsiceblock) and (not b.resistsenemykill) and (not b.resistseverything) and (not b.resistseverything) and b:shotted("right", nil, nil, false, true) then
addpoints(firepoints[b.t] or 100, self.x, self.y)
end
else
b.instantdelete = true
end
b.frozen = false
end
self.instantdelete = true
end
function ice:laser()
self:meltice()
end