function testcollision()
if axeY > 15 and currentTime > 2200 then
if pixelARD ~= transparent then collisionvoiture = 1 end 
if pixelAR ~= transparent  then collisionvoiture = 1 end 
if  pixelARG ~= transparent  then collisionvoiture = 1 end 
if  pixelPARD ~= transparent  then collisionvoiture = 1 end 
if  pixelPARG ~= transparent  then collisionvoiture = 1 end 
if  pixelPAVD ~= transparent  then collisionvoiture = 1 end 
if  pixelPAVG ~= transparent  then collisionvoiture = 1 end 
if  pixelAVD ~= transparent  then collisionvoiture = 1 end 
if  pixelAV ~= transparent  then collisionvoiture = 1 end 
if  pixelAVG ~= transparent then collisionvoiture = 1 end
end
end


function photo()
mnu_photo = Image.load("images/mnu_photo.png")
minuteur:stop()
minuteurphoto = Timer.new()
minuteurphoto:start()
while true do
currentTime2 = minuteurphoto:time()
if currentTime2 < 200 then
screen:blit(positionX, positionY, mnu_photo)
end
if currentTime2 > 200 then
break
end
screen.waitVblankStart()
screen.flip()
end
screen:save("screenshot/screen"..sccnt..".png")
sccnt=sccnt+1
frommenu=false
minuteur:start() 
mnu_photo = nil
end

function pause()
mnu_jeuenpause = Image.load("images/mnu_jeuenpause.png")
while true do
minuteur:stop()
screen:clear()
ZoomIMG(img_voiture,axeX,axeY,0,vecteur)
screen:blit(positionX, positionY, img_background)
screen:blit(positionX, positionY, mnu_jeuenpause)
screen:fontPrint(text2,362,67, ""..minutes..":"..secondes..":"..milisecondes,blanc)
screen:fontPrint(text2,362,92, ""..chminutes..":"..chsecondes..":"..chmilisecondes,orange)
pad = Controls.read()
if pad:start() and oldpad:start() ~= pad:start() then
dofile("main.lua")
break
end
if pad:select() and oldpad:select() ~= pad:select() then 
dofile("intro.lua")
break
end
if pad:square() and oldpad:square() ~= pad:square() then 
frommenu=false
minuteur:start() 
break 
end 
screen.waitVblankStart()
screen:flip()
oldpad = pad 
end
img_background =  nil
mnu_jeuenpause =  nil
end

function partieterminee()
mnu_jeutermine = Image.load("images/mnu_jeutermine.png")
while true do
minuteur:stop()
screen:clear()
ZoomIMG(img_voiture,axeX,axeY,0,vecteur)
screen:blit(positionX, positionY, img_background)
screen:blit(positionX, positionY, mnu_jeutermine)
screen:fontPrint(text2,338,92, ""..minutes..":"..secondes..":"..milisecondes,jaune)
pad = Controls.read()
if pad:start() and oldpad:start() ~= pad:start() then 
dofile("main.lua")
break
end
if pad:select() and oldpad:select() ~= pad:select() then
dofile("intro.lua")
break
end
screen.waitVblankStart()
screen:flip()
oldpad = pad 
end
img_background =  nil
mnu_jeutermine =  nil
end

function nouveaurecord()
mnu_jeurecord = Image.load("images/mnu_jeurecord.png")
file = io.open("savename.txt", "r")
name = file:read()
file:close()
while true do
minuteur:stop()
screen:clear()
ZoomIMG(img_voiture,axeX,axeY,0,vecteur)
screen:blit(positionX, positionY, img_background)
screen:blit(positionX, positionY, mnu_jeurecord)
screen:fontPrint(text2,338,92, ""..minutes..":"..secondes..":"..milisecondes,jaune)
screen:fontPrint(text2,320,68,name,orange)
pad = Controls.read()
if pad:l() and pad:r() then
photo()
end
if pad:start() and oldpad:start() ~= pad:start() then
dofile("main.lua")
break
end
if pad:select() and oldpad:select() ~= pad:select() then
savegame()
dofile("restauration.lua")
break
end
screen.waitVblankStart()
screen:flip()
oldpad = pad 
end
img_background =  nil
mnu_jeurecord =  nil
end

