--[[
Author: Will Graham (wgraham@digipen.edu)

Copyright 2008-2009 DigiPen (USA) Corp.
]]--

--print("Gameplay_Focus.lua: Gameplay in focus...")


LevelTitleTopTime = 120
TitleAlpha = 200
if GameEngine.FirstRun == true then
	if GameEngine.CurrentLevelNum_ + 1 < 5 then
		LevelTitle = true
		LevelTitleState = 0
		CurrentTitle = LevelTitles[GameEngine.CurrentLevelNum_ + 1];
		for i = 1, 4 do
			LevelTitles[i]:SetA(0)
			LevelTitles[i]:SetActive(false)
		end
		CurrentTitle:SetA(0)
		CurrentTitle:SetActive(true)
	end
end

time = 0
function Update(t)
	backgroundSpeed = 6.0 * t / fps;
	barSpeed = 5.0 * t / fps;
	time = time + 1
	if GameEngine.GameOver == false then
		if time > 10 then
			ColorTowards2(FadeBackground, 0, 0, 0, 0, backgroundSpeed)
			if FadeBackground.A == 0 then
				FadeBackground:SetActive(false)
			end
			if LevelTitle == true then
				if LevelTitleState == 0 then
					ColorTowards2(CurrentTitle, CurrentTitle.R, CurrentTitle.G, CurrentTitle.B, TitleAlpha, backgroundSpeed)
					if CurrentTitle.A == TitleAlpha then
						LevelTitleState = 1
						LevelTitleTopStart = Timer:GetFrameCount()
					end
				elseif LevelTitleState == 1 then
					LevelTitleTopTimeEllapsed = Timer:GetFrameCount() - LevelTitleTopStart
					if LevelTitleTopTimeEllapsed > LevelTitleTopTime then
						LevelTitleState = 2
					end
				else
					ColorTowards2(CurrentTitle, CurrentTitle.R, CurrentTitle.G, CurrentTitle.B, 0, backgroundSpeed)
					if CurrentTitle.A == 0 then
						LevelTitle = false
						CurrentTitle:SetActive(false)
					end
				end
			end
			ColorTowards2(LoadingScreen, 255, 255, 255, 0, backgroundSpeed)
			if LoadingScreen.A == 0 then
				LoadingScreen:SetActive(false)
			end
		end
	else
		if FadeBackground.Active == false then
			FadeBackground:SetActive(true)
		end
		if FadeBackground.A == 255 then
			if GameEngine.Credits == true then
				GameEngine:ChangeState("Credits")
				time = 0
			else
				GameEngine:ChangeState("Gameplay")
				time = 0
			end
		end
		
		ColorTowards(FadeBackground, 0, 0, 0, 255, backgroundSpeed)
		ColorTowards(LevelTitles[1], LevelTitles[1].R, LevelTitles[1].G, LevelTitles[1].B, 0, backgroundSpeed)
		ColorTowards(LevelTitles[2], LevelTitles[2].R, LevelTitles[2].G, LevelTitles[2].B, 0, backgroundSpeed)
		ColorTowards(LevelTitles[3], LevelTitles[3].R, LevelTitles[3].G, LevelTitles[3].B, 0, backgroundSpeed)
		ColorTowards(LevelTitles[4], LevelTitles[4].R, LevelTitles[4].G, LevelTitles[4].B, 0, backgroundSpeed)
		
		LoadingScreen:SetActive(true)
		ColorTowards(LoadingScreen, 255, 255, 255, 255, backgroundSpeed)
	end
	
	if PlayerData.Locked_ == true then
		CinematicBar1:SetActive(true)
		CinematicBar2:SetActive(true)
		MoveTowards(CinematicBar1, 0, 0, 0, barSpeed);
		MoveTowards(CinematicBar2, 0, ScreenHeight - BarHeight, 0, barSpeed);
	else
		MoveTowards(CinematicBar1, 0, -BarHeight, 0, barSpeed);
		MoveTowards(CinematicBar2, 0, ScreenHeight, 0, barSpeed);
		if CinematicBar1.Y == -BarHeight then
			CinematicBar1:SetActive(false)
			CinematicBar2:SetActive(false)
		end
	end
end