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

--Anonymous D
-- 07/2007

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

--menu 1st selected (play game)
menu_play = Image.load("menu_play.jpg")

--menu with 2 selected ( instructions)
menu_instructions = Image.load("menu_instructions.jpg")

--menu with 3 selected (about)
menu_about = Image.load("menu_about.jpg")

--menu with 4 selected (scores)
menu_scores = Image.load("menu_scores.jpg")

--menu with 5 selected (exit)
menu_exit = Image.load("menu_exit.jpg")

--about menu screen
about = Image.load("about.jpg")

--instructions screen 
instructions = Image.load("instructions.jpg")

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

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

--menustatus
menustatus = "menu_play"


--***********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()

--********DRAWING TASKS**********
--draw in current picture for the menu
if menustatus == "menu_play" then
screen:blit(0,0,menu_play)
elseif menustatus == "menu_instructions" then
screen:blit(0,0,menu_instructions)
elseif menustatus == "menu_about" then
screen:blit(0,0,menu_about)
elseif menustatus == "menu_scores" then
screen:blit(0,0,menu_scores)
elseif menustatus == "menu_exit" then
screen:blit(0,0,menu_exit)
elseif menustatus == "about" then
screen:blit(0,0,about)
elseif menustatus == "instructions" then
screen:blit(0,0,instructions)
end

--******************************
--*menu status changes controls****
--******************************

--************************DOWN

--down when play is selected
if pad:down() and menustatus == "menu_play" then
menustatus = "menu_instructions"
--down when instructions is selected
elseif pad:down() and menustatus == "menu_instructions" then
menustatus = "menu_about"
--down when about is selected
elseif pad:down() and menustatus == "menu_about" then
menustatus = "menu_scores"
--down when scores is selected
elseif pad:down() and menustatus == "menu_scores" then
menustatus = "menu_exit"
elseif pad:down() and menustatus == "menu_exit" then
menustatus = "menu_play"
end

--*************************UP

--up when exit is selected
if pad:up() and menustatus == "menu_exit" then
menustatus = "menu_scores"
--up when scores is selected
elseif pad:up() and menustatus == "menu_scores" then
menustatus = "menu_about"
--up when about is selected
elseif pad:up() and menustatus == "menu_about" then
menustatus = "menu_instructions"
--up when instructions is selected
elseif pad:up() and menustatus == "menu_instructions" then
menustatus = "menu_play"
elseif pad:up() and menustatus == "menu_play" then
menustatus = "menu_exit"
end


---************************selecting menu items
--*******using x and going down the menu

--play game
if pad:cross() and menustatus == "menu_play" then
--unload images
--menu 1st selected (play game)
menu_play = nil

--menu with 2 selected ( instructions)
menu_instructions = nil

--menu with 3 selected (about)
menu_about = nil

--menu with 4 selected (scores)
menu_scores = nil

--menu with 5 selected (exit)
menu_exit = nil

--about menu screen
about = nil

--instructions screen 
instructions = nil

voice:stop()
menu_loop = nil

dofile("./game.lua")
break
end
--instructions
if pad:cross() and menustatus == "menu_instructions" then
menustatus = "instructions"
end
--about
if pad:cross() and menustatus == "menu_about" then
menustatus = "about"
end
--scores
if pad:cross() and menustatus == "menu_scores" then
--unload images
--menu 1st selected (play game)
menu_play = nil

--menu with 2 selected ( instructions)
menu_instructions = nil

--menu with 3 selected (about)
menu_about = nil

--menu with 4 selected (scores)
menu_scores = nil

--menu with 5 selected (exit)
menu_exit = nil

--about menu screen
about = nil

--instructions screen 
instructions = nil

--menu sound
voice:stop()
menu_loop = nil
dofile("./scores.lua")
break
end
--exit
if pad:cross() and menustatus == "menu_exit" then
voice:stop()
menu_loop = nil
break
end 

--**********exiting controls with triangle
--instructions
if pad:triangle() and menustatus == "instructions" then
menustatus = "menu_play"
end
--about
if pad:triangle() and menustatus == "about" then
menustatus = "menu_play"
end

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