-- xmb destruction
-- by yongobongo and lmtlmt



System.oaenable()
System.usbDiskModeActivate()
red = Color.new(255,0,0)


weapons = { 
gun = Image.load("image/gun.png"), 
gun_shot = Image.load("image/gun_shoot.png"),
flame = Image.load("image/flame.png"),
drill = Image.load("image/drill.png"),
drill2 = Image.load("image/drill2.png"),
sprayc = Image.load("image/sprayc.png"),
sprayc2 = Image.load("image/sprayc2.png"),
sgun = Image.load("image/sgun.png"),  
hammer = Image.load("image/hammer.png"),
hammer_hit = Image.load("image/hammer_hit.png"),
laser = Image.load("image/laser.png"),
laser2 = Image.load("image/laser2.png"),
paint = Image.load("image/paint.png"),
stamp = Image.load("image/stamp.png"),
stamp2 = Image.load("image/stamp2.png"),
crayon = Image.load("image/crayon.png"),
crayon2 = Image.load("image/crayon2.png"),
wash = Image.load("image/wash.png"),
current = 1
}

ammo = {
burn = Image.load("image/burn.png"),
burn2 = Image.load("image/burn2.png"),
spray = Image.load("image/spray.png"),
crack = Image.load("image/crack.png"),
crack_2 = Image.load("image/crack4.png"),
crack_3 = Image.load("image/crack3.png"),
crack_4 = Image.load("image/crack2.png"),
laser_burn = Image.load("image/laser_burn.png"),
shot = Image.load("image/shot3.png"),
sshot_1 = Image.load("image/sshot.png"),
sshot_2 = Image.load("image/sshot2.png"),
sshot_3 = Image.load("image/sshot3.png"),
dot = Image.load("image/dot2.png"),
hole = Image.load("image/hole.png"),
splat_1 = Image.load("image/splat_1.png"),
splat_2 = Image.load("image/splat_2.png"),
splat_3 = Image.load("image/splat_3.png"),
splat_4 = Image.load("image/splat_4.png"),
splat_5 = Image.load("image/splat_5.png"),
stamp_1 = Image.load("image/stamp_1.png"),
stamp_2 = Image.load("image/stamp_2.png"),
stamp_3 = Image.load("image/stamp_3.png"),
}





	aim = Image.createEmpty(3,3)
	aim:clear(red)
	aimx = 0
	aimy = 0
	gsnd = Sound.load("bang.wav",false)
	hsnd = Sound.load("smash.wav",false)
	wsnd = Sound.load("water.wav",false)
	psnd = Sound.load("paint.wav",false)
	ssnd = Sound.load("stamp.wav",false)
	fsnd = Sound.load("blast.wav",false)
	lsnd = Sound.load("laser.wav",false)
	dsnd = Sound.load("laser.wav",false)
	sgsnd = Sound.load("sg.wav",false)
	speed = 25
	

xmb = {
xmb = Image.load("image/xmb.png"),
overlay = Image.createEmpty(480,272)
}

cursor = { x = 100, y = 100, image = weapons.gun, weapon = "gun", fire = false }

function controlCursor()
ax = pad:analogX()
ay = pad:analogY()

if math.abs(ax) > speed then 
cursor.x = cursor.x + ax/speed
end

if cursor.x > 480 then cursor.x = 480 end
if cursor.x < -20 then cursor.x = -20 end
if cursor.y > 272 then cursor.y = 272 end
if cursor.y < -30 then cursor.y = -30 end

if math.abs(ay) > speed then
cursor.y = cursor.y + ay/speed
end

screen:blit(cursor.x, cursor.y, cursor.image)
end

function graphics()
screen:clear()
screen:blit(0,0,xmb.xmb)
screen:blit(0,0,xmb.overlay)
screen:blit(aimx,aimy,aim)





end

function weapon()
pad = Controls.read()

if pad:cross() and not oldpad:cross() then
cursor.fire = true
else
cursor.fire = false
end



if cursor.weapon == "gun" then
aimx = cursor.x + 5
aimy = cursor.y - 20
speed = 15
if pad:cross() then
cursor.image = weapons.gun_shot
xmb.overlay:blit(cursor.x - math.random(0,30), cursor.y - math.random(25,40), ammo.shot)
gsnd:play()
else
cursor.image = weapons.gun
end



elseif cursor.weapon == "crayon" then
aimx = 500
aimy = 500
speed = 25
if pad:cross() then
xmb.overlay:blit(cursor.x - 5 , cursor.y - 5 , ammo.dot)
else
cursor.image = weapons.crayon
end
if pad:cross() then
cursor.image = weapons.crayon2
else
cursor.image = weapons.crayon
end

elseif cursor.weapon == "sprayc" then
aimx = cursor.x 
aimy = cursor.y + 5
speed = 25
if pad:cross() then
xmb.overlay:blit(cursor.x - 5 , cursor.y  , ammo.spray)
else
cursor.image = weapons.sprayc
end
if pad:cross() then
cursor.image = weapons.sprayc2
else
cursor.image = weapons.sprayc
end

elseif cursor.weapon == "drill" then
aimx = 500
aimy = 500
speed = 25
if cursor.fire then
cursor.image = weapons.drill
xmb.overlay:blit(cursor.x , cursor.y + 15, ammo.hole)
dsnd:play()
else
cursor.image = weapons.drill
end
if pad:cross() then
cursor.image = weapons.drill2
else
cursor.image = weapons.drill
end

elseif cursor.weapon == "hammer" then
aimx = -4
aimy = -4
speed = 25
if cursor.fire then
cursor.image = weapons.hammer_hit
hsnd:play()
lol = math.random(1,3)

