-- Christmas Run --
-- by PSPfreak.de DEV Team --

-- MENU --

Select = 1
maxSelect = 4
gamestate = "Menu"
IntroFrame = 1

-- ##### Loading Sprites ##### --


blue = Color.new (72, 61, 139)
white = Color.new (139, 0, 0)
t1 = os.time()
x = 0
xj = - 480
a = 0
y = 0
dt = 0
zeit = 0
blut = 0
anleitungein = 1
aus = 0


-- ##### Load Background #####

bbr = Image.load("gamespic/BBR.png")
BG = Image.load("gamespic/BG.png")
Crash = Image.load("gamespic/Crash.png")
Lowser = Image.load("gamespic/Lowser.png")
MenuSelect = Image.load("gamespic/MenuSelection.png")
Quit = Image.load("gamespic/Quit.png")

-- ##### KillImg #####
function KillImg()
blue = nil
white = nil
t1 = nil
x = nil
xj = nil
a = nil
y = nil
dt = nil
zeit = nil
blut = nil
anleitungein = nil
aus = nil
Select = nil
gamestate = nil
IntroFrame = nil
BG = nil
Bermuda = nil
Lowser = nil
MenuSelect = nil
Quit = nil
collectgarbage()
end


-- ##### Main Loop #####
gamestate = "Menu"
oldpad = Controls.read()
while true do
pad = Controls.read()
screen:clear()

     screen:blit(0, 0, BG)

     if pad:down() and oldpad:down() ~= pad:down() and Select <= 3 then
          Select = Select + 1
     end
     if pad:up() and oldpad:up() ~= pad:up() and Select >= 1 then
          Select = Select - 1
     end
	if Select > maxSelect then
		Select = 1
	elseif Select <= 0 then
		Select = maxSelect
	end

     if Select == 1 then
          screen:blit(90,70,Crash)
          screen:blit(90,115,Lowser)
          screen:blit(90,160,bbr)
          screen:blit(90,205,Quit)
          screen:blit(350,71,MenuSelect)
     end
     if Select == 2 then
          screen:blit(90,70,Crash)
          screen:blit(90,115,Lowser)
          screen:blit(90,160,bbr)
          screen:blit(90,205,Quit)
          screen:blit(350,116,MenuSelect)
     end
     if Select == 3 then
          screen:blit(90,70,Crash)
          screen:blit(90,115,Lowser)
          screen:blit(90,160,bbr)
          screen:blit(90,205,Quit)
          screen:blit(350,161,MenuSelect)
     end
     if Select == 4 then
          screen:blit(90,70,Crash)
          screen:blit(90,115,Lowser)
          screen:blit(90,160,bbr)
          screen:blit(90,205,Quit)
          screen:blit(350,206,MenuSelect)
     end
     if Select == 1 and pad:cross() and oldpad:cross() ~= pad:cross() then          
         KillImg()
         dofile("Games/CrashCar/script.lua")
     end

     if Select == 2 and pad:cross() and oldpad:cross() ~= pad:cross() then
         KillImg()
         dofile("Games/FallBall/script.lua")
     end

     if Select == 3 and pad:cross() and oldpad:cross() ~= pad:cross() then
         KillImg()
         dofile("Games/BBR/script.lua")
     end

     if Select == 4 and pad:cross() and oldpad:cross() ~= pad:cross() then
          KillImg()
          dofile("main.lua")
     end

screen.waitVblankStart()
screen.flip()
oldpad = pad
end