---- Beat Quest v1.0 Beta, Coded by Zion. 05/11/06

credits = nil
gameload = nil
collectgarbage()

Menu,message = loadfile("menu.lua")
if Menu == 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()
end

Level3,message = loadfile("level3.lua")
if Level3 == 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()
end

status = "Game"

------------**Load Colors**-----

	blue = Color.new(0 , 153, 255)
	black = Color.new(255,255,255)
	orange = Color.new(255, 102, 0)

---------**backgrounds**-----

	backgroundCache = Image.load("backgrounds/Level2.png")
	
---------**Arrow Correct Images**-----------

	ArrowCorrect = Image.load("images/ArrowCorrect.png")
 
--------Buttons---------

	LeftArrow = Image.load("images/LeftArrow.png")
	RightArrow = Image.load("images/RightArrow.png")
	DownArrow = Image.load("images/DownArrow.png")
	UpArrow = Image.load("images/UpArrow.png")

------Animated Characters/Dancers----------

	AnimatedGuy1 = Image.load("images/LeftDance.png")
	AnimatedGuy2 = Image.load("images/RightDance.png")
	AnimatedGuy3 = Image.load("images/UpDance.png")
	AnimatedGuy4 = Image.load("images/DownDance.png")

-------Floor Lights----

	Floor1 = Image.load("images/floor1.png")
	Floor2 = Image.load("images/floor2.png")
	Floor3 = Image.load("images/floor3.png")

------**Player Values**-------

	Player = {}
	Player.x = 230
	Player.y = 200
	Player.img = AnimatedGuy1
	
--------**Buttons Values**------

	Button = {}
	Button.x = 220
	Button.y = 40
	Button.img = LeftArrow
	
-------**Floor Values**---------

	Floor = {}
	Floor.x = 122
	Floor.y = 120
	Floor.img = Floor1
    
---------**timer values**--------
    
    Timer = 0
	ObjectTimer = 0
	GameTimer = 0
	FloorTimer = 0
	
-------**Score**-----

	Score = 0
	
	ScoreCounter1 = {1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60}

-------------**Timer values**--------
   
function MoveDancer()   ------Move Animated Dancer
Timer = Timer + 1
     
 	if Timer>= 55 or Timer<=0  then
    Timer = 0
  	end         
			                 
        if Timer==5 then
        Player.img = AnimatedGuy1
        end
        
        if Timer==17 then
        Player.img = AnimatedGuy2
        end
        
		if Timer==32 then
		Player.img = AnimatedGuy3
		end
		
		if Timer==47 then
		Player.img = AnimatedGuy4
		end
 end
 
 function MoveFloor()   ------Move floor lights
FloorTimer = FloorTimer + 1
     
 	if FloorTimer>= 60 or FloorTimer<=0  then
    FloorTimer = 0
  	end         
			                 
        if FloorTimer==5 then
        Floor.img = Floor1
        end
        
        if FloorTimer==30 then
        Floor.img = Floor2
        end
        
		if FloorTimer==55 then
		Floor.img = Floor3
		end
 end

function  ButtonInit()   ------Left Animation
  ObjectTimer = ObjectTimer + 1

	if ObjectTimer>= 380 or ObjectTimer<=0 then
	    ObjectTimer = 0
	    end
	           	            			    
		if ObjectTimer==5 then
		Button.img = LeftArrow 
		LeftArrow1 = false
		end
		
		if ObjectTimer==40 then
		Button.img = UpArrow
		UpArrow1 = false
		end
		
		if ObjectTimer==75 then
		Button.img = DownArrow
		DownArrow1 = false
		end
		
		if ObjectTimer==105 then
		Button.img = RightArrow
		RightArrow1 = false
		end
		
		if ObjectTimer==140 then
		Button.img = DownArrow
		DownArrow2 = false
		end
		
		if ObjectTimer==175 then
		Button.img = RightArrow
		RightArrow2 = false
		end
		
		if ObjectTimer==205 then
		Button.img = UpArrow
		UpArrow2 = false
		end
		
		if ObjectTimer==240 then
		Button.img = LeftArrow
		LeftArrow2 = false
		end
		
		if ObjectTimer==275 then
		Button.img = RightArrow 
		RightArrow3 = false
		end
		
		if ObjectTimer==305 then
		Button.img = DownArrow
		DownArrow3 = false
		end
		
		if ObjectTimer==340 then
		Button.img = UpArrow
		UpArrow3 = false
		end
		
		if ObjectTimer==375 then
		Button.img = LeftArrow
		LeftArrow3 = false
	end
