--[[Smash My PSP! v3.1
by zeroXorXdieXskater]]



-- Colors
white = Color.new(0, 0, 0)
black = Color.new(255, 255, 255)
red = Color.new(255, 0, 0)

function smashtrue()
	smash = true
end

function controlplay()
if pad:start() then
	gamestate = "paused"
end

if pad:note() then
	screen:save("screenshot.png")
end

if pad:cross() then
	smashtrue()
end

if pad:select() then
	gamestate = "picselect"

end
end

gamestate = "intro"


-------------------------------------------------while loop
while true do
screen:clear()
pad = Controls.read()

if smash == true then
	if weapon.img == hammer1 and crackin == 1 then
		hammersnd:play()
		weapon.img = hammer2
		weapon.smashpic = crack1
		fake:blit(weapon.x, weapon.y, weapon.smashpic)
		crackin = 2
	else if weapon.img == hammer1 and crackin == 2 then
		hammersnd:play()
		weapon.img = hammer2
		weapon.smashpic = crack2
		fake:blit(weapon.x, weapon.y, weapon.smashpic)
		crackin = 3
	else if weapon.img == hammer1 and crackin == 3 then
		hammersnd:play()
		weapon.img = hammer2
		weapon.smashpic = crack3
		fake:blit(weapon.x, weapon.y, weapon.smashpic)
		crackin = 4
	else if weapon.img == hammer1 and crackin == 4 then
		hammersnd:play()
		weapon.img = hammer2
		weapon.smashpic = crack4
		fake:blit(weapon.x, weapon.y, weapon.smashpic)
		crackin = 1
	else if weapon.img == hammer2 then
		weapon.img = hammer1

	else if weapon.img == pinkcrayon then
		weapon.smashpic = pinkpaint
		fake:blit(weapon.x, weapon.y, weapon.smashpic)
	
	else if weapon.img == bluecrayon then
		weapon.smashpic = bluepaint
		fake:blit(weapon.x, weapon.y, weapon.smashpic)

	else if weapon.img == smileystamp1 then
		popsnd:play()
		weapon.img = smileystamp2
		weapon.smashpic = smileyprint
		fake:blit(weapon.x, weapon.y, weapon.smashpic)
	else if weapon.img == smileystamp2 then
		weapon.img = smileystamp1

	else if weapon.img == alienstamp1 then
		popsnd:play()
		weapon.img = alienstamp2
		weapon.smashpic = alien
		fake:blit(weapon.x, weapon.y, weapon.smashpic)
	else if weapon.img == alienstamp2 then
		weapon.img = alienstamp1

	else if weapon.img == splatterstamp1 then
		popsnd:play()
		weapon.img = splatterstamp2
		weapon.smashpic = splatter
		fake:blit(weapon.x, weapon.y, weapon.smashpic)
	else if weapon.img == splatterstamp2 then
		weapon.img = splatterstamp1

	else if weapon.img == gun1 then
		gunsnd:play()
		weapon.img = gun2
		weapon.smashpic = bullet
		fake:blit(weapon.x - math.random(0,30), weapon.y - math.random(0,40), weapon.smashpic)
	else if weapon.img == gun2 then
		weapon.img = gun1

	else if weapon.img == multi and colorin == 1 then
		popsnd:play()
		weapon.smashpic = bluedot
		fake:blit(weapon.x - math.random(0,60), weapon.y - math.random(0,60), weapon.smashpic)
		colorin = 2
		
	else if weapon.img == multi and colorin == 2 then
		popsnd:play()
		weapon.smashpic = reddot
		fake:blit(weapon.x - math.random(0,60), weapon.y - math.random(0,60), weapon.smashpic)
		colorin = 3
		
	else if weapon.img == multi and colorin == 3 then
		popsnd:play()
		weapon.smashpic = greendot
		fake:blit(weapon.x - math.random(0,60), weapon.y - math.random(0,60), weapon.smashpic)
		colorin = 1
		

	else if weapon.img == chainsaw then
		weapon.smashpic = dot
		fake:blit(weapon.x, weapon.y, weapon.smashpic)

	else if weapon.img == phaser1 then
		phasersnd:play()
		weapon.img = phaser2
		weapon.smashpic = phased
		fake:blit(weapon.x, weapon.y, weapon.smashpic)
	else if weapon.img == phaser2 then
		weapon.img = phaser1

	else if weapon.img == pistol1 then
		gunsnd:play()
		weapon.img = pistol2
		weapon.smashpic = bullet
		fake:blit(weapon.x - math.random(20,30), weapon.y - math.random(20,30), weapon.smashpic)
	else if weapon.img == pistol2 then
		weapon.img = pistol1
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	end
	smash = false
end
end

---------------------------------gamestates
if gamestate == "intro" then
title = Image.load("title.png")

screen:clear()
screen:blit(0, 0, title, false)
screen:print(200, 170, "Loading", red)
screen:print(440, 2, "v3.1", red)
screen.flip()
screen.waitVblankStart(20)

