forked from alesan99/mari0_ae
-
Notifications
You must be signed in to change notification settings - Fork 1
/
donut.lua
235 lines (204 loc) · 5.65 KB
/
donut.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
donut = class:new() --it took a long time, but now you can eat donuts in Mari0. BEST MOD 10/10. "Totally Mind blowing" -Maurice
function donut:init(x, y, t, respawn, r)
--PHYSICS STUFF
self.x = x-1
self.y = y-1
self.cox = x
self.coy = y
self.speedy = 0
self.speedx = 0
self.width = 1
self.height = 1
self.static = true
self.active = true
self.category = 2
self.gravity = 0
self.portalable = false
self.mask = {true}
self.emancipatecheck = false
self.autodelete = true
self.PLATFORM = true
--IMAGE STUFF
self.drawable = true
self.graphic = donutimage
self.quadi = 2
self.quad = starquad[spriteset][self.quadi+1]
self.offsetX = 8
self.offsetY = 0
self.quadcenterX = 8
self.quadcenterY = 8
self.rotation = 0 --for portals
self.direction = "left"
self.animationtimer = 0
self.t = t or "donut"
if self.t == "donutlast" then
self.last = true
self.quadi = 0
self.quad = starquad[spriteset][self.quadi+1]
end
self.falling = false
self.falling = false
self.fallingtimer = 0
self.shaketimer = 0
self.respawn = respawn or false
if self.respawn then
self.drawable = false
self.active = false
if self.t == "donutlast" then
self.respawntimer = 4
else
self.respawntimer = 10
end
self.autodelete = false
end
self.dorespawn = true --should it even respawn at all?
if r then
self.r = r
local v = convertr(r, {"bool"}, true)
if v[1] ~= nil then
self.dorespawn = v[1]
end
end
self.trackplatform = true
self.checktable = {}
for i, v in pairs(enemies) do
if objects[v] and underwater == false then
table.insert(self.checktable, v)
end
end
table.insert(self.checktable, "player")
end
function donut:update(dt)
if self.respawn then
self.respawntimer = self.respawntimer - dt
if self.respawntimer < 0 and onscreen(self.x, self.y) then
self:appear()
else
return false
end
end
if self.falling then
if self.fallingtimer > goombadeathtime then
self.speedy = 8
local x, y, y2 = self.cox, math.floor(self.y+17/16), math.floor(self.y+16/16)
if (not inmap(x, y)) or (not tilequads[map[x][y][1]].collision and inmap(x, y2) and not tilequads[map[x][y2][1]].collision) then --stop players from falling through ground
for i, v in pairs(self.checktable) do --Make mario stay on donut when donut is falling (makes mario fall through ground)
for j, w in pairs(objects[v]) do
if ((not w.gravity) or w.gravity ~= 0) and (not w.jumping) and inrange(w.x, self.x-w.width, self.x+self.width) then
if inrange(w.y, self.y - w.height - 0.1, self.y - w.height + 0.1) then
local x1, y1 = math.ceil(w.x+0.001), math.ceil(self.y+self.height-.5)
local x2, y2 = math.ceil(w.x+w.width-0.001), math.ceil(self.y+self.height-.5)
local maxy, col = math.huge, false
if (inmap(x1, y1) and tilequads[map[x1][y1][1]]:getproperty("collision", x1, y1) and not tilequads[map[x1][y1][1]]:getproperty("invisible", x1, y1)) then
maxy = y1-1-w.height
elseif (inmap(x2, y2) and tilequads[map[x2][y2][1]]:getproperty("collision", x2, y2) and not tilequads[map[x2][y2][1]]:getproperty("invisible", x2, y2)) then
maxy = y2-1-w.height
end
if #checkrect(w.x, self.y - (12/16) + self.speedy*dt, w.width, 12/16, {"donut"}, nil, "donut") >= 3 then
maxy = y2-1-w.height
end
w.y = math.min(maxy, self.y - w.height + self.speedy*dt)
end
end
end
end
end
self.offsetX = 8
self.trackable = false
elseif self.last then
local on = false --on top
for j, w in pairs(objects["player"]) do
if (not w.jumping and inrange(w.x, self.x-w.width, self.x+self.width)) then
on = true
break
end
end
if on then
self.fallingtimer = self.fallingtimer + dt
self.quad = starquad[spriteset][self.quadi+2]
self.shaketimer = (self.shaketimer + 8*dt)%1
self.offsetX = 7+math.floor(math.abs(self.shaketimer-.5)*4+.5)
else
self.falling = false
self.fallingtimer = 0
self.quad = starquad[spriteset][self.quadi+1]
self.offsetX = 8
self.shaketimer = 0
end
else
self.fallingtimer = self.fallingtimer + dt
self.quad = starquad[spriteset][self.quadi+2]
self.shaketimer = (self.shaketimer + 8*dt)%1
self.offsetX = 7+math.floor(math.abs(self.shaketimer-.5)*4+.5)
end
return false
end
end
function donut:leftcollide(a, b)
if self:globalcollide(a, b) then
return false
end
return false
end
function donut:rightcollide(a, b)
if self:globalcollide(a, b) then
return false
end
return false
end
function donut:ceilcollide(a, b)
if self:globalcollide(a, b) then
return false
end
if a == "player" then
if b.size ~= -1 then
self.falling = true
self.static = false
end
elseif a == "thwomp" or a == "skewer" then
self.falling = true
self.last = false
self.static = false
end
return true
end
function donut:globalcollide(a, b)
end
function donut:floorcollide(a, b)
if self:globalcollide(a, b) then
return false
end
return false
end
function donut:passivecollide(a, b)
self:leftcollide(a, b)
return false
end
function donut:autodeleted()
--respawn
if not self.dorespawn then
return
end
if self.t == "donutlast" or self.t == "donut" then
local obj = donut:new(self.cox, self.coy, self.t, true)
if self.trackdonut then
obj.trackable = true
obj.trackspeed = 0
local succ = trackobject(self.cox, self.coy, obj, "donut")
end
table.insert(objects["donut"], obj)
end
end
function donut:appear()
self.drawable = true
self.active = true
self.respawn = false
self.autodelete = true
self.trackspeed = nil
makepoof(self.x+self.width/2, self.y+self.height/2, "makerpoof")
end
function donut:dotrack(track)
if track then
self.trackdonut = true
end
end