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

cutsceneload,message = loadfile("cutscene.lua")
if cutsceneload == 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

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

   
   backgroundCache = Image.load("backgrounds/title.png")
   cursor = Image.load("backgrounds/sbutton1.png") ------load cursor
   Music.playFile("music/ingmusic1.it", true)
   beep = Sound.load("music/beep.wav", false)
   
   selected = 1
   maxselected = 5 
   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
   beep:play()
   end

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


   if selected == 1 then
    screen:blit(165, 120, cursor)
end

   if selected == 2 then
   screen:blit(165, 145, cursor)
end


   if selected == 3 then
   screen:blit(168, 173, cursor)
end


   if selected == 4 then
   screen:blit(165, 203, cursor)
end


   if selected == 5 then
   screen:blit(165, 233, cursor)
end


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

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

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

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

if padmenu:cross() and oldpad:cross() ~= padmenu:cross() and selected == 5 then
returning = true
break
end

screen.flip()
oldpad = padmenu
end