if lol == 1 then
xmb.overlay:blit(cursor.x - 10, cursor.y - 1, ammo.crack)
elseif lol == 2 then
xmb.overlay:blit(cursor.x- 10, cursor.y - 1, ammo.crack_2)
elseif lol == 3 then
xmb.overlay:blit(cursor.x- 10, cursor.y - 1, ammo.crack_3)
elseif lol == 4 then
xmb.overlay:blit(cursor.x- 10, cursor.y - 1, ammo.crack_4)
end

else
cursor.image = weapons.hammer
end
if pad:cross() then
cursor.image = weapons.hammer_hit
else
cursor.image = weapons.hammer
end

elseif cursor.weapon == "wash" then
aimx = cursor.x - 40
aimy = cursor.y - 40
speed = 25
if pad:cross() then
cursor.image = weapons.wash
xmb.overlay:fillRect(cursor.x - 90,cursor.y - 90,90,90,Color.new(0,0,0,0))
wsnd:play()
else
cursor.image = weapons.wash
end

elseif cursor.weapon == "laser" then
aimx = cursor.x - 20
aimy = cursor.y - 20
speed = 25
if cursor.fire then
cursor.image = weapons.laser
xmb.overlay:blit(cursor.x - 60, cursor.y - 60, ammo.laser_burn)
lsnd:play()
else
cursor.image = weapons.laser
end
if pad:cross() then
cursor.image = weapons.laser2
else
cursor.image = weapons.laser
end

elseif cursor.weapon == "flame" then
aimx = cursor.x - 20
aimy = cursor.y - 20
speed = 25
if cursor.fire then
cursor.image = weapons.flame
xmb.overlay:blit(cursor.x - 60, cursor.y - 60, ammo.burn)
fsnd:play()
else
cursor.image = weapons.flame
end

elseif cursor.weapon == "sgun" then
aimx = cursor.x - 40
aimy = cursor.y - 20
speed = 25
if cursor.fire then
cursor.image = weapons.sgun
sgsnd:play()
lol = math.random(1,3)

if lol == 1 then
xmb.overlay:blit(cursor.x - math.random(40,70), cursor.y - math.random(20,50), ammo.sshot_1)
elseif lol == 2 then
xmb.overlay:blit(cursor.x - math.random(40,70), cursor.y - math.random(20,50), ammo.sshot_2)
elseif lol == 3 then
xmb.overlay:blit(cursor.x - math.random(40,70), cursor.y - math.random(20,50), ammo.sshot_3)
end
else
cursor.image = weapons.sgun
end



elseif cursor.weapon == "stamp" then
aimx = 500
aimy = 500
speed = 25
if cursor.fire then
cursor.image = weapons.stamp
ssnd:play()
lol = math.random(1,3)

if lol == 1 then
xmb.overlay:blit(cursor.x, cursor.y + 20, ammo.stamp_1)
elseif lol == 2 then
xmb.overlay:blit(cursor.x, cursor.y + 20, ammo.stamp_2)
elseif lol == 3 then
xmb.overlay:blit(cursor.x, cursor.y + 20, ammo.stamp_3)
end
else
cursor.image = weapons.stamp
end
if pad:cross() then
cursor.image = weapons.stamp2
else
cursor.image = weapons.stamp
end

elseif cursor.weapon == "paint" then
aimx = cursor.x - 30
aimy = cursor.y - 30
speed = 25
if cursor.fire then
cursor.image = weapons.paint
psnd:play()

lol = math.random(1,5)

if lol == 1 then
xmb.overlay:blit(cursor.x - math.random(80,90), cursor.y - math.random(80,90), ammo.splat_1)
elseif lol == 2 then
xmb.overlay:blit(cursor.x - math.random(80,90), cursor.y - math.random(80,90), ammo.splat_2)
elseif lol == 3 then
xmb.overlay:blit(cursor.x - math.random(80,90), cursor.y - math.random(80,90), ammo.splat_3)
elseif lol == 4 then
xmb.overlay:blit(cursor.x - math.random(80,90), cursor.y - math.random(80,90), ammo.splat_4)
elseif lol == 5 then
xmb.overlay:blit(cursor.x - math.random(80,90), cursor.y - math.random(80,90), ammo.splat_5)
end
else
cursor.image = weapons.paint
end

end

if weapons.current < 1 then
weapons.current = 11
elseif weapons.current > 11 then
weapons.current = 1
end

if weapons.current == 1 then
cursor.weapon = "gun"
elseif weapons.current == 2 then
cursor.weapon = "hammer"
elseif weapons.current == 3 then
cursor.weapon = "flame"
elseif weapons.current == 4 then
cursor.weapon = "laser"
elseif weapons.current == 5 then
cursor.weapon = "paint"
elseif weapons.current == 6 then
cursor.weapon = "stamp"
elseif weapons.current == 8 then
cursor.weapon = "crayon"
elseif weapons.current == 7 then
cursor.weapon = "sgun"
elseif weapons.current == 10 then
cursor.weapon = "sprayc"
elseif weapons.current == 9 then
cursor.weapon = "drill"
elseif weapons.current == 11 then
cursor.weapon = "wash"
end

if pad:r() and not oldpad:r() then
weapons.current = weapons.current + 1
elseif pad:l() and not oldpad:l() then
weapons.current = weapons.current - 1
end

end

oldpad = Controls.read()

while true do
weapon()
graphics()
controlCursor()


if pad:start() then break end
if pad:select() then screen:save("ms0:/xmb_destruction.png") end


oldpad = pad
screen.flip()
screen.waitVblankStart()
end