TitleScene = Object.extend(Object)

function TitleScene:new()
end

function TitleScene:init()
	logoWidth = gameLogo:getWidth()
	logoHeight = gameLogo:getHeight()

	progressDelta = 0
	progressTarget = 0.5
	percentage = 0

	introSound:play()

	state = "in"

	pSystem = love.graphics.newParticleSystem(titleParticle,128)
	pSystem:setParticleLifetime(0,0.8)
	pSystem:setLinearAcceleration(-6,20,6,25)
	pSystem:setSpeed(40,50)
	pSystem:setRotation(10,20)
	pSystem:setSpin(10,20)
	pSystem:setRadialAcceleration(5,20)
	pSystem:setTangentialAcceleration(10,20)
	pSystem:setSizeVariation(0.5)
	pSystem:setSizes(1,0.9,0.9,0.8,0.6,0.5,0.3,0.1)
	pSystem:setColors(
		1,1,1,0.8,
		1,1,1,0.8,
		1,1,1,0.8,
		1,1,1,0.7,
		1,1,1,0.5,
		1,1,1,0.3,
		1,1,1,0.2,
		1,1,1,0.1
	)
	pSystem:setDirection(315*(math.pi/180))

end

function TitleScene:update(dt)
	pSystem:update(dt)

	if progressDelta < progressTarget then
		progressDelta = math.min( progressTarget, progressDelta + dt )
	end

	percentage = (progressDelta/progressTarget)

	if state == "wait" then
		pSystem:emit( 32 )
	end

	if state == "in" and progressDelta == progressTarget then
		state = "wait"
		progressDelta = 0
		progressTarget = 3
		percentage = 0
	end

	if state == "wait" and progressDelta == progressTarget then
		state = "out"
		progressDelta = 0
		progressTarget = 0.5
		percentage = 0
	end

	if state == "out" and progressDelta == progressTarget then
		state = "complete"
	end

	if state == "complete" then
		pSystem:stop()
		pSystem = nil
		currentScene = GameScene
		currentScene:init()
	end
end

function TitleScene:draw()
	if state == "in" then
		logoAlpha = percentage
		logoYpos = ( (windowHeight - logoHeight) / 2 ) + ( 10 * (1-percentage) )
	elseif state == "wait" then
		logoAlpha = 1
		logoYpos = ( (windowHeight - logoHeight) / 2 )
	elseif state == "out" then
		logoAlpha = 1 - percentage
		logoYpos = ( (windowHeight - logoHeight) / 2 ) - ( 20 * (percentage) )
	end

	love.graphics.setColor(255,255,255, logoAlpha)

	if pSystem ~= nil then
		love.graphics.draw(pSystem, ((windowWidth - logoWidth) / 2) + 300, logoYpos + 8)
	end

	love.graphics.draw(gameLogo, (windowWidth - logoWidth) / 2, logoYpos )

end

function TitleScene:drawHud()
end

function TitleScene:keypressed(key,unicode)
end
