--**************************************************************
--**********CONSOLE GRAB MENU index.lua***********************
--**************************************************************

--Anonymous D
-- 07/2007

--*****load materials***********
--****************************

--BACKGROUND
bck = Image.load("./gfx/menubackground.png")


--************SOUNDS
--menu loop
menu_loop = Sound.load("./sfx/menu_loop.wav",true)

---********************
---**** variables *****
---********************

--menustatus
menustatus = 1 -- can be 1 to 4
gamestate = "normal"
playgamethingy = 0

--***********define colours
red = Color.new(255, 0, 0)
green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)
pink = Color.new(180, 0, 180)
white = Color.new(255, 255, 255)

--****************************************************
--*******MAIN MENU LOOP****************************
--****************************************************

local sound = menu_loop
voice = sound:play()

while true do

--read pad input
pad = Controls.read()

-- clear screen
screen:clear()

--draw in background
screen:blit(0,0,bck)

--print menu
if menustatus == 1 then 
screen:print(150,80,"Play Game:" .. gamestate,white)
screen:print(150,90,"Scores",green)
screen:print(150,100,"Controls",green) 
screen:print(150,110,"Exit",green)
elseif menustatus == 2 then
screen:print(150,80,"Play Game:" .. gamestate,green)
screen:print(150,90,"Scores",white)
screen:print(150,100,"Controls",green) 
screen:print(150,110,"Exit",green)
elseif menustatus == 3 then
screen:print(150,80,"Play Game:" .. gamestate,green)
screen:print(150,90,"Scores",green)
screen:print(150,100,"Controls",white) 
screen:print(150,110,"Exit",green)
elseif menustatus == 4 then
screen:print(150,80,"Play Game:" .. gamestate,green)
screen:print(150,90,"Scores",green)
screen:print(150,100,"Controls",green) 
screen:print(150,110,"Exit",white)
end

--change game type

--left
if menustatus == 1 and pad:left() and gamestate == "normal" then 
gamestate = "time Attack"
elseif menustatus == 1 and pad:left() and gamestate == "time Attack" then
gamestate = "sony" 
elseif menustatus == 1 and pad:left() and gamestate == "sony" then
gamestate = "microsoft"
elseif menustatus == 1 and pad:left() and gamestate == "microsoft" then
gamestate = "nintendo"
elseif menustatus == 1 and pad:left() and gamestate == "nintendo" then
gamestate = "avoidance"
elseif menustatus == 1 and pad:left() and gamestate == "avoidance" then
gamestate = "dualhand" 
elseif menustatus == 1 and pad:left() and gamestate == "dualhand" then
gamestate = "normal" 
end
--right
if menustatus == 1 and pad:right() and gamestate == "normal" then
gamestate = "dualhand" 
 elseif menustatus == 1 and pad:right() and gamestate == "dualhand" then
gamestate = "avoidance"    
elseif menustatus == 1 and pad:right() and gamestate == "avoidance" then
gamestate = "nintendo" 
elseif menustatus == 1 and pad:right() and gamestate == "nintendo" then
gamestate = "microsoft" 
elseif menustatus == 1 and pad:right() and gamestate == "microsoft" then
gamestate = "sony" 
elseif menustatus == 1 and pad:right() and gamestate == "sony" then
gamestate = "time Attack"
elseif menustatus == 1 and pad:right() and gamestate == "time Attack" then
gamestate = "normal"
end

--change menustatus
if pad:down() and menustatus <4 then
menustatus = menustatus + 1
elseif pad:down() and menustatus == 4 then
menustatus = 1
end
if pad:up() and menustatus >1 then
menustatus = menustatus - 1
elseif pad:up() and menustatus == 1 then
menustatus = 4
end


--select stuff
--play game
if pad:cross() and menustatus == 1  and gamestate == "normal" then
bck = nil
voice:stop()
menu_loop = nil
dofile("./game.lua")
break
end
if pad:cross() and menustatus == 1 and gamestate == "time Attack" then
bck = nil
voice:stop()
menu_loop = nil
dofile("./timeattack.lua")
break
end
if pad:cross() and menustatus == 1 and gamestate == "sony" then
bck = nil
voice:stop()
menu_loop = nil
dofile("./sony.lua")
break
end
if pad:cross() and menustatus == 1 and gamestate == "microsoft" then
bck = nil
voice:stop()
menu_loop = nil
dofile("./microsoft.lua")
break
end
if pad:cross() and menustatus == 1 and gamestate == "nintendo" then 
bck = nil
voice:stop()
menu_loop = nil
dofile("./nintendo.lua")
break
end
if pad:cross() and menustatus == 1 and gamestate == "avoidance" then
bck = nil
voice:stop()
menu_loop = nil
dofile("./avoidance.lua")
break
end
if pad:cross() and menustatus == 1  and gamestate == "dualhand" then
bck = nil
voice:stop()
menu_loop = nil
dofile("./dualhand.lua")
break
end

--scores 
if pad:cross() and menustatus == 2 then
bck = nil
voice:stop()
menu_loop = nil
dofile("./scores.lua")
break
end

-- controls 
if pad:cross() and menustatus == 3 then
bck = nil
voice:stop()
menu_loop = nil
dofile("./controls.lua")
break
end

--exit
if pad:cross() and menustatus == 4 then
bck = nil
voice:stop()
menu_loop = nil
break
end

--ending scripts
screen.waitVblankStart()
screen.flip()
end