end

function ButtonPress()

	if Button.img == LeftArrow and LeftArrow1 == false and pad:left() and ScoreCounter1[14] then
	LeftaArrow1 = true
	ScoreCounter1[14] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
	if Button.img == LeftArrow and LeftArrow2 == false and pad:left() and ScoreCounter1[15] then
	LeftArrow2 = true
	ScoreCounter1[15] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
	if Button.img == LeftArrow and LeftArrow3 == false and pad:left() and ScoreCounter1[16] then
	leftArrow3 = true
	ScoreCounter1[16] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
	if Button.img == UpArrow and UpArrow1 == false and pad:up() and ScoreCounter1[17] then
	UpArrow1 = true
	ScoreCounter1[17] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
	if Button.img == UpArrow and UpArrow2 == false and pad:up() and ScoreCounter1[18] then
	UpArrow2 = true
	ScoreCounter1[18] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
	if Button.img == UpArrow and UpArrow3 == false and pad:up() and ScoreCounter1[19] then
	UpArrow3 = true
	ScoreCounter1[19] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
	if Button.img == DownArrow and DownArrow1 == false and pad:down() and ScoreCounter1[20] then
	DownArrow1 = true
	ScoreCounter1[20] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
	if Button.img == DownArrow and DownArrow2 == false and pad:down() and ScoreCounter1[21] then
	DownArrow2 = true
	ScoreCounter1[21] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
	if Button.img == DownArrow and DownArrow3 == false and pad:down() and ScoreCounter1[22] then
	DownArrow3 = true
	ScoreCounter1[22] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
	if Button.img == RightArrow and RightArrow1 == false and pad:right() and ScoreCounter1[23] then
	RightArrow1 = true
	ScoreCounter1[23] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end

	if Button.img == RightArrow and RightArrow2 == false and pad:right() and ScoreCounter1[24] then
	RightArrow2 = true
	ScoreCounter1[24] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
	if Button.img == RightArrow and RightArrow3 == false and pad:right() and ScoreCounter1[25] then
	RightArrow3 = true
	ScoreCounter1[25] = false
	Score = Score + 5
	screen:blit(190, 30, ArrowCorrect)
	screen.flip()
	screen.waitVblankStart(10)
	end
	
end

function GameTime()   ------Move Animated Dancer
GameTimer = GameTimer + 1
     
 	if GameTimer>= 385 or GameTimer<=0  then
    GameTimer = 0
  	end         
			                 
        if GameTimer>=375 and Score<=50 then
        Menu()
       
        elseif GameTimer>=375 and Score>=50 then
	screen:blit(0, 0, loading)
	screen.flip()
	screen.waitVblankStart(100)
		Level3()
        end
  end

--------**Start Main Game Loop**-----

     while true do
	 	 
-------**Init Functions**------

ButtonInit() ---Blit Different Buttons On screen At Timed Intervals
MoveDancer() -----Makes The Character Dance
GameTime() -------- Makes the game stop at the end of the level

	
---------**Init Gamepad**-------

	pad = Controls.read()
	
------------**Other**--------

 	if pad:select() then screen:save("screenshot.png") end  ----Take Screenshot 
	                        
-------**Blit Images To Screen**------

	screen:blit(0, 0, backgroundCache)
	screen:blit(Floor.x, Floor.y, Floor.img)
 	screen:blit(Player.x, Player.y, Player.img) 
	screen:blit(Button.x, Button.y, Button.img)
   	screen.flip()
	screen.waitVblankStart() 
	
	MoveFloor()   ------Move floor lights
	ButtonPress() ------Adds to the score if button is pressed at correct time

end
