-- Super Rock Paper Scissors coded in LUA by pspwner
handofgod = Image.load("./GFX/HandOfGod.png")
bg = Image.load("./GFX/bg1.jpg")
screen:blit(0,0,bg)
screen:blit(0,272-handofgod:height(),handofgod)
screen:flip()
count = 240
pl=5
cl=5
code = 0
max = 3
-- VARIABLES
white = Color.new(255,255,255)
fg = Image.load("./GFX/fg.png")
oldpad = Controls.read()
math.randomseed(os.time())
spos = 94
selection1 = Image.load("./GFX/Selection1.png")
selection0 = Image.load("./GFX/Selection0.png")
s = 0
menu = 0
c = 1
gunavailible = 0
gunused = 0
hogavailible = 0
hogused = 0
gunavailibles = 0
gunuseds = 0
hogavailibles = 0
hoguseds = 0
dofile("choice.lua")
screen:clear()
bg = Image.load("./GFX/bg.png")
-- LOOP
while true do
	if menu == 0 then
	screen:blit(0,0,bg,0,0,480,272)
	screen:blit(240-surrender:width()/2,272-surrender:height(),surrender)
	screen:blit(0,0,fg)
	if s == 0 then
		screen:blit(0,spos,selection0)
	elseif s == 1 then
		screen:blit(480-selection1:width(),spos,selection1)
	end
	elseif menu == 1 then
		screen:blit(0,0,bg)
		if count > 119 then
		screen:print(208,10,"  Rock!",white)
		count = count - 1
		elseif count < 120 and count > 59 then
		screen:print(208,10," Paper!",white)
		count = count -1
		elseif count<60 and count > 0 then
		screen:print(208,10,"Scissors!",white)
		count = count-1
		comp = math.random(1,3)
		elseif count == 0 then
		screen:blit(0,0,choice[player].bg)
		screen:blit(240,0,choice[comp].bg)
		screen:blit(0,272-choice[player].img:height(),choice[player].img)
		screen:blit(480-choice[comp].rimg:width(),272-choice[comp].rimg:height(), choice[comp].rimg)
		screen:print(208,10," Shoot!",white)
		screen:print(95,80,outcome[player*10+comp].txt,white)
		if done == 0 then
		cl = cl + outcome[player*10+comp].cl
		pl = pl + outcome[player*10+comp].pl
		done = 1
		end
		if cl == 0 and pl == 0 then
			screen:print(30,10,"Loser!",white)
			screen:print(410,10,"Loser!",white)			
		elseif cl == 0 then
			screen:print(30,10,"Winner!",white)
			screen:print(410,10,"Loser!",white)
		elseif pl == 0 then
			screen:print(30,10,"Loser!",white)
			screen:print(410,10,"Winner!",white)
		end
		screen:print(130,250,"Press Start for next round.")
		end
		screen:blit(0,0,border)
		screen:print(70,40,pl,white)
		screen:print(410,40,cl,white)
		if pl == 5 and cl < 3 and hogused == 0 then
			hogavailible = 1
		end
		if (pl - cl) >1 and gunused == 0 then
			gunavailible = 1
		end
		screen:print(200,60,"One Player",white)
	elseif menu == 2 then
		screen:blit(0,0,bg)
		if count > 119 then
		screen:print(208,10,"  Rock!",white)
		count = count - 1
		elseif count < 120 and count > 59 then
		screen:print(208,10," Paper!",white)
		count = count -1
		elseif count<60 and count > 0 then
		screen:print(208,10,"Scissors!",white)
		count = count-1
		elseif count == 0 then
		screen:blit(0,0,choice[player].bg)
		screen:blit(240,0,choice[comp].bg)
		screen:blit(0,272-choice[player].img:height(),choice[player].img)
		screen:blit(480-choice[comp].rimg:width(),272-choice[comp].rimg:height(), choice[comp].rimg)
		screen:print(208,10," Shoot!",white)
		screen:print(95,80,outcome[player*10+comp].txt,white)
		if done == 0 then
		cl = cl + outcome[player*10+comp].cl
		pl = pl + outcome[player*10+comp].pl
		done = 1
		end
		if cl == 0 and pl == 0 then
			screen:print(30,10,"Loser!",white)
			screen:print(410,10,"Loser!",white)			
		elseif cl == 0 then
			screen:print(30,10,"Winner!",white)
			screen:print(410,10,"Loser!",white)
		elseif pl == 0 then
			screen:print(30,10,"Loser!",white)
			screen:print(410,10,"Winner!",white)
		end
		screen:print(130,250,"Press Start for next round.")
		end
		screen:blit(0,0,border)
		screen:print(70,40,pl,white)
		screen:print(410,40,cl,white)
		if pl == 5 and cl < 3 and hogused == 0 then
			hogavailible = 1
		end
		if (pl - cl) >1 and gunused == 0 then
			gunavailible = 1
		end
		if cl == 5 and pl < 3 and hoguseds == 0 then
			hogavialibles = 1
		end
		if (cl - pl) > 1 and gunuseds == 0 then
			gunavailibles = 1
		end
		screen:print(200,60,"Two Player",white)
	elseif menu == 3 then
		screen:blit(0,0,choice[c].bg)
		screen:blit(240,0,choice[c].bg)
		screen:blit(0,272-choice[c].img:height(),choice[c].img)
		screen:blit(0,0,choice[c].txt)
	elseif menu == 4 then
		screen:blit(0,0,choice[0].bg)
		screen:blit(240,0,choice[0].bg)
		screen:blit(0,272-choice[5].img:height(),choice[5].img)
		screen:blit(480-choice[4].rimg:width(),272-choice[4].rimg:height(),choice[4].rimg)
		screen:print(180,42, "Options Menu",white)
		screen:print(154,52,"Press L+R to go back.",white)
		screen:print(174,92,"Enter the code:",white)
		if code < 2 and code > 0 then
			screen:print(210,102,"*",white)
		elseif code < 3 and code > 0 then
			screen:print(210,102,"**",white)		
		elseif code < 4 and code > 0 then
			screen:print(210,102,"***",white)		
		elseif code < 5 and code > 0 then
			screen:print(210,102,"****",white)
		end
		if max == 5 then
			screen:print(194,112,"Unlocked!",white)
		end
	end
