--screenshot
niveaua=1

perso = Image.load("jeu/marioperso.png")
Perso = {}
Perso[1] = { x = 10, y = 210, alive=true }
block = Image.load("jeu/peach.png")
Block = {}                                                                                         
Block[1] = { x = 190, y = 123, alive=true }
mariosound = Sound.load("jeu/mario.wav", true)
voice = mariosound:play()
mur = Image.load("jeu/lab.png")
sol = Image.load("jeu/sol.png")
transparent = mur:pixel(0,0)

while true do
screen:clear()
screen:blit(0,0,sol)
screen:blit(0,0,mur)
screen:blit(Block[1].x,Block[1].y,block)
screen:blit(Perso[1].x,Perso[1].y,perso)

pad = Controls.read()

function move_player()

if pad:left() then
direction="left" 
if Perso[1].x>1 then
Perso[1].x=Perso[1].x-3
end
end
if pad:right() then
direction="right"
if Perso[1].x<460 then
Perso[1].x=Perso[1].x+3
end
end
if pad:up() then Perso[1].y = Perso[1].y - 3 end
if pad:down() then Perso[1].y =  Perso[1].y + 3 end
end

function collision_perso()

if Block[1].alive then

if Perso[1].x+11>Block[1].x and Perso[1].x<Block[1].x+11 and Perso[1].y+11>Block[1].y and Perso[1].y<Block[1].y+11 then

voice:stop()
dofile("gagne.lua")

end
end
end


function collision_mur()

couleurhaut = mur:pixel(Perso[1].x+10,Perso[1].y+8)
couleurdroite = mur:pixel(Perso[1].x+18,Perso[1].y+13)
couleurbas = mur:pixel(Perso[1].x+10,Perso[1].y+22)
couleurgauche = mur:pixel(Perso[1].x+1,Perso[1].y+13)
if couleurhaut ~= transparent then Perso[1].y = Perso[1].y + 3 end
if couleurdroite ~= transparent then Perso[1].x = Perso[1].x - 3 end
if couleurbas ~= transparent then Perso[1].y = Perso[1].y - 3 end
if couleurgauche ~= transparent then Perso[1].x = Perso[1].x + 3 end 
end

if pad:select() then
screen:save("ms0:/PSP/PHOTO/niveaua"..niveaua..".png")
niveaua=niveaua+1
end

collision_mur()
move_player()
collision_perso()

screen.flip()
screen.waitVblankStart()
end