forked from KirbyKid256/mari0_aces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
levelscreen.lua
413 lines (371 loc) · 13.8 KB
/
levelscreen.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
405
406
407
408
409
410
411
412
413
function levelscreen_load(reason, i)
--BLOCKTOGGLE STUFF
solidblocksred = true
solidblocksblue = true
solidblocksyellow = true
solidblocksgreen = true
if reason ~= "sublevel" and reason ~= "vine" and reason ~= "animation" and testlevel then
stoptestinglevelsafe = true
marioworld = testlevelworld
mariolevel = testlevellevel
editormode = true
testlevel = false
startlevel(marioworld .. "-" .. mariolevel)
return
end
windsound:stop()
if not continuesublevelmusic then
music:disableintromusic()
end
levelscreenimagecheck = false
checkcheckpoint = false
dcfinish = false
--check if lives left
livesleft = false
for i = 1, players do
if mariolivecount == false or (mariolives[i] and mariolives[i] > 0) then
livesleft = true
end
end
if reason == "sublevel" then
gamestate = "sublevelscreen"
blacktime = sublevelscreentime
sublevelscreen_level = i
elseif reason == "vine" then
gamestate = "sublevelscreen"
blacktime = sublevelscreentime
sublevelscreen_level = i
elseif reason == "dc" then
gamestate = "dclevelscreen"
blacktime = 0.8
elseif livesleft then
gamestate = "levelscreen"
blacktime = levelscreentime
if reason == "next" or reason == "animation" then --next level
respawnsublevel = 0
checkpointx = nil
checkpointsublevel = false
--check if next level doesn't exist
if not dcplaying then
local gamefinished = false
if not love.filesystem.getInfo("mappacks/" .. mappack .. "/" .. marioworld .. "-" .. mariolevel .. ".txt") then
gamefinished = true
--check incase there are fewer than 4 levels in the world
if reason == "next" and tonumber(mariolevel) and mariolevel <= 4 then
if love.filesystem.getInfo("mappacks/" .. mappack .. "/" .. marioworld+1 .. "-1.txt") then
marioworld = marioworld + 1
mariolevel = 1
gamefinished = false
end
end
end
if gamefinished then
if testlevel then
testlevelworld = 1
testlevellevel = 1
notice.new("You have finished this mappack!", notice.white, 5)
stoptestinglevel()
else
gamestate = "mappackfinished"
blacktime = gameovertime
if love.filesystem.getInfo("mappacks/" .. mappack .. "/endingmusic.ogg") or love.filesystem.getInfo("mappacks/" .. mappack .. "/endingmusic.mp3") then
playsound(endingmusic)
else
music:play("princessmusic")
end
if love.filesystem.getInfo("mappacks/" .. mappack .. "/ending.png") then
levelscreenimage = love.graphics.newImage("mappacks/" .. mappack .. "/ending.png")
levelscreenimagecheck = true
end
end
else
if love.filesystem.getInfo("mappacks/" .. mappack .. "/" .. marioworld .. "-" .. mariolevel .. "levelscreen.png") then
levelscreenimage = love.graphics.newImage("mappacks/" .. mappack .. "/" .. marioworld .. "-" .. mariolevel .. "levelscreen.png")
levelscreenimagecheck = true
elseif love.filesystem.getInfo("mappacks/" .. mappack .. "/" .. marioworld .. "levelscreen.png") then
levelscreenimage = love.graphics.newImage("mappacks/" .. mappack .. "/" .. marioworld .. "levelscreen.png")
levelscreenimagecheck = true
elseif love.filesystem.getInfo("mappacks/" .. mappack .. "/levelscreen.png") then
levelscreenimage = love.graphics.newImage("mappacks/" .. mappack .. "/levelscreen.png")
levelscreenimagecheck = true
end
end
else
dcfinish = true
blacktime = 0.8
end
else
checkcheckpoint = true
if reason == "death" and i then
respawnsublevel = i
--sublevelscreen_level = i
end
if not dcplaying then
if love.filesystem.getInfo("mappacks/" .. mappack .. "/" .. marioworld .. "-" .. mariolevel .. "levelscreen.png") then
levelscreenimage = love.graphics.newImage("mappacks/" .. mappack .. "/" .. marioworld .. "-" .. mariolevel .. "levelscreen.png")
levelscreenimagecheck = true
elseif love.filesystem.getInfo("mappacks/" .. mappack .. "/" .. marioworld .. "levelscreen.png") then
levelscreenimage = love.graphics.newImage("mappacks/" .. mappack .. "/" .. marioworld .. "levelscreen.png")
levelscreenimagecheck = true
elseif love.filesystem.getInfo("mappacks/" .. mappack .. "/levelscreen.png") then
levelscreenimage = love.graphics.newImage("mappacks/" .. mappack .. "/levelscreen.png")
levelscreenimagecheck = true
end
end
end
else
gamestate = "gameover"
blacktime = gameovertime
playsound(gameoversound)
checkpointx = nil
if not dcplaying and love.filesystem.getInfo("mappacks/" .. mappack .. "/gameover.png") then
levelscreenimage = love.graphics.newImage("mappacks/" .. mappack .. "/gameover.png")
levelscreenimagecheck = true
end
end
if editormode then
blacktime = 0
end
if reason ~= "initial" and not everyonedead then
updatesizes()
updateplayerproperties()
end
if marioworld == 1 or mariolevel == 1 then
blacktime = blacktime * 1.5
end
coinframe = 1
love.graphics.setBackgroundColor(0, 0, 0)
levelscreentimer = 0
--reached worlds
local updated = false
if not reachedworlds[mappack] then
reachedworlds[mappack] = {}
end
if tonumber(marioworld) then
if not reachedworlds[mappack][marioworld] and gamestate ~= "mappackfinished" then
for j = 1, marioworld do
for k = 1, #mappacklevels[j] do
if reachedworlds[mappack][j] == nil and love.filesystem.getInfo("mappacks/" .. mappack .. "/" .. j .. "-" .. k .. ".txt") then
reachedworlds[mappack][j] = {}
if reachedworlds[mappack][j][k] == nil then
reachedworlds[mappack][j][k] = false
end
end
end
end
if not reachedworlds[mappack][marioworld][mariolevel] then
reachedworlds[mappack][marioworld][mariolevel] = true
updated = true
end
end
end
if updated then
saveconfig()
end
server_levelscreen(reason, i)
end
function levelscreen_update(dt)
if endingmusic:isPlaying() then
levelscreentimer = 1
else
levelscreentimer = levelscreentimer + dt
end
if CLIENT and levelscreentimer > blacktime+5 and (love.keyboard.isDown("escape") or (android and jumpkey(1))) then --netplay
net_quit()
end
if levelscreentimer > blacktime and net_levelscreensync() then
if gamestate == "levelscreen" then
gamestate = "game"
if dcplaying then
if dcfinish then
menu_load()
dcplaying = false
gamestate = "mappackmenu"
mappacktype = "daily_challenge"
mappackhorscroll = 2
mappackhorscrollsmooth = 2
else
startlevel("dc")
end
else
if respawnsublevel ~= 0 then
actualsublevel = respawnsublevel
startlevel(marioworld .. "-" .. mariolevel .. "_" .. respawnsublevel)
mariosublevel = actualsublevel --this nonsensical sublevel logic is making me lose my mind, remove this is someone complains
else
mariosublevel = respawnsublevel
actualsublevel = 0
startlevel(marioworld .. "-" .. mariolevel)
end
end
elseif gamestate == "sublevelscreen" then
gamestate = "game"
actualsublevel = sublevelscreen_level
startlevel(sublevelscreen_level, "sublevel")
elseif gamestate == "dclevelscreen" then
gamestate = "game"
startlevel("dc")
else
if SERVER or CLIENT then
lobby_load()
else
menu_load()
end
if dcplaying then
dcplaying = false
gamestate = "mappackmenu"
mappacktype = "daily_challenge"
mappackhorscroll = 2
mappackhorscrollsmooth = 2
end
end
return
end
end
function levelscreen_draw()
local properprintfunc = properprintF
if hudoutline then
properprintfunc = properprintFbackground
end
local properprintbasicfunc = properprint
if hudoutline then
properprintbasicfunc = properprintbackground
end
if levelscreentimer < blacktime - blacktimesub and levelscreentimer > blacktimesub then
love.graphics.setColor(1, 1, 1, 1)
if gamestate == "levelscreen" and not dcplaying then
if levelscreenimagecheck then
love.graphics.draw(levelscreenimage, 0, 0, 0, scale, scale)
end
local world = marioworld
if hudworldletter and tonumber(world) and world > 9 and world <= 9+#alphabet then
world = alphabet:sub(world-9, world-9)
elseif world == "M" then
world = " "
end
properprintfunc("world " .. world .. "-" .. mariolevel, (width/2*16)*scale-40*scale, 72*scale - (players-1)*6*scale)
for i = 1, players do
local x = (width/2*16)*scale-29*scale
local y = (97 + (i-1)*20 - (players-1)*8)*scale
local v = characters.data[mariocharacter[i]]
for j = 1, #characters.data[mariocharacter[i]]["animations"] do
love.graphics.setColor(unpack(mariocolors[i][j]))
if playertype == "classic" or playertype == "cappy" or not portalgun then--no portal gun
love.graphics.draw(v["animations"][j], v["small"]["idle"][5], x+(v.smalloffsetX)*scale, y+(11-v.smalloffsetY)*scale, 0, scale, scale, v.smallquadcenterX, v.smallquadcenterY)
else
love.graphics.draw(v["animations"][j], v["small"]["idle"][3], x+(v.smalloffsetX)*scale, y+(11-v.smalloffsetY)*scale, 0, scale, scale, v.smallquadcenterX, v.smallquadcenterY)
end
end
--hat
offsets = customplayerhatoffsets(mariocharacter[i], "hatoffsets", "idle") or hatoffsets["idle"]
if #mariohats[i] > 1 or mariohats[i][1] ~= 1 then
local yadd = 0
for j = 1, #mariohats[i] do
love.graphics.setColor(1, 1, 1)
love.graphics.draw(hat[mariohats[i][j]].graphic, hat[mariohats[i][j]].quad[1], x+(v.smalloffsetX)*scale, y+(11-v.smalloffsetY)*scale, 0, scale, scale, v.smallquadcenterX - hat[mariohats[i][j]].x + offsets[1], v.smallquadcenterY - hat[mariohats[i][j]].y + offsets[2] + yadd)
yadd = yadd + hat[mariohats[i][j]].height
end
elseif #mariohats[i] == 1 then
love.graphics.setColor(mariocolors[i][1])
love.graphics.draw(hat[mariohats[i][1]].graphic, hat[mariohats[i][1]].quad[1], x+(v.smalloffsetX)*scale, y+(11-v.smalloffsetY)*scale, 0, scale, scale, v.smallquadcenterX - hat[mariohats[i][1]].x + offsets[1], v.smallquadcenterY - hat[mariohats[i][1]].y + offsets[2])
end
love.graphics.setColor(1, 1, 1, 1)
if playertype == "classic" or playertype == "cappy" or not portalgun then--no portal gun
love.graphics.draw(v["animations"][0], v["small"]["idle"][5], x+(v.smalloffsetX)*scale, y+(11-v.smalloffsetY)*scale, 0, scale, scale, v.smallquadcenterX, v.smallquadcenterY)
else
love.graphics.draw(v["animations"][0], v["small"]["idle"][3], x+(v.smalloffsetX)*scale, y+(11-v.smalloffsetY)*scale, 0, scale, scale, v.smallquadcenterX, v.smallquadcenterY)
end
if mariolivecount == false then
properprintfunc("* inf", (width/2*16)*scale-8*scale, y+7*scale)
else
properprintfunc("* " .. mariolives[i], (width/2*16)*scale-8*scale, y+7*scale)
end
end
if mappack == "smb" and marioworld == 2 and mariolevel == 1 then
local s = "remember that you can run with "
for i = 1, #controls[1]["run"] do
s = s .. controls[1]["run"][i]
if i ~= #controls[1]["run"] then
s = s .. "-"
end
end
properprintfunc(s, (width/2*16)*scale-string.len(s)*4*scale, 200*scale)
elseif mappack == "portal" and marioworld == 1 and mariolevel == 1 then
local s = "you can remove your portals with "
for i = 1, #controls[1]["reload"] do
s = s .. controls[1]["reload"][i]
if i ~= #controls[1]["reload"] then
s = s .. "-"
end
end
properprintfunc(s, (width/2*16)*scale-string.len(s)*4*scale, 190*scale)
local s = "you can grab cubes and push buttons with "
for i = 1, #controls[1]["use"] do
s = s .. controls[1]["use"][i]
if i ~= #controls[1]["use"] then
s = s .. "-"
end
end
properprintfunc(s, (width/2*16)*scale-string.len(s)*4*scale, 200*scale)
elseif levelscreentext[marioworld .. "-" .. mariolevel] then
local s = levelscreentext[marioworld .. "-" .. mariolevel]
properprintbasicfunc(s, (width/2*16)*scale-string.len(s)*4*scale, 200*scale)
end
elseif gamestate == "mappackfinished" then
if levelscreenimagecheck then
love.graphics.draw(levelscreenimage, 0, 0, 0, scale, scale)
end
love.graphics.setColor(endingtextcolor)
properprintfunc(endingtext[1], width*8*scale-string.len(endingtext[1])*4*scale, 120*scale)
properprintfunc(endingtext[2], width*8*scale-string.len(endingtext[2])*4*scale, 140*scale)
love.graphics.setColor(1, 1, 1, 1)
elseif gamestate == "dclevelscreen" or dcplaying then
if dcfinish then
properprintfunc("daily challenge completed!", width*8*scale-string.len("daily challenge completed!")*4*scale, 120*scale)
else
properprintfunc("daily challenge", width*8*scale-string.len("daily challenge")*4*scale, 120*scale)
properprintfunc(DCchalobjective, width*8*scale-string.len(DCchalobjective)*4*scale, 140*scale)
end
else
if levelscreenimagecheck then
love.graphics.draw(levelscreenimage, 0, 0, 0, scale, scale)
end
properprintfunc("game over", (width/2*16)*scale-40*scale, 120*scale)
end
love.graphics.translate(0, -yoffset*scale)
if yoffset < 0 then
love.graphics.translate(0, yoffset*scale)
end
if hudvisible then
drawHUD()
end
elseif CLIENT and levelscreentimer > blacktime then
local s = "waiting for players..."
properprintfunc(s, (width/2*16)*scale-string.len(s)*4*scale, 100*scale)
if levelscreentimer > blacktime+5 then
s = "something went wrong. press esc to quit"
properprintfunc(s, (width/2*16)*scale-string.len(s)*4*scale, 140*scale)
end
end
end
local function levelscreen_skip()
local timeskip = blacktime - blacktimesub
levelscreentimer = math.max(levelscreentimer, timeskip)
end
function levelscreen_keypressed(key)
if levelscreentimer > 0.4 then
if key == "return" or key == controls[1]["jump"][1] then
levelscreen_skip()
return
end
end
end
function levelscreen_joystickpressed(joystick, button)
if levelscreentimer > 0.4 then
local s = controls[1]["jump"]
if s[1] == "joy" and joystick == s[2] and s[3] == "but" and button == s[4] then
levelscreen_skip()
return
end
end
end