--------------------------------------weapons
hammer1 = Image.load( "weapons/hammer1.png" )
hammer2 = Image.load( "weapons/hammer2.png" )
crack1 = Image.load( "weapons/crack1.png" )
crack2 = Image.load( "weapons/crack2.png" )
crack3 = Image.load( "weapons/crack3.png" )
crack4 = Image.load( "weapons/crack4.png" )
pinkcrayon = Image.load( "weapons/pinkcrayon.png" )
pinkpaint = Image.load( "weapons/pinkcolor.png" )
bluecrayon = Image.load( "weapons/bluecrayon.png" )
bluepaint = Image.load( "weapons/bluecolor.png" )
smileystamp1 = Image.load( "weapons/stamp1.png" )
smileystamp2 = Image.load( "weapons/stamp2.png" )
smileyprint = Image.load( "weapons/smiley.png")
alienstamp1 = Image.load( "weapons/stamp1.png" )
alienstamp2 = Image.load( "weapons/stamp2.png" )
alien = Image.load("weapons/alien.png")
splatterstamp1 = Image.load( "weapons/stamp1.png" )
splatterstamp2 = Image.load( "weapons/stamp2.png" )
splatter = Image.load("weapons/splatter.png")
gun1 = Image.load("weapons/gun1.png")
gun2 = Image.load("weapons/gun2.png")
bullet = Image.load("weapons/bullet.png")
multi = Image.load("weapons/multi.png")
bluedot = Image.load("weapons/bluedot.png")
reddot = Image.load("weapons/reddot.png")
greendot = Image.load("weapons/greendot.png")
chainsaw = Image.load("weapons/chainsaw.png")
dot = Image.load("weapons/dot.png")
phaser1 = Image.load("weapons/phaser1.png")
phaser2 = Image.load("weapons/phaser2.png")
phased = Image.load("weapons/phased.png")
pistol1 = Image.load("weapons/pistol1.png")
pistol2 = Image.load("weapons/pistol2.png")
weapon = {}
weapon = { x = 2, y = 50, speed = 4, img = nil, smashpic = nil}
fake = Image.createEmpty(480,272)

--------------------------------------------sounds
gunsnd = Sound.load("sounds/gun.wav", false)
phasersnd = Sound.load("sounds/phaser.wav", false)
popsnd = Sound.load("sounds/pop.wav", false)
hammersnd = Sound.load("sounds/hammer.wav", false)

----------------------------------------------backgrounds
backgroundsmenu = Image.load("backgroundsmenu.png")
default = Image.load("backgrounds/default.jpg")
customtheme1 = Image.load("backgrounds/customtheme1.jpg")
fahzakpon = Image.load("backgrounds/Fah Zakpon.jpg")
popbean = Image.load("backgrounds/popbean.png")
background = default

pausemenu = Image.load("pause.png")
aboutmenu = Image.load("about.png")
Resolution = { width = 480, height = 272 }
gamestate = nil

screen:clear()
screen:blit(0, 0, title, false)
screen:print(200, 170, "Loading.", red)
screen:print(440, 2, "v3.1", red)
screen.flip()
screen.waitVblankStart(20)

------------------------------------controls
function moveplayer()
anaX=pad:analogX()
anaY=pad:analogY()
if pad:up() and weapon.y > 0 then
	weapon.y = weapon.y - 2
end

if pad:down() and weapon.y < ( Resolution.height) then
	weapon.y = weapon.y + 2
end

if pad:left() and weapon.x > 0 then
	weapon.x = weapon.x - 2
end

if pad:right() and weapon.x < ( 480) then
	weapon.x = weapon.x + 2
end

if anaY<-50 and weapon.y > 0 then
	weapon.y = weapon.y - 2
end

if anaY>50 and weapon.y < ( Resolution.height ) then
	weapon.y = weapon.y + 2
end

if anaX<-50 and weapon.x > 0 then
	weapon.x = weapon.x - 2
end

if anaX>50 and weapon.x < ( 480 ) then
	weapon.x = weapon.x + 2
end

if anaY<-127 and weapon.y > 0 then
	weapon.y = weapon.y - weapon.speed
end

if anaY>126 and weapon.y < ( Resolution.height ) then
	weapon.y = weapon.y + weapon.speed
end

if anaX<-127 and weapon.x > 0 then
	weapon.x = weapon.x - weapon.speed
end

if anaX>126 and weapon.x < ( 480 ) then
	weapon.x = weapon.x + weapon.speed
end
end

screen:clear()
screen:blit(0, 0, title, false)
screen:print(200, 170, "Loading..", red)
screen:print(440, 2, "v3.1", red)
screen.flip()
screen.waitVblankStart(20)

crackin = 1
colorin = 1
weapon.img = hammer1
menustatus = 1

screen:clear()
screen:blit(0, 0, title, false)
screen:print(200, 170, "Loading...", red)
screen:print(440, 2, "v3.1", red)
screen.flip()
screen.waitVblankStart(50)

gamestate = "play"
end

if gamestate == "play" then
	screen:blit(0,0,background)
	screen:blit(0,0,fake)
	screen:blit(weapon.x,weapon.y,weapon.img)
	moveplayer()
	controlplay()	
end

