menuload = nil
menuload2 = nil
menuload3 = nil
cutsceneload = nil
gameover = nil
gameload = nil
collectgarbage()

credits,message = loadfile("credits.lua")
if credits == nil then
screen:clear()
screen:print(0,0,"LOAD FAILED",Color.new(255,0,0))
screen:print(0,10,message,Color.new(255,255,255))
screen.flip()
while true do
screen.waitVblankStart()
end
end

gameload,message = loadfile("game.lua")
if gameload == nil then
screen:clear()
screen:print(0,0,"LOAD FAILED",Color.new(255,0,0))
screen:print(0,10,message,Color.new(255,255,255))
screen.flip()
while true do
screen.waitVblankStart()
end
end

status = "menu"
   
   backgroundCache = Image.load("backgrounds/title.png")
   cursor = Image.load("backgrounds/selector.png") ------load cursor
   
   Mp3.load("music/menu.mp3")
   if status == "menu" then
   Mp3.play()
   end
   
   selected = 1
   maxselected = 2 
   oldpad = Controls.read() 

while true do

   if selected > maxselected then
   selected = 1
   elseif selected <= 0 then
   selected = maxselected
   end

   padmenu = Controls.read()

   screen.waitVblankStart(6)

   screen:blit(0, 0, backgroundCache, false)

   if padmenu:up() and oldpad:up() ~= padmenu:up() then
   selected = selected - 1
   end

   if padmenu:down() and oldpad:down() ~= padmenu:down() then
   selected = selected + 1
   end


   if selected == 1 then
    screen:blit(173, 136, cursor)
end

   if selected == 2 then
   screen:blit(173, 170, cursor)
end

if padmenu:cross() and oldpad:cross() ~= padmenu:cross() and selected == 1 then
gameload()
end

if padmenu:cross() and oldpad:cross() ~= padmenu:cross() and selected == 2 then
credits()
end

screen.flip()
oldpad = padmenu
end