function collision()
mnu_collision = Image.load("images/mnu_collision.png")
while true do
minuteur:stop()
screen:clear()
ZoomIMG(img_collisionvoiture,axeX,axeY,0,vecteur)
screen:blit(positionX, positionY, img_background)
screen:blit(positionX, positionY, mnu_collision)
pad = Controls.read()
if pad:l() and pad:r() then
photo()
end
if pad:start() and oldpad:start() ~= pad:start() then
dofile("main.lua")
end
if pad:select() and oldpad:select() ~= pad:select() then
dofile("intro.lua")
break
end
screen.waitVblankStart()
screen:flip()
oldpad = pad 
end
img_background =  nil
mnu_collision =  nil
end

function savegame()
blanc = Color.new(255,255,255)
mes_sauvencours = Image.load("images/mes_sauvencours.png")
img_filigrane = Image.load("images/img_filigrane.png")
minuteursauv = Timer.new()
minuteursauv:start()
while true do
currentTime1 = minuteursauv:time()
if currentTime1 < 500 then
screen:clear()
ZoomIMG(img_voiture,axeX,axeY,0,vecteur)
screen:blit(positionX, positionY, img_background)
screen:blit(positionX, positionY, mnu_jeurecord)
screen:fontPrint(text2,338,92, ""..minutes..":"..secondes..":"..milisecondes,jaune)
screen:fontPrint(text2,320,68,name,orange)
screen:print(430,92, "v1.1",blanc)
screen:blit(positionX, positionY, mes_sauvencours)
screen:blit(positionX, positionY, img_filigrane)
end
if currentTime1 > 100 and currentTime1 < 600 then
file = io.open("savename.txt", "r")
name = file:read()
file:close()
file = io.open("sauvegarde/"..name..".txt", "w")
file:write(currentTime)
file:close()
end
if currentTime1 > 600 then
screen:save("screenshot/screen"..sccnt..".png")
sccnt=sccnt+1
frommenu=false
break
end
screen.waitVblankStart()
screen.flip()
end
img_filigrane =  nil
mes_sauvencours =  nil
end

function controletime()
file = io.open("savechrono.txt", "r")
name = file:read()
file:close()
end

function ZoomIMG(image,axeX,axeY,zoom,rotation) 
a_ = image:width()/10 
b_ = image:height()/10 
axeX = axeX - (480/2) 
axeY = axeY - (272/2) 
axeX = axeX + image:width()/2 
axeY = axeY + image:height()/2 
axeX = axeX/10 
axeY = axeY/10 
X_ = 0-axeX+ a_/2/10 
Y_ = 0-axeY+ b_/2/10 
Z_ = zoom + 50 
Rot = rotation + 180
Gu.start3d()
Gu.clearDepth(0) 
Gu.clear(Gu.COLOR_BUFFER_BIT+Gu.DEPTH_BUFFER_BIT)
Gum.matrixMode(Gu.PROJECTION) 
Gum.loadIdentity() 
Gum.perspective(30, 16/9, 3, 10000)
Gum.matrixMode(Gu.VIEW)        
Gum.loadIdentity()
Gum.lookAt(0,0,0,0,0,Z_,0,1,0) 
Gu.enable(Gu.TEXTURE_2D)
Gu.texImage(image)
Gu.texFunc(Gu.TFX_MODULATE, Gu.TCC_RGBA)
Gu.texEnvColor(Color.new(255,255,255))
Gu.texFilter(Gu.LINEAR, Gu.LINEAR)
Gu.texScale(1,0.8)
Gu.texOffset(0, 0)
Gu.ambientColor(Color.new(255,255,255)) 
Gum.matrixMode(Gu.MODEL) 
Gum.loadIdentity()
Gum.translate(X_ , Y_ , Z_);
Gum.rotateXYZ(0,0,math.rad(0-Rot)) 
Gum.drawArray(Gu.TRIANGLES, Gu.TEXTURE_32BITF+Gu.VERTEX_32BITF+Gu.TRANSFORM_3D, {{1,1,  a_/2,  b_/2, 0},{0,0,  -a_/2,  -b_/2,  0},{1,0, a_/2,  -b_/2,  0}, {0,0,  -a_/2,  -b_/2, 0},{1,1, a_/2,  b_/2, 0},{0,1, -a_/2,  b_/2, 0},})
Gu.end3d() 
end 

function savename()
file = io.open("savename.txt", "r+")
file:write(name)
file:close()
end

--img_background =  nil
mnu_photo = nil
mnu_jeuenpause =  nil
mnu_jeutermine =  nil
mnu_jeurecord =  nil
img_filigrane =  nil
mnu_collision =  nil
mes_sauvencours =  nil