-----------------------pause
if gamestate == "paused" then
screen:blit(0,0,pausemenu)
	if pad:circle() then
		gamestate = "play"
	end
	if pad:up() then
    		menustatus = menustatus - 1
    		screen.waitVblankStart(4)
	end
	if pad:down() then
    		menustatus = menustatus + 1
    		screen.waitVblankStart(4)
	end
	if pad:left() then
    		menustatus = menustatus - 5
    		screen.waitVblankStart(4)
	end
	if pad:right() then
    		menustatus = menustatus + 5
    		screen.waitVblankStart(4)
	end

color={white,white,white,white,white,white,white,white,white,white,white,white,white}
color[menustatus]=red

screen:print(50, 50, "Hammer", color[1])
screen:print(50, 60, "Pink Crayon", color[2])
screen:print(50, 70, "Blue Crayon", color[3])
screen:print(50, 80, "Smiley Stamp", color[4])
screen:print(50, 90, "Alien Stamp", color[5])
screen:print(50, 100, "Splatter Stamp", color[6])
screen:print(50, 110, "Machine Gun", color[7])
screen:print(50, 120, "Pistol Gun", color[8])
screen:print(50, 130, "Multi-Color Gun", color[9])
screen:print(50, 140, "Chainsaw", color[10])
screen:print(50, 150, "Phaser", color[11])
screen:print(50, 160, "Reset", color[12])

if menustatus == 1 then
    if pad:cross() then
    	weapon.img = hammer1
	gamestate = "play"
    end
end

if menustatus == 2 then
    if pad:cross() then
    	weapon.img = pinkcrayon
	gamestate = "play"
    end
end

if menustatus == 3 then
    if pad:cross() then
    	weapon.img = bluecrayon
	gamestate = "play"
    end
end

if menustatus == 4 then
		if pad:cross() then
		weapon.img = smileystamp1
		gamestate = "play"
		end
end

if menustatus == 5 then
		if pad:cross() then
		weapon.img = alienstamp1
		gamestate = "play"
		end
end

if menustatus == 6 then
		if pad:cross() then
		weapon.img = splatterstamp1
		gamestate = "play"
		end
end

if menustatus == 7 then
		if pad:cross() then
		weapon.img = gun1
		gamestate = "play"
		end
end

if menustatus == 8 then
		if pad:cross() then
		weapon.img = pistol1
		gamestate = "play"
		end
end

if menustatus == 9 then
		if pad:cross() then
		weapon.img = multi
		gamestate = "play"
		end
end

if menustatus == 10 then
		if pad:cross() then
		weapon.img = chainsaw
		gamestate = "play"
		end
end

if menustatus == 11 then
		if pad:cross() then
		weapon.img = phaser1
		gamestate = "play"
		end
end

if menustatus == 12 then
		if pad:cross() then
		fake:clear()
		gamestate = "play"
		end
end

if menustatus <= 0 then
    menustatus = 12
end
if menustatus >= 13 then
    menustatus = 1
end
end

-------------------------------backgrounds
if gamestate == "picselect" then
screen:blit(0,0,backgroundsmenu)
	if pad:circle() then
		gamestate = "play"
	end
	if pad:up() then
    		menustatus = menustatus - 1
    		screen.waitVblankStart(4)
	end
	if pad:down() then
    		menustatus = menustatus + 1
    		screen.waitVblankStart(4)
	end

color={white, white, white, white, white, white, white}
color[menustatus]=red
screen:print(50, 50, "Default", color[1])
screen:print(50, 60, "Custom Theme 1", color[2])
screen:print(50, 70, "Fah Zakpon (Patapon 2)", color[3])
screen:print(50, 80, "Pop Bean (Patapon)", color[4])
screen:print(50, 90, "Custom Background JPG", color[5])
screen:print(50, 100, "Custom Background PNG", color[6])
screen:print(50, 110, "Custom Background GIF", color[7])


if menustatus == 1 then
    if pad:cross() then
    	background = default
	fake:clear()
	gamestate = "play"
    end
end

if menustatus == 2 then
    if pad:cross() then
    	background = customtheme1
	fake:clear()
	gamestate = "play"
    end
end

if menustatus == 3 then
    if pad:cross() then
    	background = fahzakpon
	fake:clear()
	gamestate = "play"
    end
end

if menustatus == 4 then
    if pad:cross() then
	background = popbean
	fake:clear()
	gamestate = "play"
    end
end

if menustatus == 5 then
    if pad:cross() then
    	customjpg = Image.load("backgrounds/custom.jpg")
	background = customjpg
	fake:clear()
	gamestate = "play"
    end
end

if menustatus == 6 then
    if pad:cross() then
    	custompng = Image.load("backgrounds/custom.gif")
	background = custompng
	fake:clear()
	gamestate = "play"
    end
end

if menustatus == 7 then
    if pad:cross() then
    	custompng = Image.load("backgrounds/custom.png")
	background = custompng
	fake:clear()
	gamestate = "play"
    end
end


if menustatus <= 0 then
    menustatus = 7
end
if menustatus >= 8 then
    menustatus = 1
end
end	

screen.waitVblankStart()
screen.flip()
end