forked from alesan99/mari0_ae
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipe.lua
224 lines (207 loc) · 5.54 KB
/
pipe.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
pipe = class:new()
function pipe:init(t, x, y, r)
self.cox = x
self.coy = y
self.x = x-1
self.y = y-1
self.width = 28/16 --smb: 22/16
self.height = 26/16
self.active = false
self.static = true
self.r = {unpack(r)}
table.remove(self.r, 1)
table.remove(self.r, 1)
self.world = 1
self.level = 1
self.sub = 0
self.exitid = 1
--defaults
self.dir = "down"
self.dir2 = false
self.exit = false
self.t = "pipe"
self.size = "big"
self.legacy = true
if t == "pipe" then
self.dir = "down"
self.dir2 = "right"
self.t = "pipe"
elseif t == "pipe2" then
self.dir = "up"
self.dir2 = "left"
self.t = "pipe"
elseif t == "pipespawn" then
self.dir = "up"
self.dir2 = false
self.t = "pipespawn"
elseif t == "pipespawndown" then
self.dir = "down"
self.dir2 = false
self.t = "pipespawn"
elseif t == "pipespawnhor" then
self.dir = "right"
if inmap(x+1, y) and tilequads[map[x+1][y][1]] and tilequads[map[x+1][y][1]]["collision"] then
self.dir = "left"
end
self.dir2 = false
self.t = "pipespawn"
elseif t == "warppipe" then
self.dir = "down"
self.t = "warppipe"
end
--right click menu
if #self.r > 0 and self.r[1] ~= "link" then
if self.t == "pipe" then
--target sub, exitid, direction
local v = convertr(self.r[1], {"num", "num", "string", "string"}, true)
self.sub = v[1]
self.exitid = v[2] or 1
if v[3] then
self.dir2 = false
self.dir = v[3]
self.size = v[4]
self.legacy = false
end
elseif self.t == "pipespawn" then
--entry sub, exitid, direction
local v = convertr(self.r[1], {"num", "num", "string", "string"}, true)
self.sub = v[1]
self.exitid = v[2] or 1
if v[3] then
self.dir = v[3]
self.size = v[4]
self.legacy = false
end
elseif self.t == "warppipe" then
--world, level, direction
local v = convertr(self.r[1], {"string", "num", "string", "string"}, true)
local world = tonumber(v[1]) or 1
if not tonumber(v[1]) then
local f1 = alphabet:find(tostring(v[1]))
if f1 then
world = 9+f1
else
world = 1
end
end
local worldstring = world
if hudworldletter and tonumber(world) and world > 9 and world <= 9+#alphabet then
worldstring = alphabet:sub(world-9, world-9)
end
self.worldstring = worldstring
self.world = world
self.level = v[2] or 1
if v[3] then
self.dir = v[3]
self.size = v[4]
self.legacy = false
end
end
table.remove(self.r, 1)
end
--set type
if self.t == "pipe" then
self.quad = pipesquad[1][self.dir]
elseif self.t == "pipespawn" then
--decide if it should be exited from
local targetsublevel = self.sub or 0
local exitid = self.exitid or 1
--testing sublevels (I KNOW YOULL ALSO NEED THIS)
--print(prevsublevel, mariosublevel, pipeexitid)
--print(targetsublevel, targetsublevel, exitid)
if (prevsublevel == targetsublevel or
(mariosublevel == targetsublevel and blacktime == sublevelscreentime)) and (((not pipeexitid) and exitid == 1) or
(pipeexitid == exitid)) then
pipestartx = x
pipestarty = y
pipestartdir = self.dir
end
self.exit = true
self.quad = pipesquad[2][self.dir]
elseif self.t == "warppipe" then
--insert warp pipe numbers
table.insert(warpzonenumbers, {x, y, self.worldstring})
self.quad = pipesquad[3][self.dir]
end
--dir
self.scissor = {}
self.scissor["up"] = {self.cox-4, self.coy-1-4, 5, 4}
self.scissor["down"] = {self.cox-4, self.coy, 5, 4}
self.scissor["left"] = {self.cox-1-4, self.coy-4, 4, 5}
self.scissor["right"] = {self.cox, self.coy-4, 4, 5}
--set size
if self.size == "big" then
self.x = x-1
self.y = y
elseif self.size == "giant" then
self.width = self.width*2
self.height = self.height*2
self.x = x-2
self.y = y
elseif self.size == "small" then
self.width = 1
self.height = 1
self.x = x-.5
self.y = y
elseif self.size == "tiny" then
self.width = 10/16
self.height = 10/16
self.x = x-.5
self.y = y
end
end
function pipe:draw()
love.graphics.draw(pipesimg, self.quad, math.floor((self.cox-1-xscroll)*16*scale), ((self.coy-1-yscroll)*16-8)*scale, 0, scale, scale)
end
function pipe:inside(dir, c, b) --direction of entrance, cox or coy, player
if (not self.exit) then
local p = b.x+b.width/2
local px, pw, py, ph = b.x, b.width, b.y, b.height
if hugemario then --hugemario cheat should still enter pipes i guess
pw, ph = 24/16, 24/16
px = b.x+b.width/2-pw/2
py = b.y+b.height-ph
end
local enterdir = false
if dir == self.dir then --multiple enter directions for backwards compatibility
enterdir = self.dir
elseif dir == self.dir2 then
enterdir = self.dir2
end
if enterdir then
if enterdir == "up" or enterdir == "down" then
if c == self.coy then
if (px >= self.x-self.width/2 and px+pw <= self.x+self.width/2) or bigmario then
return true
end
end
elseif enterdir == "left" or enterdir == "right" then
if c == self.cox then
--accurate pipe entering
--[[if py >= self.y-self.height and py+ph <= self.y then
return true
end]]
--mari0 1.6 pipe entering
--all it needs is a collision
if ((ph <= self.height) or bigmario) and --should he fit at all?
py+ph > self.coy-1 and py < self.coy and --is the player touching the pipe entity
py+ph*.4 < self.coy then --is the middle of the player within the pipe? (just to make it resonable)
return true
end
end
end
end
end
return false
end
function pipe:opp(dir)
if dir == "down" then
return "up"
elseif dir == "up" then
return "down"
elseif dir == "left" then
return "right"
elseif dir == "right" then
return "left"
end
end