-- REQUIRED FUNCTIONS
	screen.waitVblankStart()
	screen.flip()
	pad = Controls.read()
	if oldpad ~= pad then
-- CONTROLS
	if pad:select() then
		screen:save("ms0:/PSP/PHOTO/screenshot.png")
	end
	if menu == 0 then
		if pad:down() and spos == 94 then
			spos = 154
		elseif pad:down() then
			spos = 94
		end
		if pad:up() and spos == 154 then
			spos = 94
		elseif pad:up() then
			spos = 154
		end
		if pad:right() and s == 0 then
			s = 1
		elseif pad:right() then
			s = 0
		end
		if pad:left() and s == 1 then
			s = 0
		elseif pad:left() then
			s = 1
		end
		if pad:cross() and spos == 94 and s == 0 then
			menu = 1
			bg = Image.load("./GFX/bgfight.png")
			border = Image.load("./GFX/border.png")
			count = 180
			player = 0
			pl = 5
			cl = 5
			done = 0
		elseif pad:cross() and spos == 154 and s == 0 then
			menu = 2
			bg = Image.load("./GFX/bgfight.png")
			border = Image.load("./GFX/border.png")
		elseif pad:cross() and spos == 94 and s == 1 then
			menu = 3
			c = 1
		elseif pad:cross() and spos == 154 and s == 1 then
			menu = 4
		end
	elseif menu == 1 then
		if pad:l() and pad:r() then
			menu = 0
			bg = Image.load("./GFX/bg.png")
		end
			if pad:down() and count > 0 or pad:cross() and count > 0 then
				player = 1
			elseif pad:left() and count > 0 or pad:square() and count > 0 then
				player = 2
			elseif pad:right() and count > 0 or pad:circle() and count > 0 then
				player = 3
			elseif pad:up() and count > 0 or pad:triangle() and count > 0 then
				if hogavailible == 1 and hogused == 0 then
					player = 5
					hogused = 1
				elseif gunavailible == 1 and gunused == 0 then
					player = 4
					gunused = 1
				else
				player = 0
				end
			end
			if pad:start() and count == 0 then
				if cl == 0 or pl == 0 then
				pl = 5
				cl = 5
				gunavailible = 0
				gunused = 0
				hogavailible = 0
				hogused = 0
				end
				player = 0
				comp = 0
				count = 180
				done = 0
			end
	elseif menu == 2 then
		if pad:l() and pad:r() then
			menu = 0
			bg = Image.load("./GFX/bg.png")
		end
			if pad:down() and count > 0 then
				player = 1
			elseif pad:left() and count > 0 then
				player = 2
			elseif pad:right() and count > 0 then
				player = 3
			elseif pad:up() and count > 0 then
				if hogavailible == 1 and hogused == 0 then
					player = 5
					hogused = 1
				elseif gunavailible == 1 and gunused == 0 then
					player = 4
					gunused = 1
				else
				player = 0
				end
			end
			if pad:cross() and count > 0 then
				comp = 1
			elseif pad:square() and count > 0 then
				comp = 2
			elseif pad:circle() and count > 0 then
				comp = 3
			elseif pad:triangle() and count > 0 then
				if hogavailibles == 1 and hoguseds == 0 then
					comp = 5
					hoguseds = 1
				elseif gunavailibles == 1 and gunuseds == 0 then
					comp = 4
					gunuseds = 1
				else
				comp = 0
				end
			end
			if pad:start() and count == 0 then
				if cl == 0 or pl == 0 then
				pl = 5
				cl = 5
				gunavailible = 0
				gunused = 0
				hogavailible = 0
				hogused = 0
				gunavailibles = 0
				gunuseds = 0
				hogavailibles = 0
				hoguseds = 0
				end
				player = 0
				comp = 0
				count = 180
				done = 0
			end
	elseif menu == 3 then
		if pad:l() and pad:r() then
			menu = 0
			bg = Image.load("./GFX/bg.png")
		end
		if pad:cross() and c < max or pad:right() and c < max or pad:down() and c < max then
			c = c + 1
		end
		if pad:left() and c > 0 or pad:up() and c > 0 then
			c = c - 1
		end
		if pad:triangle() or pad:circle() or pad:square() then
			menu = 0
		end
	elseif menu == 4 then
		if pad:l() and pad:r() then
			menu = 0
			bg = Image.load("./GFX/bg.png")
		end
		if pad:cross() and code == 0 then
			code = 1
		elseif pad:circle() and code == 1 then
			code = 2
		elseif pad:square() and code == 2 then
			code = 3
		elseif pad:triangle() and code == 3 then
			code = 4
			max = 5
		end
	end
end
oldpad = pad
end