1function menu_load()
2	love.audio.stop()
3	editormode = false
4	gamestate = "menu"
5	selection = 1
6	coinanimation = 1
7	love.graphics.setBackgroundColor(92, 148, 252)
8	scrollsmoothrate = 4
9	optionstab = 2
10	optionsselection = 1
11	skinningplayer = 1
12	rgbselection = 1
13	mappackselection = 1
14	onlinemappackselection = 1
15	mappackhorscroll = 0
16	mappackhorscrollsmooth = 0
17	checkpointx = false
18	love.graphics.setBackgroundColor(backgroundcolor[1])
19
20	controlstable = {"left", "right", "up", "down", "run", "jump", "reload", "use", "aimx", "aimy", "portal1", "portal2"}
21
22	portalanimation = 1
23	portalanimationtimer = 0
24	portalanimationdelay = 0.08
25
26	infmarioY = 0
27	infmarioR = 0
28
29	infmarioYspeed = 200
30	infmarioRspeed = 4
31
32	RGBchangespeed = 200
33	huechangespeed = 0.5
34	spriteset = 1
35
36	portalcolors = {}
37	for i = 1, players do
38		portalcolors[i] = {}
39	end
40
41	continueavailable = false
42	if love.filesystem.exists("suspend.txt") then
43		continueavailable = true
44	end
45
46	mariolevel = 1
47	marioworld = 1
48	mariosublevel = 0
49
50	--load 1-1 as background
51	loadbackground("1-1.txt")
52
53	skipupdate = true
54end
55
56function menu_update(dt)
57	--coinanimation
58	coinanimation = coinanimation + dt*6.75
59	while coinanimation > 6 do
60		coinanimation = coinanimation - 5
61	end
62
63	if mappackscroll then
64		--smooth the scroll
65		if mappackscrollsmooth > mappackscroll then
66			mappackscrollsmooth = mappackscrollsmooth - (mappackscrollsmooth-mappackscroll)*dt*5-0.1*dt
67			if mappackscrollsmooth < mappackscroll then
68				mappackscrollsmooth = mappackscroll
69			end
70		elseif mappackscrollsmooth < mappackscroll then
71			mappackscrollsmooth = mappackscrollsmooth - (mappackscrollsmooth-mappackscroll)*dt*5+0.1*dt
72			if mappackscrollsmooth > mappackscroll then
73				mappackscrollsmooth = mappackscroll
74			end
75		end
76	end
77
78	if onlinemappackscroll then
79		--smooth the scroll
80		if onlinemappackscrollsmooth > onlinemappackscroll then
81			onlinemappackscrollsmooth = onlinemappackscrollsmooth - (onlinemappackscrollsmooth-onlinemappackscroll)*dt*5-0.1*dt
82			if onlinemappackscrollsmooth < onlinemappackscroll then
83				onlinemappackscrollsmooth = onlinemappackscroll
84			end
85		elseif onlinemappackscrollsmooth < onlinemappackscroll then
86			onlinemappackscrollsmooth = onlinemappackscrollsmooth - (onlinemappackscrollsmooth-onlinemappackscroll)*dt*5+0.1*dt
87			if onlinemappackscrollsmooth > onlinemappackscroll then
88				onlinemappackscrollsmooth = onlinemappackscroll
89			end
90		end
91	end
92
93	if mappackhorscroll then
94		if mappackhorscrollsmooth > mappackhorscroll then
95			mappackhorscrollsmooth = mappackhorscrollsmooth - (mappackhorscrollsmooth-mappackhorscroll)*dt*5-0.03*dt
96			if mappackhorscrollsmooth < mappackhorscroll then
97				mappackhorscrollsmooth = mappackhorscroll
98			end
99		elseif mappackhorscrollsmooth < mappackhorscroll then
100			mappackhorscrollsmooth = mappackhorscrollsmooth - (mappackhorscrollsmooth-mappackhorscroll)*dt*5+0.03*dt
101			if mappackhorscrollsmooth > mappackhorscroll then
102				mappackhorscrollsmooth = mappackhorscroll
103			end
104		end
105	end
106
107	if gamestate == "options" and optionstab == 2 then
108		portalanimationtimer = portalanimationtimer + dt
109		while portalanimationtimer > portalanimationdelay do
110			portalanimation = portalanimation + 1
111			if portalanimation > 6 then
112				portalanimation = 1
113			end
114			portalanimationtimer = portalanimationtimer - portalanimationdelay
115		end
116
117		infmarioY = infmarioY + infmarioYspeed*dt
118		while infmarioY > 64 do
119			infmarioY = infmarioY - 64
120		end
121
122		infmarioR = infmarioR + infmarioRspeed*dt
123		while infmarioR > math.pi*2 do
124			infmarioR = infmarioR - math.pi*2
125		end
126
127		if optionsselection > 3 and optionsselection < 13 then
128			local colornumber = math.floor((optionsselection-1)/3)
129			local colorRGB = math.mod(optionsselection-4, 3)+1
130
131			if love.keyboard.isDown("right") and mariocolors[skinningplayer][colornumber][colorRGB] < 255 then
132				mariocolors[skinningplayer][colornumber][colorRGB] = mariocolors[skinningplayer][colornumber][colorRGB] + RGBchangespeed*dt
133				if mariocolors[skinningplayer][colornumber][colorRGB] > 255 then
134					mariocolors[skinningplayer][colornumber][colorRGB] = 255
135				end
136			elseif love.keyboard.isDown("left") and mariocolors[skinningplayer][colornumber][colorRGB] > 0 then
137				mariocolors[skinningplayer][colornumber][colorRGB] = mariocolors[skinningplayer][colornumber][colorRGB] - RGBchangespeed*dt
138				if mariocolors[skinningplayer][colornumber][colorRGB] < 0 then
139					mariocolors[skinningplayer][colornumber][colorRGB] = 0
140				end
141			end
142
143		elseif optionsselection == 13 then
144			if love.keyboard.isDown("right") and portalhues[skinningplayer][1] < 1 then
145				portalhues[skinningplayer][1] = portalhues[skinningplayer][1] + huechangespeed*dt
146				if portalhues[skinningplayer][1] > 1 then
147					portalhues[skinningplayer][1] = 1
148				end
149				portalcolor[skinningplayer][1] = getrainbowcolor(portalhues[skinningplayer][1])
150
151			elseif love.keyboard.isDown("left") and portalhues[skinningplayer][1] > 0 then
152				portalhues[skinningplayer][1] = portalhues[skinningplayer][1] - huechangespeed*dt
153				if portalhues[skinningplayer][1] < 0 then
154					portalhues[skinningplayer][1] = 0
155				end
156				portalcolor[skinningplayer][1] = getrainbowcolor(portalhues[skinningplayer][1])
157			end
158
159		elseif optionsselection == 14 then
160			if love.keyboard.isDown("right") and portalhues[skinningplayer][2] < 1 then
161				portalhues[skinningplayer][2] = portalhues[skinningplayer][2] + huechangespeed*dt
162				if portalhues[skinningplayer][2] > 1 then
163					portalhues[skinningplayer][2] = 1
164				end
165				portalcolor[skinningplayer][2] = getrainbowcolor(portalhues[skinningplayer][2])
166
167			elseif love.keyboard.isDown("left") and portalhues[skinningplayer][2] > 0 then
168				portalhues[skinningplayer][2] = portalhues[skinningplayer][2] - huechangespeed*dt
169				if portalhues[skinningplayer][2] < 0 then
170					portalhues[skinningplayer][2] = 0
171				end
172				portalcolor[skinningplayer][2] = getrainbowcolor(portalhues[skinningplayer][2])
173			end
174		end
175	end
176end
177
178function menu_draw()
179	--GUI LIBRARY?! Never heard of that.
180	--I'm not proud of this at all; But I'm even lazier than not proud.
181
182	--TILES
183	love.graphics.translate(0, yoffset*scale)
184	local xtodraw
185	if mapwidth < width+1 then
186		xtodraw = mapwidth
187	else
188		if mapwidth > width then
189			xtodraw = width+1
190		else
191			xtodraw = width
192		end
193	end
194
195	--custom background
196	if custombackground then
197		for i = #custombackgroundimg, 1, -1 do
198			for y = 1, math.ceil(15/custombackgroundheight[i]) do
199				for x = 1, math.ceil(width/custombackgroundwidth[i])+1 do
200					love.graphics.draw(custombackgroundimg[i], math.floor(((x-1)*custombackgroundwidth[i])*16*scale), (y-1)*custombackgroundheight[i]*16*scale, 0, scale, scale)
201				end
202			end
203		end
204	end
205
206	local coinframe
207	if math.floor(coinanimation) == 4 then
208		coinframe = 2
209	elseif math.floor(coinanimation) == 5 then
210		coinframe = 1
211	else
212		coinframe = math.floor(coinanimation)
213	end
214
215	for y = 1, 15 do
216		for x = 1, xtodraw do
217			local t = map[x][y]
218			local tilenumber = tonumber(t[1])
219			if tilequads[tilenumber].coinblock and tilequads[tilenumber].invisible == false then --coinblock
220				love.graphics.drawq(coinblockimage, coinblockquads[spriteset][coinframe], math.floor((x-1)*16*scale), ((y-1)*16-8)*scale, 0, scale, scale)
221			elseif tilenumber ~= 0 and tilequads[tilenumber].invisible == false then
222				love.graphics.drawq(tilequads[tilenumber].image, tilequads[tilenumber].quad, math.floor((x-1)*16*scale), ((y-1)*16-8)*scale, 0, scale, scale)
223			end
224		end
225	end
226
227	---UI
228
229	properprint("mario", uispace*.5 - 24*scale, 8*scale)
230	properprint("000000", uispace*0.5-24*scale, 16*scale)
231
232	properprint("*", uispace*1.5-8*scale, 16*scale)
233
234	love.graphics.drawq(coinanimationimage, coinanimationquads[1][coinframe], uispace*1.5-16*scale, 16*scale, 0, scale, scale)
235	properprint("00", uispace*1.5-0*scale, 16*scale)
236
237	properprint("world", uispace*2.5 - 20*scale, 8*scale)
238	properprint("1-1", uispace*2.5 - 12*scale, 16*scale)
239
240	properprint("time", uispace*3.5 - 16*scale, 8*scale)
241
242	for j = 1, players do
243
244		--draw player
245		love.graphics.setColor(255, 255, 255, 255)
246		for k = 1, 3 do
247			love.graphics.setColor(unpack(mariocolors[j][k]))
248			love.graphics.draw(skinpuppet[k], (startx*16-6)*scale+8*(j-1)*scale, (starty*16-23)*scale, 0, scale, scale)
249		end
250
251		--hat
252
253		offsets = hatoffsets["idle"]
254		if #mariohats[j] > 1 or mariohats[j][1] ~= 1 then
255			local yadd = 0
256			for i = 1, #mariohats[j] do
257				love.graphics.setColor(255, 255, 255)
258				love.graphics.draw(hat[mariohats[j][i]].graphic, (startx*16-11)*scale+8*(j-1)*scale, (starty*16-25)*scale, 0, scale, scale, - hat[mariohats[j][i]].x + offsets[1], - hat[mariohats[j][i]].y + offsets[2] + yadd)
259				yadd = yadd + hat[mariohats[j][i]].height
260			end
261		elseif #mariohats[j] == 1 then
262			love.graphics.setColor(mariocolors[j][1])
263			love.graphics.draw(hat[mariohats[j][1]].graphic, (startx*16-11)*scale+8*(j-1)*scale, (starty*16-25)*scale, 0, scale, scale, - hat[mariohats[j][1]].x + offsets[1], - hat[mariohats[j][1]].y + offsets[2])
264		end
265
266		love.graphics.setColor(255, 255, 255, 255)
267
268		love.graphics.draw(skinpuppet[0], (startx*16-6)*scale+8*(j-1)*scale, (starty*16-23)*scale, 0, scale, scale)
269	end
270
271	love.graphics.setColor(255, 255, 255, 255)
272
273	if gamestate == "menu" then
274		love.graphics.draw(titleimage, 40*scale, 24*scale, 0, scale, scale)
275
276		if updatenotification then
277			love.graphics.setColor(255, 0, 0)
278			properprint("version outdated!|go to stabyourself.net|to download latest", 220*scale, 90*scale)
279			love.graphics.setColor(255, 255, 255, 255)
280		end
281
282		if selection == 0 then
283			love.graphics.draw(menuselection, 73*scale, (137+(selection-1)*16)*scale, 0, scale, scale)
284		elseif selection == 1 then
285			love.graphics.draw(menuselection, 73*scale, (137+(selection-1)*16)*scale, 0, scale, scale)
286		elseif selection == 2 then
287			love.graphics.draw(menuselection, 81*scale, (137+(selection-1)*16)*scale, 0, scale, scale)
288		elseif selection == 3 then
289			love.graphics.draw(menuselection, 73*scale, (137+(selection-1)*16)*scale, 0, scale, scale)
290		elseif selection == 4 then
291			love.graphics.draw(menuselection, 98*scale, (137+(selection-1)*16)*scale, 0, scale, scale)
292		end
293
294		local start = 9
295		if custombackground then
296			start = 1
297		end
298
299		for i = start, 9 do
300			local tx, ty = -scale, scale
301			love.graphics.setColor(0, 0, 0)
302			if i == 2 then
303				tx, ty = scale, scale
304			elseif i == 3 then
305				tx, ty = -scale, -scale
306			elseif i == 4 then
307				tx, ty = scale, -scale
308			elseif i == 5 then
309				tx, ty = 0, -scale
310			elseif i == 6 then
311				tx, ty = 0, scale
312			elseif i == 7 then
313				tx, ty = scale, 0
314			elseif i == 8 then
315				tx, ty = -scale, 0
316			elseif i == 9 then
317				tx, ty = 0, 0
318				love.graphics.setColor(255, 255, 255)
319			end
320
321			love.graphics.translate(tx, ty)
322
323			if continueavailable then
324				properprint("continue game", 87*scale, 122*scale)
325			end
326
327			properprint("player game", 103*scale, 138*scale)
328
329			properprint("level editor", 95*scale, 154*scale)
330
331			properprint("select mappack", 87*scale, 170*scale)
332
333			properprint("options", 111*scale, 186*scale)
334
335			properprint(players, 87*scale, 138*scale)
336
337			love.graphics.translate(-tx, -ty)
338		end
339
340		if players > 1 then
341			love.graphics.draw(playerselectimg, 82*scale, 138*scale, 0, scale, scale)
342		end
343
344		if players < 4 then
345			love.graphics.draw(playerselectimg, 102*scale, 138*scale, 0, -scale, scale)
346		end
347
348		if selectworldopen then
349			love.graphics.setColor(0, 0, 0)
350			love.graphics.rectangle("fill", 30*scale, 92*scale, 200*scale, 60*scale)
351			love.graphics.setColor(255, 255, 255)
352			drawrectangle(31, 93, 198, 58)
353			properprint("select world", 83*scale, 105*scale)
354			for i = 1, 8 do
355				if selectworldcursor == i then
356					love.graphics.setColor(255, 255, 255)
357				elseif reachedworlds[mappack][i] then
358					love.graphics.setColor(200, 200, 200)
359				elseif selectworldexists[i] then
360					love.graphics.setColor(50, 50, 50)
361				else
362					love.graphics.setColor(0, 0, 0)
363				end
364
365				properprint(i, (55+(i-1)*20)*scale, 130*scale)
366				if i == selectworldcursor then
367					properprint("v", (55+(i-1)*20)*scale, 120*scale)
368				end
369			end
370		end
371
372	elseif gamestate == "mappackmenu" then
373		--background
374		love.graphics.setColor(0, 0, 0, 100)
375		love.graphics.rectangle("fill", 21*scale, 16*scale, 218*scale, 200*scale)
376		love.graphics.setColor(255, 255, 255, 255)
377
378		--set scissor
379		love.graphics.setScissor(21*scale, 16*scale, 218*scale, 200*scale)
380
381		if loadingonlinemappacks then
382			love.graphics.setColor(0, 0, 0, 200)
383			love.graphics.rectangle("fill", 21*scale, 16*scale, 218*scale, 200*scale)
384			love.graphics.setColor(255, 255, 255, 255)
385			properprint("a little patience..|downloading " .. currentdownload .. " of " .. downloadcount, 50*scale, 30*scale)
386			drawrectangle(50, 55, 152, 10)
387			love.graphics.rectangle("fill", 50*scale, 55*scale, 152*((currentfiledownload-1)/(filecount-1))*scale, 10*scale)
388		else
389			love.graphics.translate(-round(mappackhorscrollsmooth*scale*mappackhorscrollrange), 0)
390
391			if mappackhorscrollsmooth < 1 then
392				--draw each butten (even if all you do, is press ONE. BUTTEN.)
393				--scrollbar offset
394				love.graphics.translate(0, -round(mappackscrollsmooth*60*scale))
395
396				love.graphics.setScissor(240*scale, 16*scale, 200*scale, 200*scale)
397				love.graphics.setColor(0, 0, 0, 200)
398				love.graphics.rectangle("fill", 240*scale, 81*scale, 115*scale, 61*scale)
399				love.graphics.setColor(255, 255, 255)
400				if not savefolderfailed then
401					properprint("press right to|access the dlc||press m to|open your|mappack folder", 241*scale, 83*scale)
402				else
403					properprint("press right to|access the dlc||could not|open your|mappack folder", 241*scale, 83*scale)
404				end
405				love.graphics.setScissor(21*scale, 16*scale, 218*scale, 200*scale)
406
407				for i = 1, #mappacklist do
408					--back
409					love.graphics.draw(mappackback, 25*scale, (20+(i-1)*60)*scale, 0, scale, scale)
410
411					--icon
412					if mappackicon[i] ~= nil then
413						local scale2w = scale*50 / math.max(1, mappackicon[i]:getWidth())
414						local scale2h = scale*50 / math.max(1, mappackicon[i]:getHeight())
415						love.graphics.draw(mappackicon[i], 29*scale, (24+(i-1)*60)*scale, 0, scale2w, scale2h)
416					else
417						love.graphics.draw(mappacknoicon, 29*scale, (24+(i-1)*60)*scale, 0, scale, scale)
418					end
419					love.graphics.draw(mappackoverlay, 29*scale, (24+(i-1)*60)*scale, 0, scale, scale)
420
421					--name
422					love.graphics.setColor(200, 200, 200)
423					if mappackselection == i then
424						love.graphics.setColor(255, 255, 255)
425					end
426
427					properprint(string.sub(mappackname[i]:lower(), 1, 17), 83*scale, (26+(i-1)*60)*scale)
428
429					--author
430					love.graphics.setColor(100, 100, 100)
431					if mappackselection == i then
432						love.graphics.setColor(100, 100, 100)
433					end
434
435					if mappackauthor[i] then
436						properprint(string.sub("by " .. mappackauthor[i]:lower(), 1, 16), 91*scale, (35+(i-1)*60)*scale)
437					end
438
439					--description
440					love.graphics.setColor(130, 130, 130)
441					if mappackselection == i then
442						love.graphics.setColor(180, 180, 180)
443					end
444
445					if mappackdescription[i] then
446						properprint( string.sub(mappackdescription[i]:lower(), 1, 17), 83*scale, (47+(i-1)*60)*scale)
447
448						if mappackdescription[i]:len() > 17 then
449							properprint( string.sub(mappackdescription[i]:lower(), 18, 34), 83*scale, (56+(i-1)*60)*scale)
450						end
451
452						if mappackdescription[i]:len() > 34 then
453							properprint( string.sub(mappackdescription[i]:lower(), 35, 51), 83*scale, (65+(i-1)*60)*scale)
454						end
455					end
456
457					love.graphics.setColor(255, 255, 255)
458
459					--highlight
460					if i == mappackselection then
461						love.graphics.draw(mappackhighlight, 25*scale, (20+(i-1)*60)*scale, 0, scale, scale)
462					end
463				end
464
465				love.graphics.translate(0, round(mappackscrollsmooth*60*scale))
466
467				local i = mappackscrollsmooth / (#mappacklist-3.233)
468
469				love.graphics.draw(mappackscrollbar, 227*scale, (20+i*160)*scale, 0, scale, scale)
470
471			end
472
473			love.graphics.translate(round(mappackhorscrollsmooth*scale*mappackhorscrollrange), 0)
474			----------
475			--ONLINE--
476			----------
477
478			love.graphics.translate(round(mappackhorscrollrange*scale - mappackhorscrollsmooth*scale*mappackhorscrollrange), 0)
479
480			if mappackhorscrollsmooth > 0 then
481				if #onlinemappacklist == 0 then
482					properprint("something went wrong||      sorry d:||maybe your internet|does not work right?", 40*scale, 80*scale)
483				end
484
485				love.graphics.setScissor()
486				love.graphics.setColor(0, 0, 0, 200)
487				love.graphics.rectangle("fill", 241*scale, 16*scale, 150*scale, 200*scale)
488				love.graphics.setColor(255, 255, 255, 255)
489				properprint("wanna contribute?|make a mappack and|send an email to|mappack at|stabyourself.net!||include your map-|pack! you can find|it in your appdata|love/mari0 dir.", 244*scale, 19*scale)
490				if outdated then
491					love.graphics.setColor(255, 0, 0, 255)
492					properprint("version outdated!|you have an old|version of mari0!|mappacks could not|be downloaded.|go to|stabyourself.net|to download latest", 244*scale, 130*scale)
493					love.graphics.setColor(255, 255, 255, 255)
494				elseif downloaderror then
495					love.graphics.setColor(255, 0, 0, 255)
496					properprint("download error!|something went|wrong while|downloading|mappacks.|press left and|right to try|again.  sorry.", 244*scale, 130*scale)
497					love.graphics.setColor(255, 255, 255, 255)
498				end
499
500				love.graphics.setScissor(21*scale, 16*scale, 218*scale, 200*scale)
501
502				--scrollbar offset
503				love.graphics.translate(0, -round(onlinemappackscrollsmooth*60*scale))
504				for i = 1, #onlinemappacklist do
505					--back
506					love.graphics.draw(mappackback, 25*scale, (20+(i-1)*60)*scale, 0, scale, scale)
507
508					--icon
509					if onlinemappackicon[i] ~= nil then
510						love.graphics.draw(onlinemappackicon[i], 29*scale, (24+(i-1)*60)*scale, 0, scale, scale)
511					else
512						love.graphics.draw(mappacknoicon, 29*scale, (24+(i-1)*60)*scale, 0, scale, scale)
513					end
514					love.graphics.draw(mappackoverlay, 29*scale, (24+(i-1)*60)*scale, 0, scale, scale)
515
516					--name
517					love.graphics.setColor(200, 200, 200)
518					if onlinemappackselection == i then
519						love.graphics.setColor(255, 255, 255)
520					end
521
522					properprint(string.sub(onlinemappackname[i]:lower(), 1, 17), 83*scale, (26+(i-1)*60)*scale)
523
524					--author
525					love.graphics.setColor(100, 100, 100)
526					if onlinemappackselection == i then
527						love.graphics.setColor(100, 100, 100)
528					end
529
530					if onlinemappackauthor[i] then
531						properprint(string.sub("by " .. onlinemappackauthor[i]:lower(), 1, 16), 91*scale, (35+(i-1)*60)*scale)
532					end
533
534					--description
535					love.graphics.setColor(130, 130, 130)
536					if onlinemappackselection == i then
537						love.graphics.setColor(180, 180, 180)
538					end
539
540					if onlinemappackdescription[i] then
541						properprint( string.sub(onlinemappackdescription[i]:lower(), 1, 17), 83*scale, (47+(i-1)*60)*scale)
542
543						if onlinemappackdescription[i]:len() > 17 then
544							properprint( string.sub(onlinemappackdescription[i]:lower(), 18, 34), 83*scale, (56+(i-1)*60)*scale)
545						end
546
547						if onlinemappackdescription[i]:len() > 34 then
548							properprint( string.sub(onlinemappackdescription[i]:lower(), 35, 51), 83*scale, (65+(i-1)*60)*scale)
549						end
550					end
551
552					love.graphics.setColor(255, 255, 255)
553
554					--highlight
555					if i == onlinemappackselection then
556						love.graphics.draw(mappackhighlight, 25*scale, (20+(i-1)*60)*scale, 0, scale, scale)
557					end
558				end
559
560				love.graphics.translate(0, round(onlinemappackscrollsmooth*60*scale))
561
562				local i = onlinemappackscrollsmooth / (#onlinemappacklist-3.233)
563
564				love.graphics.draw(mappackscrollbar, 227*scale, (20+i*160)*scale, 0, scale, scale)
565			end
566
567			love.graphics.translate(- round(mappackhorscrollrange*scale - mappackhorscrollsmooth*scale*mappackhorscrollrange), 0)
568		end
569
570		love.graphics.setScissor()
571
572		if mappackhorscroll == 0 then
573			love.graphics.setColor(255, 255, 255)
574			love.graphics.rectangle("fill", 22*scale, 3*scale, 44*scale, 13*scale)
575			love.graphics.setColor(0, 0, 0)
576			properprint("local", 23*scale, 6*scale)
577			drawrectangle(22, 3, 44, 13)
578			love.graphics.setColor(0, 0, 0)
579			love.graphics.rectangle("fill", 70*scale, 3*scale, 29*scale, 13*scale)
580			love.graphics.setColor(255, 255, 255)
581			properprint("dlc", 72*scale, 6*scale)
582		else
583			love.graphics.setColor(0, 0, 0)
584			love.graphics.rectangle("fill", 22*scale, 3*scale, 44*scale, 13*scale)
585			love.graphics.setColor(255, 255, 255)
586			properprint("local", 23*scale, 6*scale)
587			love.graphics.setColor(255, 255, 255)
588			love.graphics.rectangle("fill", 70*scale, 3*scale, 29*scale, 13*scale)
589			love.graphics.setColor(0, 0, 0)
590			properprint("dlc", 72*scale, 6*scale)
591			drawrectangle(70, 3, 29, 13)
592		end
593
594	elseif gamestate == "onlinemenu" then
595		if CLIENT == false and SERVER == false then
596			properprint("press c for client", 70*scale, 100*scale)
597			properprint("press s for server", 70*scale, 160*scale)
598			properprint("run away to quit", 78*scale, 170*scale)
599		elseif CLIENT then
600			properprint("waiting for server..", 62*scale, 100*scale)
601		elseif SERVER then
602			properprint("press enter to start!", 62*scale, 100*scale)
603		end
604	elseif gamestate == "options" then
605		love.graphics.setColor(0, 0, 0, 200)
606		love.graphics.rectangle("fill", 21*scale, 16*scale, 218*scale, 200*scale)
607
608		--Controls tab head
609		if optionstab == 1 then
610			love.graphics.setColor(100, 100, 100, 100)
611			love.graphics.rectangle("fill", 25*scale, 20*scale, 67*scale, 11*scale)
612		end
613
614		if optionstab == 1 and optionsselection == 1 then
615			love.graphics.setColor(255, 255, 255, 255)
616		else
617			love.graphics.setColor(100, 100, 100, 255)
618		end
619		properprint("controls", 26*scale, 22*scale)
620
621		--Skins tab head
622		if optionstab == 2 then
623			love.graphics.setColor(100, 100, 100, 100)
624			love.graphics.rectangle("fill", 96*scale, 20*scale, 43*scale, 11*scale)
625		end
626
627
628		if optionstab == 2 and optionsselection == 1 then
629			love.graphics.setColor(255, 255, 255, 255)
630		else
631			love.graphics.setColor(100, 100, 100, 255)
632		end
633		properprint("skins", 97*scale, 22*scale)
634
635		--Miscellaneous tab head
636		if optionstab == 3 then
637			love.graphics.setColor(100, 100, 100, 100)
638			love.graphics.rectangle("fill", 145*scale, 20*scale, 39*scale, 11*scale)
639		end
640
641		if optionstab == 3 and optionsselection == 1 then
642			love.graphics.setColor(255, 255, 255, 255)
643		else
644			love.graphics.setColor(100, 100, 100, 255)
645		end
646		properprint("misc.", 146*scale, 22*scale)
647
648		--Cheat tab head
649		if optionstab == 4 then
650			love.graphics.setColor(100, 100, 100, 100)
651			love.graphics.rectangle("fill", 190*scale, 20*scale, 43*scale, 11*scale)
652		end
653
654		if optionstab == 4 and optionsselection == 1 then
655			love.graphics.setColor(255, 255, 255, 255)
656		else
657			love.graphics.setColor(100, 100, 100, 255)
658		end
659		properprint("cheat", 191*scale, 22*scale)
660
661		love.graphics.setColor(255, 255, 255, 255)
662
663		if optionstab == 1 then
664			--CONTROLS
665			if optionsselection == 2 then
666				love.graphics.setColor(255, 255, 255, 255)
667			else
668				love.graphics.setColor(100, 100, 100, 255)
669			end
670
671			properprint("edit player:" .. skinningplayer, 74*scale, 40*scale)
672
673			if optionsselection == 3 then
674				love.graphics.setColor(255, 255, 255, 255)
675			else
676				love.graphics.setColor(100, 100, 100, 255)
677			end
678
679			if mouseowner == skinningplayer then
680				properprint("uses the mouse: yes", 46*scale, 52*scale)
681			else
682				properprint("uses the mouse: no", 46*scale, 52*scale)
683			end
684
685			for i = 1, #controlstable do
686				if mouseowner ~= skinningplayer or i <= 8 then
687					if optionsselection == 3+i then
688						love.graphics.setColor(255, 255, 255, 255)
689					else
690						love.graphics.setColor(100, 100, 100, 255)
691					end
692
693					properprint(controlstable[i], 30*scale, (70+(i-1)*12)*scale)
694
695					local s = ""
696
697					if controls[skinningplayer][controlstable[i]] then
698						for j = 1, #controls[skinningplayer][controlstable[i]] do
699							s = s .. controls[skinningplayer][controlstable[i]][j]
700						end
701					end
702					if s == " " then
703						s = "space"
704					end
705					properprint(s, 120*scale, (70+(i-1)*12)*scale)
706				end
707			end
708
709			if keyprompt then
710				love.graphics.setColor(0, 0, 0, 255)
711				love.graphics.rectangle("fill", 30*scale, 100*scale, 200*scale, 60*scale)
712				love.graphics.setColor(255, 255, 255, 255)
713				drawrectangle(30, 100, 200, 60)
714				if controlstable[optionsselection-3] == "aimx" then
715					properprint("move stick right", 40*scale, 110*scale)
716				elseif controlstable[optionsselection-3] == "aimy" then
717					properprint("move stick down", 40*scale, 110*scale)
718				else
719					properprint("press key for '" .. controlstable[optionsselection-3] .. "'", 40*scale, 110*scale)
720				end
721				properprint("press 'esc' to cancel", 40*scale, 140*scale)
722
723				if buttonerror then
724					love.graphics.setColor(200, 0, 0)
725					properprint("you can only set", 40*scale, 120*scale)
726					properprint("buttons for this", 40*scale, 130*scale)
727				elseif axiserror then
728					love.graphics.setColor(200, 0, 0)
729					properprint("you can only set", 40*scale, 120*scale)
730					properprint("axes for this", 40*scale, 130*scale)
731				end
732			end
733		elseif optionstab == 2 then
734			--SKINS
735			if optionsselection == 2 then
736				love.graphics.setColor(255, 255, 255, 255)
737			else
738				love.graphics.setColor(100, 100, 100, 255)
739			end
740
741			properprint("edit player:" .. skinningplayer, 74*scale, 32*scale)
742
743			--PREVIEW MARIO IN BIG. WITH BIG LETTERS
744			love.graphics.setColor(255, 255, 255, 255)
745			for i = 1, 3 do
746				love.graphics.setColor(unpack(mariocolors[skinningplayer][i]))
747				love.graphics.draw(skinpuppet[i], 80*scale, 42*scale, 0, scale*2, scale*2)
748			end
749
750			--hat
751			offsets = hatoffsets["idle"]
752			if #mariohats[skinningplayer] > 1 or mariohats[skinningplayer][1] ~= 1 then
753				local yadd = 0
754				for i = 1, #mariohats[skinningplayer] do
755					love.graphics.setColor(255, 255, 255)
756					love.graphics.draw(hat[mariohats[skinningplayer][i]].graphic, 70*scale, 38*scale, 0, scale*2, scale*2, - hat[mariohats[skinningplayer][i]].x + offsets[1], - hat[mariohats[skinningplayer][i]].y + offsets[2] + yadd)
757					yadd = yadd + hat[mariohats[skinningplayer][i]].height
758				end
759			elseif #mariohats[skinningplayer] == 1 then
760				love.graphics.setColor(mariocolors[skinningplayer][1])
761				love.graphics.draw(hat[mariohats[skinningplayer][1]].graphic, 70*scale, 38*scale, 0, scale*2, scale*2, - hat[mariohats[skinningplayer][1]].x + offsets[1], - hat[mariohats[skinningplayer][1]].y + offsets[2])
762			end
763
764			love.graphics.setColor(255, 255, 255, 255)
765
766			love.graphics.draw(skinpuppet[0], 80*scale, 42*scale, 0, scale*2, scale*2)
767
768			--PREVIEW PORTALS WITH FALLING MARIO BECAUSE I CAN AND IT LOOKS RAD
769			love.graphics.setScissor(142*scale, 42*scale, 32*scale, 32*scale)
770
771			for j = 1, 3 do
772				love.graphics.setColor(255, 255, 255, 255)
773				love.graphics.draw(secondskinpuppet[0], 158*scale, (2+((j-1)*32)+infmarioY)*scale, infmarioR, scale, scale, 8, 8)
774				for i = 1, 3 do
775					love.graphics.setColor(unpack(mariocolors[skinningplayer][i]))
776					love.graphics.draw(secondskinpuppet[i], 158*scale, (2+((j-1)*32)+infmarioY)*scale, infmarioR, scale, scale, 8, 8)
777				end
778			end
779
780			local portalframe = portalanimation
781
782			love.graphics.setColor(255, 255, 255, 80 - math.abs(portalframe-3)*10)
783			love.graphics.draw(portalglow, 174*scale, 59*scale, math.pi, scale, scale)
784			love.graphics.draw(portalglow, 142*scale, 57*scale, 0, scale, scale)
785
786			love.graphics.setColor(unpack(portalcolor[skinningplayer][1]))
787			love.graphics.drawq(portalimage, portal1quad[portalframe], 174*scale, 46*scale, math.pi, scale, scale)
788			love.graphics.setColor(unpack(portalcolor[skinningplayer][2]))
789			love.graphics.drawq(portalimage, portal1quad[portalframe], 142*scale, 70*scale, 0, scale, scale)
790
791			love.graphics.setScissor()
792
793			--HAT
794			if optionsselection == 3 then
795				love.graphics.setColor(255, 255, 255, 255)
796			else
797				love.graphics.setColor(100, 100, 100, 255)
798			end
799			if mariohats[skinningplayer][1] == nil then
800				properprint("hat: none", (79)*scale, 80*scale)
801			else
802				properprint("hat: " .. mariohats[skinningplayer][1], (95-string.len(mariohats[skinningplayer][1])*4)*scale, 80*scale)
803			end
804
805			love.graphics.setColor(255, 255, 255, 255)
806			--WHITE BACKGROUND FOR RGB BARS
807
808			if optionsselection > 3 and optionsselection < 13 then
809				love.graphics.rectangle("fill", 69*scale, 89*scale + math.mod(optionsselection-4, 3)*10*scale + math.floor((optionsselection-4)/3)*14*scale, 142*scale, 10*scale)
810			end
811
812			if math.floor((optionsselection-1)/3) == 1 then
813				love.graphics.setColor(255, 255, 255)
814			else
815				love.graphics.setColor(100, 100, 100)
816			end
817
818			properprint("hat", 35*scale, 90*scale)
819
820			if math.floor((optionsselection-1)/3) == 2 then
821				love.graphics.setColor(255, 255, 255)
822			else
823				love.graphics.setColor(100, 100, 100)
824			end
825
826			properprint("hair", 31*scale, 114*scale)
827
828			if math.floor((optionsselection-1)/3) == 3 then
829				love.graphics.setColor(255, 255, 255)
830			else
831				love.graphics.setColor(100, 100, 100)
832			end
833
834			properprint("skin", 31*scale, 138*scale)
835			for i = 1, 3 do
836				if math.floor((optionsselection-1)/3) == i then
837					love.graphics.setColor(100, 0, 0)
838					properprint("r", 70*scale, (91+(i-1)*14)*scale)
839					love.graphics.setColor(255, 0, 0)
840					properprint("r", 69*scale, (90+(i-1)*14)*scale)
841
842					love.graphics.setColor(0, 100, 0)
843					properprint("g", 70*scale, (101+(i-1)*14)*scale)
844					love.graphics.setColor(0, 255, 0)
845					properprint("g", 69*scale, (100+(i-1)*14)*scale)
846
847					love.graphics.setColor(0, 0, 100)
848					properprint("b", 70*scale, (111+(i-1)*14)*scale)
849					love.graphics.setColor(0, 0, 255)
850					properprint("b", 69*scale, (110+(i-1)*14)*scale)
851				end
852			end
853
854			for j = 1, 3 do
855				if math.floor((optionsselection-1)/3) == j then
856					love.graphics.setColor(100, 0, 0)
857					love.graphics.rectangle("fill", 81*scale, (91+(j-1)*14)*scale, math.floor(129*scale * (mariocolors[skinningplayer][j][1]/255)), 7*scale)
858					love.graphics.setColor(255, 0, 0)
859					love.graphics.rectangle("fill", 80*scale, (90+(j-1)*14)*scale, math.floor(129*scale * (mariocolors[skinningplayer][j][1]/255)), 7*scale)
860
861					love.graphics.setColor(0, 100, 0)
862					love.graphics.rectangle("fill", 81*scale, (101+(j-1)*14)*scale, math.floor(129*scale * (mariocolors[skinningplayer][j][2]/255)), 7*scale)
863					love.graphics.setColor(0, 255, 0)
864					love.graphics.rectangle("fill", 80*scale, (100+(j-1)*14)*scale, math.floor(129*scale * (mariocolors[skinningplayer][j][2]/255)), 7*scale)
865
866					love.graphics.setColor(0, 0, 100)
867					love.graphics.rectangle("fill", 81*scale, (111+(j-1)*14)*scale, math.floor(129*scale * (mariocolors[skinningplayer][j][3]/255)), 7*scale)
868					love.graphics.setColor(0, 0, 255)
869					love.graphics.rectangle("fill", 80*scale, (110+(j-1)*14)*scale, math.floor(129*scale * (mariocolors[skinningplayer][j][3]/255)), 7*scale)
870				end
871			end
872
873			--Portalhues
874			--hue
875			local alpha = 100
876			if optionsselection == 13 then
877				alpha = 255
878			end
879
880			love.graphics.setColor(255, 255, 255, alpha)
881
882			properprint("coop portal 1 color:", 31*scale, 150*scale)
883
884			love.graphics.draw(huebarimg, 32*scale, 170*scale, 0, scale, scale)
885
886			--marker
887			love.graphics.setColor(unpack(portalcolor[skinningplayer][1]))
888			love.graphics.rectangle("fill", math.floor(29 + (portalhues[skinningplayer][1])*178)*scale, 161*scale, 7*scale, 6*scale)
889			love.graphics.setColor(alpha, alpha, alpha)
890			love.graphics.draw(huebarmarkerimg, math.floor(28 + (portalhues[skinningplayer][1])*178)*scale, 160*scale, 0, scale, scale)
891
892			alpha = 100
893			if optionsselection == 14 then
894				alpha = 255
895			end
896
897			love.graphics.setColor(255, 255, 255, alpha)
898
899			properprint("coop portal 2 color:", 31*scale, 180*scale)
900
901			love.graphics.draw(huebarimg, 32*scale, 200*scale, 0, scale, scale)
902
903			--marker
904			love.graphics.setColor(unpack(portalcolor[skinningplayer][2]))
905			love.graphics.rectangle("fill", math.floor(29 + (portalhues[skinningplayer][2])*178)*scale, 191*scale, 7*scale, 6*scale)
906			love.graphics.setColor(alpha, alpha, alpha)
907			love.graphics.draw(huebarmarkerimg, math.floor(28 + (portalhues[skinningplayer][2])*178)*scale, 190*scale, 0, scale, scale)
908		elseif optionstab == 3 then
909			if optionsselection == 2 then
910				love.graphics.setColor(255, 255, 255, 255)
911			else
912				love.graphics.setColor(100, 100, 100, 255)
913			end
914			properprint("scale:", 30*scale, 40*scale)
915			properprint(scale, (180-string.len(scale)*8)*scale, 40*scale)
916
917
918			if optionsselection == 3 then
919				love.graphics.setColor(255, 255, 255, 255)
920			else
921				love.graphics.setColor(100, 100, 100, 255)
922			end
923
924			properprint("shader1:", 30*scale, 55*scale)
925			if shaderssupported == false then
926				properprint("unsupported", (180-string.len("unsupported")*8)*scale, 55*scale)
927			else
928				properprint(string.lower(shaderlist[currentshaderi1]), (180-string.len(shaderlist[currentshaderi1])*8)*scale, 55*scale)
929			end
930
931			if optionsselection == 4 then
932				love.graphics.setColor(255, 255, 255, 255)
933			else
934				love.graphics.setColor(100, 100, 100, 255)
935			end
936			properprint("shader2:", 30*scale, 65*scale)
937			if shaderssupported == false then
938				properprint("unsupported", (180-string.len("unsupported")*8)*scale, 65*scale)
939			else
940				properprint(string.lower(shaderlist[currentshaderi2]), (180-string.len(shaderlist[currentshaderi2])*8)*scale, 65*scale)
941			end
942
943			love.graphics.setColor(100, 100, 100, 255)
944			properprint("shaders will really", 30*scale, 80*scale)
945			properprint("reduce performance!", 30*scale, 90*scale)
946
947			if optionsselection == 5 then
948				love.graphics.setColor(255, 255, 255, 255)
949			else
950				love.graphics.setColor(100, 100, 100, 255)
951			end
952			properprint("volume:", 30*scale, 105*scale)
953			drawrectangle(90, 108, 90, 1)
954			drawrectangle(90, 105, 1, 7)
955			drawrectangle(179, 105, 1, 7)
956			love.graphics.draw(volumesliderimg, math.floor((89+89*volume)*scale), 105*scale, 0, scale, scale)
957
958			if optionsselection == 6 then
959				love.graphics.setColor(255, 255, 255, 255)
960			else
961				love.graphics.setColor(100, 100, 100, 255)
962			end
963
964			properprint("reset game mappacks", 30*scale, 120*scale)
965
966			if optionsselection == 7 then
967				love.graphics.setColor(255, 255, 255, 255)
968			else
969				love.graphics.setColor(100, 100, 100, 255)
970			end
971
972			properprint("reset all settings", 30*scale, 135*scale)
973
974			if optionsselection == 8 then
975				love.graphics.setColor(255, 255, 255, 255)
976			else
977				love.graphics.setColor(100, 100, 100, 255)
978			end
979
980			properprint("vsync:", 30*scale, 150*scale)
981			if vsync then
982				properprint("on", (180-16)*scale, 150*scale)
983			else
984				properprint("off", (180-24)*scale, 150*scale)
985			end
986
987			love.graphics.setColor(100, 100, 100, 255)
988			properprint("you can lock the|mouse with f12", 30*scale, 165*scale)
989
990			love.graphics.setColor(255, 255, 255, 255)
991			properprint(versionstring, 150*scale, 207*scale)
992		elseif optionstab == 4 then
993			love.graphics.setColor(255, 255, 255, 255)
994			if not gamefinished then
995				properprint("unlock this by completing", 30*scale, 40*scale)
996				properprint("the original levels pack!", 30*scale, 50*scale)
997			else
998				properprint("have fun with these!", 30*scale, 45*scale)
999			end
1000
1001			if optionsselection == 2 then
1002				love.graphics.setColor(255, 255, 255, 255)
1003			else
1004				love.graphics.setColor(100, 100, 100, 255)
1005			end
1006
1007			properprint("mode:", 30*scale, 65*scale)
1008			properprint("{" .. playertype .. "}", (180-(string.len(playertype)+2)*8)*scale, 65*scale)
1009
1010			if optionsselection == 3 then
1011				love.graphics.setColor(255, 255, 255, 255)
1012			else
1013				love.graphics.setColor(100, 100, 100, 255)
1014			end
1015
1016			properprint("knockback:", 30*scale, 80*scale)
1017			if portalknockback then
1018				properprint("on", (180-16)*scale, 80*scale)
1019			else
1020				properprint("off", (180-24)*scale, 80*scale)
1021			end
1022
1023			if optionsselection == 4 then
1024				love.graphics.setColor(255, 255, 255, 255)
1025			else
1026				love.graphics.setColor(100, 100, 100, 255)
1027			end
1028
1029			properprint("bullettime:", 30*scale, 95*scale)
1030			properprint("use mousewheel", 30*scale, 105*scale)
1031			if bullettime then
1032				properprint("on", (180-16)*scale, 95*scale)
1033			else
1034				properprint("off", (180-24)*scale, 95*scale)
1035			end
1036
1037			if optionsselection == 5 then
1038				love.graphics.setColor(255, 255, 255, 255)
1039			else
1040				love.graphics.setColor(100, 100, 100, 255)
1041			end
1042
1043			properprint("huge mario:", 30*scale, 120*scale)
1044			if bigmario then
1045				properprint("on", (180-16)*scale, 120*scale)
1046			else
1047				properprint("off", (180-24)*scale, 120*scale)
1048			end
1049
1050			if optionsselection == 6 then
1051				love.graphics.setColor(255, 255, 255, 255)
1052			else
1053				love.graphics.setColor(100, 100, 100, 255)
1054			end
1055
1056			properprint("goomba attack:", 30*scale, 135*scale)
1057			if goombaattack then
1058				properprint("on", (180-16)*scale, 135*scale)
1059			else
1060				properprint("off", (180-24)*scale, 135*scale)
1061			end
1062
1063			if optionsselection == 7 then
1064				love.graphics.setColor(255, 255, 255, 255)
1065			else
1066				love.graphics.setColor(100, 100, 100, 255)
1067			end
1068
1069			properprint("sonic rainboom:", 30*scale, 150*scale)
1070			if sonicrainboom then
1071				properprint("on", (180-16)*scale, 150*scale)
1072			else
1073				properprint("off", (180-24)*scale, 150*scale)
1074			end
1075
1076			if optionsselection == 8 then
1077				love.graphics.setColor(255, 255, 255, 255)
1078			else
1079				love.graphics.setColor(100, 100, 100, 255)
1080			end
1081
1082			properprint("playercollision:", 30*scale, 165*scale)
1083			if playercollisions then
1084				properprint("on", (180-16)*scale, 165*scale)
1085			else
1086				properprint("off", (180-24)*scale, 165*scale)
1087			end
1088
1089			if optionsselection == 9 then
1090				love.graphics.setColor(255, 255, 255, 255)
1091			else
1092				love.graphics.setColor(100, 100, 100, 255)
1093			end
1094
1095			properprint("infinite time:", 30*scale, 180*scale)
1096			if infinitetime then
1097				properprint("on", (180-16)*scale, 180*scale)
1098			else
1099				properprint("off", (180-24)*scale, 180*scale)
1100			end
1101
1102			if optionsselection == 10 then
1103				love.graphics.setColor(255, 255, 255, 255)
1104			else
1105				love.graphics.setColor(100, 100, 100, 255)
1106			end
1107
1108			properprint("infinite lives:", 30*scale, 195*scale)
1109			if infinitelives then
1110				properprint("on", (180-16)*scale, 195*scale)
1111			else
1112				properprint("off", (180-24)*scale, 195*scale)
1113			end
1114		end
1115	end
1116	love.graphics.translate(0, yoffset*scale)
1117end
1118
1119function loadbackground(background)
1120	if love.filesystem.exists("mappacks/" .. mappack .. "/" .. background) == false then
1121
1122		map = {}
1123		mapwidth = width
1124		for x = 1, width do
1125			map[x] = {}
1126			for y = 1, 13 do
1127				map[x][y] = {1}
1128			end
1129
1130			for y = 14, 15 do
1131				map[x][y] = {2}
1132			end
1133		end
1134		startx = 3
1135		starty = 13
1136		custombackground = false
1137		backgroundi = 1
1138		love.graphics.setBackgroundColor(backgroundcolor[backgroundi])
1139	else
1140		local s = love.filesystem.read( "mappacks/" .. mappack .. "/" .. background )
1141		local s2 = s:split(";")
1142
1143		--remove custom sprites
1144		for i = smbtilecount+portaltilecount+1, #tilequads do
1145			tilequads[i] = nil
1146		end
1147
1148		for i = smbtilecount+portaltilecount+1, #rgblist do
1149			rgblist[i] = nil
1150		end
1151
1152		--add custom tiles
1153		if love.filesystem.exists("mappacks/" .. mappack .. "/tiles.png") then
1154			customtiles = true
1155			customtilesimg = love.graphics.newImage("mappacks/" .. mappack .. "/tiles.png")
1156			local imgwidth, imgheight = customtilesimg:getWidth(), customtilesimg:getHeight()
1157			local width = math.floor(imgwidth/17)
1158			local height = math.floor(imgheight/17)
1159			local imgdata = love.image.newImageData("mappacks/" .. mappack .. "/tiles.png")
1160
1161			for y = 1, height do
1162				for x = 1, width do
1163					table.insert(tilequads, quad:new(customtilesimg, imgdata, x, y, imgwidth, imgheight))
1164					local r, g, b = getaveragecolor(imgdata, x, y)
1165					table.insert(rgblist, {r, g, b})
1166				end
1167			end
1168			customtilecount = width*height
1169		else
1170			customtiles = false
1171			customtilecount = 0
1172		end
1173
1174		--MAP ITSELF
1175		local t = s2[1]:split(",")
1176
1177		if math.mod(#t, 15) ~= 0 then
1178			print("Incorrect number of entries: " .. #t)
1179			return false
1180		end
1181
1182		mapwidth = #t/15
1183		startx = 3
1184		starty = 13
1185
1186		map = {}
1187
1188		for y = 1, 15 do
1189			for x = 1, #t/15 do
1190				if y == 1 then
1191					map[x] = {}
1192				end
1193
1194				map[x][y] = t[(y-1)*(#t/15)+x]:split("-")
1195
1196				r = map[x][y]
1197
1198				if #r > 1 then
1199					if entityquads[tonumber(r[2])].t == "spawn" then
1200						startx = x
1201						starty = y
1202					end
1203				end
1204
1205				if tonumber(r[1]) > smbtilecount+portaltilecount+customtilecount then
1206					r[1] = 1
1207				end
1208			end
1209		end
1210
1211		--get background color
1212		custombackground = false
1213
1214		for i = 2, #s2 do
1215			s3 = s2[i]:split("=")
1216			if s3[1] == "background" then
1217				local backgroundi = tonumber(s3[2])
1218
1219				love.graphics.setBackgroundColor(backgroundcolor[backgroundi])
1220			elseif s3[1] == "spriteset" then
1221				spriteset = tonumber(s3[2])
1222			elseif s3[1] == "custombackground" or s3[1] == "portalbackground" then
1223				custombackground = true
1224			end
1225		end
1226
1227		if custombackground then
1228			loadcustombackground()
1229		end
1230	end
1231end
1232
1233function updatescroll()
1234	--check if current focus is completely onscreen
1235	if inrange(mappackselection, 1+mappackscroll, 3+mappackscroll, true) == false then
1236		if mappackselection < 1+mappackscroll then --above window
1237			mappackscroll = mappackselection-1
1238		else
1239			mappackscroll = mappackselection-3.233
1240		end
1241	end
1242end
1243
1244function onlineupdatescroll()
1245	--check if current focus is completely onscreen
1246	if inrange(onlinemappackselection, 1+onlinemappackscroll, 3+onlinemappackscroll, true) == false then
1247		if onlinemappackselection < 1+onlinemappackscroll then --above window
1248			onlinemappackscroll = onlinemappackselection-1
1249		else
1250			onlinemappackscroll = onlinemappackselection-3.233
1251		end
1252	end
1253end
1254
1255function mappacks()
1256	if mappackhorscroll == 0 then
1257		loadmappacks()
1258	else
1259		loadonlinemappacks()
1260	end
1261end
1262
1263function loadmappacks()
1264	mappacktype = "local"
1265	mappacklist = love.filesystem.enumerate( "mappacks" )
1266
1267	local delete = {}
1268	for i = 1, #mappacklist do
1269		if love.filesystem.exists( "mappacks/" .. mappacklist[i] .. "/version.txt") or not love.filesystem.exists( "mappacks/" .. mappacklist[i] .. "/settings.txt") then
1270			table.insert(delete, i)
1271		end
1272	end
1273
1274	table.sort(delete, function(a,b) return a>b end)
1275
1276	for i, v in pairs(delete) do
1277		table.remove(mappacklist, v) --remove
1278	end
1279
1280	mappackicon = {}
1281
1282	--get info
1283	mappackname = {}
1284	mappackauthor = {}
1285	mappackdescription = {}
1286	mappackbackground = {}
1287
1288	for i = 1, #mappacklist do
1289		if love.filesystem.exists( "mappacks/" .. mappacklist[i] .. "/icon.png" ) then
1290			mappackicon[i] = love.graphics.newImage("mappacks/" .. mappacklist[i] .. "/icon.png")
1291		else
1292			mappackicon[i] = nil
1293		end
1294
1295		mappackauthor[i] = ""
1296		mappackdescription[i] = ""
1297		mappackbackground[i] = "1-1"
1298		if love.filesystem.exists( "mappacks/" .. mappacklist[i] .. "/settings.txt" ) then
1299			local s = love.filesystem.read( "mappacks/" .. mappacklist[i] .. "/settings.txt" )
1300			local s1 = s:split("\n")
1301			for j = 1, #s1 do
1302				local s2 = s1[j]:split("=")
1303				if s2[1] == "name" then
1304					mappackname[i] = s2[2]
1305				elseif s2[1] == "author" then
1306					mappackauthor[i] = s2[2]
1307				elseif s2[1] == "description" then
1308					mappackdescription[i] = s2[2]
1309				elseif s2[1] == "background" then
1310					mappackbackground[i] = s2[2]
1311				end
1312			end
1313		else
1314			mappackname[i] = mappacklist[i]
1315		end
1316	end
1317
1318	table.insert(mappacklist, "custom_mappack")
1319	table.insert(mappackname, "{new mappack}")
1320	table.insert(mappackauthor, "you")
1321	table.insert(mappackdescription, "create a mappack from scratch withthis!")
1322
1323	--get the current cursorposition
1324	for i = 1, #mappacklist do
1325		if mappacklist[i] == mappack then
1326			mappackselection = i
1327		end
1328	end
1329
1330	mappack = mappacklist[mappackselection]
1331
1332	--load background
1333	if mappackbackground[mappackselection] then
1334		loadbackground(mappackbackground[mappackselection] .. ".txt")
1335	else
1336		loadbackground("1-1.txt")
1337	end
1338
1339	mappackscroll = 0
1340	updatescroll()
1341	mappackscrollsmooth = mappackscroll
1342end
1343
1344function loadonlinemappacks()
1345	mappacktype = "online"
1346	downloadmappacks()
1347	onlinemappacklist = love.filesystem.enumerate( "mappacks" )
1348
1349	local delete = {}
1350	for i = 1, #onlinemappacklist do
1351		if not love.filesystem.exists( "mappacks/" .. onlinemappacklist[i] .. "/version.txt") or not love.filesystem.exists( "mappacks/" .. onlinemappacklist[i] .. "/settings.txt") then
1352			table.insert(delete, i)
1353		end
1354	end
1355
1356	table.sort(delete, function(a,b) return a>b end)
1357
1358	for i, v in pairs(delete) do
1359		table.remove(onlinemappacklist, v) --remove
1360	end
1361
1362	onlinemappackicon = {}
1363
1364	--get info
1365	onlinemappackname = {}
1366	onlinemappackauthor = {}
1367	onlinemappackdescription = {}
1368	onlinemappackbackground = {}
1369
1370	for i = 1, #onlinemappacklist do
1371		if love.filesystem.exists( "mappacks/" .. onlinemappacklist[i] .. "/icon.png" ) then
1372			onlinemappackicon[i] = love.graphics.newImage("mappacks/" .. onlinemappacklist[i] .. "/icon.png")
1373		else
1374			onlinemappackicon[i] = nil
1375		end
1376
1377		onlinemappackauthor[i] = nil
1378		onlinemappackdescription[i] = nil
1379		onlinemappackbackground[i] = nil
1380		if love.filesystem.exists( "mappacks/" .. onlinemappacklist[i] .. "/settings.txt" ) then
1381			local s = love.filesystem.read( "mappacks/" .. onlinemappacklist[i] .. "/settings.txt" )
1382			local s1 = s:split("\n")
1383			for j = 1, #s1 do
1384				local s2 = s1[j]:split("=")
1385				if s2[1] == "name" then
1386					onlinemappackname[i] = s2[2]
1387				elseif s2[1] == "author" then
1388					onlinemappackauthor[i] = s2[2]
1389				elseif s2[1] == "description" then
1390					onlinemappackdescription[i] = s2[2]
1391				elseif s2[1] == "background" then
1392					onlinemappackbackground[i] = s2[2]
1393				end
1394			end
1395		else
1396			onlinemappackname[i] = onlinemappacklist[i]
1397		end
1398	end
1399
1400	--get the current cursorposition
1401	for i = 1, #onlinemappacklist do
1402		if onlinemappacklist[i] == mappack then
1403			onlinemappackselection = i
1404		end
1405	end
1406
1407	if #onlinemappacklist >= 1 then
1408		mappack = onlinemappacklist[onlinemappackselection]
1409	end
1410
1411	--load background
1412	if onlinemappackbackground[onlinemappackselection] then
1413		loadbackground(onlinemappackbackground[onlinemappackselection] .. ".txt")
1414	else
1415		loadbackground("1-1.txt")
1416	end
1417
1418	onlinemappackscroll = 0
1419	onlineupdatescroll()
1420	onlinemappackscrollsmooth = onlinemappackscroll
1421end
1422
1423function downloadmappacks()
1424	downloaderror = false
1425	local onlinedata, code = http.request("http://server.stabyourself.net/mari0/index2.php?mode=mappacks")
1426
1427	if code ~= 200 then
1428		downloaderror = true
1429		return false
1430	elseif not onlinedata then
1431		downloaderror = true
1432		return false
1433	end
1434
1435	local maplist = {}
1436	local versionlist = {}
1437	local latestversion = marioversion
1438
1439	local split1 = onlinedata:split("<")
1440	for i = 2, #split1 do
1441		local split2 = split1[i]:split(">")
1442		if split2[1] == "latestversion" then
1443			latestversion = tonumber(split2[2])
1444		elseif split2[1] == "mapfile" then
1445			table.insert(maplist, split2[2])
1446		elseif split2[1] == "version" then
1447			table.insert(versionlist, tonumber(split2[2]))
1448		end
1449	end
1450
1451	if latestversion > marioversion then
1452		outdated = true
1453		return false
1454	end
1455
1456	success = true
1457
1458	--download all mappacks
1459	for i = 1, #maplist do
1460		--check if current version is equal or newer
1461		local version = 0
1462		if love.filesystem.exists("mappacks/" .. maplist[i] .. "/version.txt") then
1463			local data = love.filesystem.read("mappacks/" .. maplist[i] .. "/version.txt")
1464			if data then
1465				version = tonumber(data)
1466			end
1467		end
1468
1469		if version < versionlist[i] then
1470			print("DOWNLOADING MAPPACK: " .. maplist[i])
1471
1472			--draw
1473			currentdownload = i
1474			downloadcount = #maplist
1475
1476			if love.filesystem.exists("mappacks/" .. maplist[i] .. "/") then
1477				love.filesystem.remove("mappacks/" .. maplist[i] .. "/")
1478			end
1479
1480			love.filesystem.mkdir("mappacks/" .. maplist[i])
1481			local onlinedata, code = http.request("http://server.stabyourself.net/mari0/index2.php?mode=getmap&get=" .. maplist[i])
1482
1483			if code == 200 then
1484				filecount = 0
1485				local checksums = {}
1486
1487				local split1 = onlinedata:split("<")
1488				for j = 2, #split1 do
1489					local split2 = split1[j]:split(">")
1490					if split2[1] == "asset" then
1491						filecount = filecount + 1
1492					elseif split2[1] == "checksum" then
1493						table.insert(checksums, split2[2])
1494					end
1495				end
1496
1497				currentfiledownload = 1
1498
1499				local split1 = onlinedata:split("<")
1500				for j = 2, #split1 do
1501					local split2 = split1[j]:split(">")
1502					if split2[1] == "asset" then
1503						loadingonlinemappacks = true
1504						love.graphics.clear()
1505						love.draw()
1506						love.graphics.present()
1507						loadingonlinemappacks = false
1508
1509						local target = "mappacks/" .. maplist[i] .. "/" .. split2[2]:match("([^/]-)$")
1510
1511						local tries = 0
1512						success = false
1513						while not success and tries < 3 do
1514							success = downloadfile(split2[2], target, checksums[currentfiledownload])
1515							tries = tries + 1
1516						end
1517
1518						if not success then
1519							break
1520						end
1521						currentfiledownload = currentfiledownload + 1
1522					end
1523				end
1524				if success then
1525					love.filesystem.write( "mappacks/" .. maplist[i] .. "/version.txt", versionlist[i])
1526				end
1527			else
1528				success = false
1529			end
1530		end
1531
1532		--Delete stuff and stuff.
1533		if not success then
1534			if love.filesystem.exists("mappacks/" .. maplist[i] .. "/") then
1535				local list = love.filesystem.enumerate("mappacks/" .. maplist[i] .. "/")
1536				for j = 1, #list do
1537					love.filesystem.remove("mappacks/" .. maplist[i] .. "/" .. list[j])
1538				end
1539
1540				love.filesystem.remove("mappacks/" .. maplist[i] .. "/")
1541			end
1542			downloaderror = true
1543			break
1544		else
1545			print("Download succeeded.")
1546		end
1547	end
1548
1549	return true
1550end
1551
1552function menu_keypressed(key, unicode)
1553	if gamestate == "menu" then
1554		if selectworldopen then
1555			if (key == "right" or key == "d") then
1556				local target = selectworldcursor+1
1557				while target < 9 and not reachedworlds[mappack][target] do
1558					target = target + 1
1559				end
1560				if target < 9 then
1561					selectworldcursor = target
1562				end
1563			elseif (key == "left" or key == "a") then
1564				local target = selectworldcursor-1
1565				while target > 0 and not reachedworlds[mappack][target] do
1566					target = target - 1
1567				end
1568				if target > 0 then
1569					selectworldcursor = target
1570				end
1571			elseif (key == "return" or key == "enter" or key == "kpenter" or key == " ") then
1572				selectworldopen = false
1573				game_load(selectworldcursor)
1574			elseif key == "escape" then
1575				selectworldopen = false
1576			end
1577			return
1578		end
1579		if (key == "up" or key == "w") then
1580			if continueavailable then
1581				if selection > 0 then
1582					selection = selection - 1
1583				end
1584			else
1585				if selection > 1 then
1586					selection = selection - 1
1587				end
1588			end
1589		elseif (key == "down" or key == "s") then
1590			if selection < 4 then
1591				selection = selection + 1
1592			end
1593		elseif (key == "return" or key == "enter" or key == "kpenter" or key == " ") then
1594			if selection == 0 then
1595				game_load(true)
1596			elseif selection == 1 then
1597				selectworld()
1598			elseif selection == 2 then
1599				editormode = true
1600				players = 1
1601				playertype = "portal"
1602				playertypei = 1
1603				bullettime = false
1604				portalknockback = false
1605				bigmario = false
1606				goombaattack = false
1607				sonicrainboom = false
1608				playercollisions = false
1609				infinitetime = false
1610				infinitelives = false
1611				game_load()
1612			elseif selection == 3 then
1613				gamestate = "mappackmenu"
1614				mappacks()
1615			elseif selection == 4 then
1616				gamestate = "options"
1617			end
1618		elseif key == "escape" then
1619			love.event.quit()
1620		elseif (key == "left" or key == "a") then
1621			if players > 1 then
1622				players = players - 1
1623			end
1624		elseif (key == "right" or key == "d") then
1625			players = players + 1
1626			if players > 4 then
1627				players = 4
1628			end
1629		end
1630	elseif gamestate == "mappackmenu" then
1631		if (key == "up" or key == "w") then
1632			if mappacktype == "local" then
1633				if mappackselection > 1 then
1634					mappackselection = mappackselection - 1
1635					mappack = mappacklist[mappackselection]
1636
1637					--load background
1638					if mappackbackground[mappackselection] then
1639						loadbackground(mappackbackground[mappackselection] .. ".txt")
1640					else
1641						loadbackground("1-1.txt")
1642					end
1643
1644					updatescroll()
1645				end
1646			else
1647				if onlinemappackselection > 1 then
1648					onlinemappackselection = onlinemappackselection - 1
1649					mappack = onlinemappacklist[onlinemappackselection]
1650
1651					--load background
1652					if onlinemappackbackground[onlinemappackselection] then
1653						loadbackground(onlinemappackbackground[onlinemappackselection] .. ".txt")
1654					else
1655						loadbackground("1-1.txt")
1656					end
1657
1658					onlineupdatescroll()
1659				end
1660			end
1661		elseif (key == "down" or key == "s") then
1662			if mappacktype == "local" then
1663				if mappackselection < #mappacklist then
1664					mappackselection = mappackselection + 1
1665					mappack = mappacklist[mappackselection]
1666
1667					--load background
1668					if mappackbackground[mappackselection] then
1669						loadbackground(mappackbackground[mappackselection] .. ".txt")
1670					else
1671						loadbackground("1-1.txt")
1672					end
1673
1674					updatescroll()
1675				end
1676			else
1677				if onlinemappackselection < #onlinemappacklist then
1678					onlinemappackselection = onlinemappackselection + 1
1679					mappack = onlinemappacklist[onlinemappackselection]
1680
1681					--load background
1682					if onlinemappackbackground[onlinemappackselection] then
1683						loadbackground(onlinemappackbackground[onlinemappackselection] .. ".txt")
1684					else
1685						loadbackground("1-1.txt")
1686					end
1687
1688					onlineupdatescroll()
1689				end
1690			end
1691		elseif key == "escape" or (key == "return" or key == "enter" or key == "kpenter" or key == " ") then
1692			gamestate = "menu"
1693			saveconfig()
1694			if mappack == "custom_mappack" then
1695				createmappack()
1696			end
1697		elseif (key == "right" or key == "d") then
1698			loadonlinemappacks()
1699			mappackhorscroll = 1
1700		elseif (key == "left" or key == "a") then
1701			loadmappacks()
1702			mappackhorscroll = 0
1703		elseif key == "m" then
1704			if not openSaveFolder("mappacks") then
1705				savefolderfailed = true
1706			end
1707		end
1708	elseif gamestate == "onlinemenu" then
1709		if CLIENT == false and SERVER == false then
1710			if key == "c" then
1711				client_load()
1712			elseif key == "s" then
1713				server_load()
1714			end
1715		elseif SERVER then
1716			if (key == "return" or key == "enter" or key == "kpenter" or key == " ") then
1717				server_start()
1718			end
1719		end
1720	elseif gamestate == "options" then
1721		if optionsselection == 1 then
1722			if (key == "left" or key == "a") then
1723				if optionstab > 1 then
1724					optionstab = optionstab - 1
1725				end
1726			elseif (key == "right" or key == "d") then
1727				if optionstab < 4 then
1728					optionstab = optionstab + 1
1729				end
1730			end
1731		elseif optionsselection == 2 then
1732			if (key == "left" or key == "a") then
1733				if optionstab == 2 or optionstab == 1 then
1734					if skinningplayer > 1 then
1735						skinningplayer = skinningplayer - 1
1736					end
1737				end
1738			elseif (key == "right" or key == "d") then
1739				if optionstab == 2 or optionstab == 1 then
1740					if skinningplayer < 4 then
1741						skinningplayer = skinningplayer + 1
1742						if players > #controls then
1743							loadconfig()
1744						end
1745					end
1746				end
1747			end
1748		end
1749
1750		if (key == "return" or key == "enter" or key == "kpenter" or key == " ") then
1751			if optionstab == 1 then
1752				if optionsselection == 3 then
1753					if mouseowner == skinningplayer then
1754						mouseowner = 0
1755					else
1756						mouseowner = skinningplayer
1757					end
1758				elseif optionsselection > 3 then
1759					keypromptstart()
1760				end
1761			elseif optionstab == 3 then
1762				if optionsselection == 6 then
1763					reset_mappacks()
1764				elseif optionsselection == 7 then
1765					resetconfig()
1766				end
1767			end
1768		elseif (key == "down" or key == "s") then
1769			if optionstab == 1 then
1770				if skinningplayer ~= mouseowner then
1771					if optionsselection < 15 then
1772						optionsselection = optionsselection + 1
1773					else
1774						optionsselection = 1
1775					end
1776				else
1777					if optionsselection < 11 then
1778						optionsselection = optionsselection + 1
1779					else
1780						optionsselection = 1
1781					end
1782				end
1783			elseif optionstab == 2 then
1784				if optionsselection < 14 then
1785					optionsselection = optionsselection + 1
1786				else
1787					optionsselection = 1
1788				end
1789			elseif optionstab == 3 then
1790				if optionsselection < 8 then
1791					optionsselection = optionsselection + 1
1792				else
1793					optionsselection = 1
1794				end
1795			elseif optionstab == 4 and gamefinished then
1796				if optionsselection < 10 then
1797					optionsselection = optionsselection + 1
1798				else
1799					optionsselection = 1
1800				end
1801			end
1802		elseif (key == "up" or key == "w") then
1803			if optionsselection > 1 then
1804				optionsselection = optionsselection - 1
1805			else
1806				if optionstab == 1 then
1807					if skinningplayer ~= mouseowner then
1808						optionsselection = 15
1809					else
1810						optionsselection = 11
1811					end
1812				elseif optionstab == 2 then
1813					optionsselection = 14
1814				elseif optionstab == 3 then
1815					optionsselection = 8
1816				elseif optionstab == 4 and gamefinished then
1817					optionsselection = 10
1818				end
1819			end
1820		elseif (key == "right" or key == "d") then
1821			if optionstab == 2 then
1822				if optionsselection == 3 then
1823					if mariohats[skinningplayer][1] == nil then
1824						mariohats[skinningplayer][1] = 1
1825					elseif mariohats[skinningplayer][1] < #hat then
1826						mariohats[skinningplayer][1] = mariohats[skinningplayer][1] + 1
1827					end
1828				end
1829			elseif optionstab == 3 then
1830				if optionsselection == 2 then
1831					if scale < 5 then
1832						changescale(scale+1)
1833					end
1834				elseif optionsselection == 3 then
1835					currentshaderi1 = currentshaderi1 + 1
1836					if currentshaderi1 > #shaderlist then
1837						currentshaderi1 = 1
1838					end
1839					if shaderlist[currentshaderi1] == "none" then
1840						shaders:set(1, nil)
1841					else
1842						shaders:set(1, shaderlist[currentshaderi1])
1843					end
1844
1845				elseif optionsselection == 4 then
1846					currentshaderi2 = currentshaderi2 + 1
1847					if currentshaderi2 > #shaderlist then
1848						currentshaderi2 = 1
1849					end
1850					if shaderlist[currentshaderi2] == "none" then
1851						shaders:set(2, nil)
1852					else
1853						shaders:set(2, shaderlist[currentshaderi2])
1854					end
1855
1856				elseif optionsselection == 5 then
1857					if volume < 1 then
1858						volume = volume + 0.1
1859						if volume > 1 then
1860							volume = 1
1861						end
1862						love.audio.setVolume( volume )
1863						playsound(coinsound)
1864						soundenabled = true
1865					end
1866				elseif optionsselection == 8 then
1867					vsync = not vsync
1868					changescale(scale)
1869				end
1870			elseif optionstab == 4 then
1871				if optionsselection == 2 then
1872					playertypei = playertypei + 1
1873					if playertypei > #playertypelist then
1874						playertypei = 1
1875					end
1876					playertype = playertypelist[playertypei]
1877					if playertype == "minecraft" then
1878						portalknockback = false
1879						bullettime = false
1880						bigmario = false
1881						sonicrainboom = false
1882					elseif playertype == "gelcannon" then
1883						sonicrainboom = false
1884					end
1885				elseif optionsselection == 3 then
1886					portalknockback = not portalknockback
1887					if portalknockback then
1888						if playertype == "minecraft" then
1889							playertypei = 1
1890							playertype = "portal"
1891						end
1892					end
1893				elseif optionsselection == 4 then
1894					bullettime = not bullettime
1895					if bullettime then
1896						if playertype == "minecraft" then
1897							playertypei = 1
1898							playertype = "portal"
1899						end
1900					end
1901				elseif optionsselection == 5 then
1902					bigmario = not bigmario
1903					if bigmario then
1904						if playertype == "minecraft" then
1905							playertypei = 1
1906							playertype = "portal"
1907						end
1908					end
1909				elseif optionsselection == 6 then
1910					goombaattack = not goombaattack
1911				elseif optionsselection == 7 then
1912					sonicrainboom = not sonicrainboom
1913					playertype = "portal"
1914					playertypei = 1
1915				elseif optionsselection == 8 then
1916					playercollisions = not playercollisions
1917				elseif optionsselection == 9 then
1918					infinitetime = not infinitetime
1919				elseif optionsselection == 10 then
1920					infinitelives = not infinitelives
1921				end
1922			end
1923		elseif (key == "left" or key == "a") then
1924			if optionstab == 2 then
1925				if optionsselection == 3 then
1926					if mariohats[skinningplayer][1] == 1 then
1927						mariohats[skinningplayer] = {}
1928					elseif mariohats[skinningplayer][1] and mariohats[skinningplayer][1] > 1 then
1929						mariohats[skinningplayer][1] = mariohats[skinningplayer][1] - 1
1930					end
1931				end
1932			elseif optionstab == 3 then
1933				if optionsselection == 2 then
1934					if scale > 1 then
1935						changescale(scale-1)
1936					end
1937				elseif optionsselection == 3 then
1938					currentshaderi1 = currentshaderi1 - 1
1939					if currentshaderi1 < 1 then
1940						currentshaderi1 = #shaderlist
1941					end
1942
1943					if shaderlist[currentshaderi1] == "none" then
1944						shaders:set(1, nil)
1945					else
1946						shaders:set(1, shaderlist[currentshaderi1])
1947					end
1948				elseif optionsselection == 4 then
1949					currentshaderi2 = currentshaderi2 - 1
1950					if currentshaderi2 < 1 then
1951						currentshaderi2 = #shaderlist
1952					end
1953
1954					if shaderlist[currentshaderi2] == "none" then
1955						shaders:set(2, nil)
1956					else
1957						shaders:set(2, shaderlist[currentshaderi2])
1958					end
1959
1960				elseif optionsselection == 5 then
1961					if volume > 0 then
1962						volume = volume - 0.1
1963						if volume <= 0 then
1964							volume = 0
1965							soundenabled = false
1966						end
1967						love.audio.setVolume( volume )
1968						playsound(coinsound)
1969					end
1970				elseif optionsselection == 8 then
1971					vsync = not vsync
1972					changescale(scale)
1973				end
1974			elseif optionstab == 4 then
1975				if optionsselection == 2 then
1976					playertypei = playertypei - 1
1977					if playertypei < 1 then
1978						playertypei = #playertypelist
1979					end
1980					playertype = playertypelist[playertypei]
1981					if playertype == "minecraft" then
1982						portalknockback = false
1983						bullettime = false
1984						bigmario = false
1985						sonicrainboom = false
1986					elseif playertype == "gelcannon" then
1987						sonicrainboom = false
1988					end
1989				elseif optionsselection == 3 then
1990					portalknockback = not portalknockback
1991					if portalknockback then
1992						if playertype == "minecraft" then
1993							playertypei = 1
1994							playertype = "portal"
1995						end
1996					end
1997				elseif optionsselection == 4 then
1998					bullettime = not bullettime
1999					if bullettime then
2000						if playertype == "minecraft" then
2001							playertypei = 1
2002							playertype = "portal"
2003						end
2004					end
2005				elseif optionsselection == 5 then
2006					bigmario = not bigmario
2007					if bigmario then
2008						if playertype == "minecraft" then
2009							playertypei = 1
2010							playertype = "portal"
2011						end
2012					end
2013				elseif optionsselection == 6 then
2014					goombaattack = not goombaattack
2015				elseif optionsselection == 7 then
2016					sonicrainboom = not sonicrainboom
2017					playertype = "portal"
2018					playertypei = 1
2019				elseif optionsselection == 8 then
2020					playercollisions = not playercollisions
2021				elseif optionsselection == 9 then
2022					infinitetime = not infinitetime
2023				elseif optionsselection == 10 then
2024					infinitelives = not infinitelives
2025				end
2026			end
2027		elseif key == "escape" then
2028			gamestate = "menu"
2029			saveconfig()
2030		end
2031	end
2032end
2033
2034function menu_keyreleased(key, unicode)
2035
2036end
2037
2038function menu_mousepressed(x, y, button)
2039
2040end
2041
2042function menu_mousereleased(x, y, button)
2043
2044end
2045
2046function menu_joystickpressed(joystick, button)
2047
2048end
2049
2050function menu_joystickreleased(joystick, button)
2051
2052end
2053
2054function keypromptenter(t, ...)
2055	arg = {...}
2056	if t == "key" and (arg[1] == ";" or arg[1] == "," or arg[1] == "," or arg[1] == "-") then
2057		return
2058	end
2059	buttonerror = false
2060	axiserror = false
2061	local buttononly = {"run", "jump", "reload", "use", "portal1", "portal2"}
2062	local axisonly = {"aimx", "aimy"}
2063	if t ~= "key" or arg[1] ~= "escape" then
2064		if t == "key" then
2065			if tablecontains(axisonly, controlstable[optionsselection-3]) then
2066				axiserror = true
2067			else
2068				controls[skinningplayer][controlstable[optionsselection-3]] = {arg[1]}
2069			end
2070		elseif t == "joybutton" then
2071			if tablecontains(axisonly, controlstable[optionsselection-3]) then
2072				axiserror = true
2073			else
2074				controls[skinningplayer][controlstable[optionsselection-3]] = {"joy", arg[1], "but", arg[2]}
2075			end
2076		elseif t == "joyhat" then
2077			if tablecontains(buttononly, controlstable[optionsselection-3]) then
2078				buttonerror = true
2079			elseif tablecontains(axisonly, controlstable[optionsselection-3]) then
2080				axiserror = true
2081			else
2082				controls[skinningplayer][controlstable[optionsselection-3]] = {"joy", arg[1], "hat", arg[2], arg[3]}
2083			end
2084		elseif t == "joyaxis" then
2085			if tablecontains(buttononly, controlstable[optionsselection-3]) then
2086				buttonerror = true
2087			else
2088				controls[skinningplayer][controlstable[optionsselection-3]] = {"joy", arg[1], "axe", arg[2], arg[3]}
2089			end
2090		end
2091	end
2092
2093	if (not buttonerror and not axiserror) or arg[1] == "escape" then
2094		keyprompt = false
2095	end
2096end
2097
2098function keypromptstart()
2099	keyprompt = true
2100	buttonerror = false
2101	axiserror = false
2102
2103	--save number of stuff
2104	prompt = {}
2105	prompt.joystick = {}
2106	prompt.joysticks = love.joystick.getNumJoysticks()
2107
2108	for i = 1, prompt.joysticks do
2109		prompt.joystick[i] = {}
2110		prompt.joystick[i].hats = love.joystick.getNumHats(i)
2111		prompt.joystick[i].axes = love.joystick.getNumAxes(i)
2112
2113		prompt.joystick[i].validhats = {}
2114		for j = 1, prompt.joystick[i].hats do
2115			if love.joystick.getHat(i, j) == "c" then
2116				table.insert(prompt.joystick[i].validhats, j)
2117			end
2118		end
2119
2120		prompt.joystick[i].axisposition = {}
2121		for j = 1, prompt.joystick[i].axes do
2122			table.insert(prompt.joystick[i].axisposition, love.joystick.getAxis(i, j))
2123		end
2124	end
2125end
2126
2127function downloadfile(url, target, checksum)
2128	local data, code = http.request(url)
2129
2130	if code ~= 200 then
2131		return false
2132	end
2133
2134	if checksum ~= sha1(data) then
2135		print("Checksum doesn't match!")
2136		return false
2137	end
2138
2139	if data then
2140		love.filesystem.write(target, data)
2141		return true
2142	else
2143		return false
2144	end
2145end
2146
2147function reset_mappacks()
2148	delete_mappack("smb")
2149	delete_mappack("portal")
2150
2151	loadbackground("1-1.txt")
2152
2153	playsound(oneupsound)
2154end
2155
2156function delete_mappack(pack)
2157	if not love.filesystem.exists("mappacks/" .. pack .. "/") then
2158		return false
2159	end
2160
2161	local list = love.filesystem.enumerate("mappacks/" .. pack .. "/")
2162	for i = 1, #list do
2163		love.filesystem.remove("mappacks/" .. pack .. "/" .. list[i])
2164	end
2165
2166	love.filesystem.remove("mappacks/" .. pack .. "/")
2167end
2168
2169function createmappack()
2170	local i = 1
2171	while love.filesystem.exists("mappacks/custom_mappack_" .. i .. "/") do
2172		i = i + 1
2173	end
2174
2175	mappack = "custom_mappack_" .. i
2176
2177	love.filesystem.mkdir("mappacks/" .. mappack .. "/")
2178
2179	local s = ""
2180	s = s .. "name=new mappack" .. "\n"
2181	s = s .. "author=you" .. "\n"
2182	s = s .. "description=the newest best  mappack?" .. "\n"
2183
2184	love.filesystem.write("mappacks/" .. mappack .. "/settings.txt", s)
2185end
2186
2187function resetconfig()
2188	defaultconfig()
2189
2190	changescale(scale)
2191	love.audio.setVolume(volume)
2192	currentshaderi1 = 1
2193	currentshaderi2 = 1
2194	shaders:set(1, nil)
2195	shaders:set(2, nil)
2196	saveconfig()
2197	loadbackground("1-1.txt")
2198end
2199
2200function selectworld()
2201	if not reachedworlds[mappack] then
2202		game_load()
2203	end
2204
2205	local noworlds = true
2206	for i = 2, 8 do
2207		if reachedworlds[mappack][i] then
2208			noworlds = false
2209			break
2210		end
2211	end
2212
2213	if noworlds then
2214		game_load()
2215		return
2216	end
2217
2218	selectworldopen = true
2219	selectworldcursor = 1
2220
2221	selectworldexists = {}
2222	for i = 1, 8 do
2223		if love.filesystem.exists("mappacks/" .. mappack .. "/" .. i .. "-1.txt") then
2224			selectworldexists[i] = true
2225		end
2226	end
2227end