forked from Mari0-CE/Mari0-Community-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.lua
284 lines (241 loc) · 5.72 KB
/
box.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
box = class("box")
function box:init(x, y)
--PHYSICS STUFF
self.cox = x
self.coy = y
self.x = x-14/16
self.y = y-12/16
self.speedy = 0
self.speedx = 0
self.width = 12/16
self.height = 12/16
self.static = false
self.active = true
self.category = 9
self.parent = nil
self.portaloverride = true
self.mask = { true,
false, false, false, false, false,
false, true, false, true, true,
false, false, true, false, false,
true, true, false, false, true,
false, true, true, false, false,
true, false, true, true, true}
self.emancipatecheck = true
self.userect = adduserect(self.x, self.y, 12/16, 12/16, self)
--IMAGE STUFF
self.drawable = true
self.graphic = boximg
self.quad = boxquad[1]
self.offsetX = 6
self.offsetY = 2
self.quadcenterX = 6
self.quadcenterY = 6
self.rotation = 0 --for portals
self.gravitydirection = math.pi/2
self.falling = false
self.destroying = false
self.outtable = {}
self.portaledframe = false
end
function box:update(dt)
local friction = boxfrictionair
if self.falling == false then
friction = boxfriction
end
--Funnels and fuck
if self.funnel and not self.infunnel then
self:enteredfunnel(true)
end
if self.infunnel and not self.funnel then
self:enteredfunnel(false)
end
self.funnel = false
if not self.pushed then
if self.speedx > 0 then
self.speedx = self.speedx - friction*dt
if self.speedx < 0 then
self.speedx = 0
end
else
self.speedx = self.speedx + friction*dt
if self.speedx > 0 then
self.speedx = 0
end
end
else
self.pushed = false
end
self.rotation = 0
if self.parent then
local oldx = self.x
local oldy = self.y
self.x = self.parent.x+math.sin(-self.parent.pointingangle)*0.3
self.y = self.parent.y-math.cos(-self.parent.pointingangle)*0.3
if self.portaledframe == false then
for h, u in pairs(emancipationgrills) do
if u.active then
if u.dir == "hor" then
if inrange(self.x+6/16, u.startx-1, u.endx, true) and inrange(u.y-14/16, oldy, self.y, true) then
self:emancipate(h)
end
else
if inrange(self.y+6/16, u.starty-1, u.endy, true) and inrange(u.x-14/16, oldx, self.x, true) then
self:emancipate(h)
end
end
end
end
end
self.rotation = self.parent.rotation
end
self.userect.x = self.x
self.userect.y = self.y
--check if offscreen
if self.y > mapheight+2 then
self:destroy()
end
self.portaledframe = false
if self.destroying then
return true
else
return false
end
end
function box:globalcollide(a, b, c, d, dir)
if a == "platform" or a == "seesawplatform" then
if dir == "floor" then
if self.jumping and self.speedy < -jumpforce + 0.1 then
return true
end
else
return true
end
end
end
function box:ceilcollide(a, b)
if self:globalcollide(a, b, c, d, "ceil") then
return false
end
end
function box:leftcollide(a, b)
if self:globalcollide(a, b, c, d, "left") then
return false
end
if a == "button" then
self.y = b.y - self.height
self.x = b.x + b.width - 0.01
if self.speedy > 0 then
self.speedy = 0
end
return false
elseif a == "player" then
self.pushed = true
return false
end
end
function box:rightcollide(a, b)
if self:globalcollide(a, b, c, d, "right") then
return false
end
if a == "button" then
self.y = b.y - self.height
self.x = b.x - self.width+0.01
if self.speedy > 0 then
self.speedy = 0
end
return false
elseif a == "player" then
self.pushed = true
return false
end
end
function box:floorcollide(a, b)
if self:globalcollide(a, b, c, d, "floor") then
return false
end
if self.falling then
self.falling = false
end
if a == "enemy" and b.killedbyboxes then
if b.stompable then
b:stomp()
else
b:shotted("right", false, false, false)
end
addpoints(200, self.x, self.y)
playsound("stomp")
self.falling = true
self.speedy = -10
return false
end
end
function box:passivecollide(a, b)
if self:globalcollide(a, b, c, d, "passive") then
return false
end
if a == "player" then
if self.x+self.width > b.x+b.width then
self.x = b.x+b.width
else
self.x = b.x-self.width
end
end
end
function box:startfall()
self.falling = true
end
function box:emancipate()
if not self.destroying then
local speedx, speedy = self.speedx, self.speedy
if self.parent then
self.parent:cubeemancipate()
speedx = speedx + self.parent.speedx
speedy = speedy + self.parent.speedy
end
table.insert(emancipateanimations, emancipateanimation:new(self.x, self.y, self.width, self.height, self.graphic, self.quad, speedx, speedy, self.rotation, self.offsetX, self.offsetY, self.quadcenterX, self.quadcenterY))
self:destroy()
end
end
function box:destroy()
self.userect.delete = true
self.destroying = true
for i = 1, #self.outtable do
if self.outtable[i][1].input then
self.outtable[i][1]:input("toggle", self.outtable[i][2])
end
end
end
function box:addoutput(a, t)
table.insert(self.outtable, {a, t})
end
function box:used(id)
self.parent = objects["player"][id]
self.active = false
objects["player"][id]:pickupbox(self)
end
function box:dropped()
self.parent = nil
self.active = true
end
function box:portaled()
self.portaledframe = true
end
function box:enteredfunnel(inside)
if inside then
self.infunnel = true
else
self.infunnel = false
self.gravity = nil
end
end
function box:faithplate(dir)
self.falling = true
end
function box:onbutton(s)
if s then
self.quad = boxquad[2]
else
self.quad = boxquad[1]
end
end