--------------------------------------------------------------------
-- e_start.lua
-- ゲーム開始時演出
--
-- author IZUMI STUDIO
-- date 
--------------------------------------------------------------------
require(".\\scripts\\common")

PROJ_FOV        = 3.1415 * 25.0 / 180.0
PROJ_RADIUS     = 40.0 / math.cos( PROJ_FOV / 2.0 )
PROJ_HALF_WIDTH = PROJ_RADIUS * math.sin( PROJ_FOV / 2.0 )
s = 1.0 / 400.0 * 1.333 * PROJ_HALF_WIDTH

BACK_R = 13
BACK_G = 105
BACK_B = 187
BACK_MAX = 2.0

FLASH_R = 255
FLASH_G = 255
FLASH_B = 255
FLASH_MAX = 4.0


function createElement_Ring( delay, endFrame, x, y, _scale )
	
	local mover = Effect.CreateAnimator_Still(
		x, y, 0.0,
		x, y, 0.0 )
	
	local rotator = Effect.CreateAnimator_Still(
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	Effect.CreateElement_Ring(
		255,255,255,255,
		255,0,0,0,
		255,255,255,255,
		255,0,0,0,
		255,255,255,255,
		255,0,0,0,
		INTERPOLATION_LINEAR,
		0.0, _scale,
		INTERPOLATION_LINEAR,
		0.1, 0.1,
		INTERPOLATION_LINEAR,
		34,
		255,
		0.5,
		EFFECT_BLEND_ADD,
		EFFECT_BILLBOARD_NORMAL,
		delay, endFrame, 1,
		mover, rotator )
	
end


function createElement_Back_In( delay, endFrame, x, y, spdY )
	
	local mover = Effect.CreateAnimator_Dynamics(
		x, y, 0.0,
		0.0, 0.0, 0.0,
		0.0, spdY, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	local rotator = Effect.CreateAnimator_Still(
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	Effect.CreateElement_Circle(
		0,BACK_R,BACK_G,BACK_B,
		255,BACK_R,BACK_G,BACK_B,
		0,BACK_R,BACK_G,BACK_B,
		0,BACK_R,BACK_G,BACK_B,
		BACK_MAX, BACK_MAX,
		INTERPOLATION_EASE_OUT,
		EFFECT_BLEND_NORMAL,
		EFFECT_BILLBOARD_NORMAL,
		delay, endFrame, 1,
		mover, rotator )
end

function createElement_Back( delay, endFrame, x, y, spdY )
	
	local mover = Effect.CreateAnimator_Dynamics(
		x, y, 0.0,
		0.0, 0.0, 0.0,
		0.0, spdY, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	local rotator = Effect.CreateAnimator_Still(
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	Effect.CreateElement_Circle(
		255,BACK_R,BACK_G,BACK_B,
		255,BACK_R,BACK_G,BACK_B,
		0,BACK_R,BACK_G,BACK_B,
		0,BACK_R,BACK_G,BACK_B,
		BACK_MAX, BACK_MAX,
		INTERPOLATION_EASE_OUT,
		EFFECT_BLEND_NORMAL,
		EFFECT_BILLBOARD_NORMAL,
		delay, endFrame, 1,
		mover, rotator )
end

function createElement_Back_Out( delay, endFrame, x, y, spdY )
	
	local mover = Effect.CreateAnimator_Dynamics(
		x, y, 0.0,
		0.0, 0.0, 0.0,
		0.0, spdY, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	local rotator = Effect.CreateAnimator_Still(
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	Effect.CreateElement_Circle(
		255,BACK_R,BACK_G,BACK_B,
		0,BACK_R,BACK_G,BACK_B,
		0,BACK_R,BACK_G,BACK_B,
		0,BACK_R,BACK_G,BACK_B,
		BACK_MAX, BACK_MAX,
		INTERPOLATION_EASE_OUT,
		EFFECT_BLEND_NORMAL,
		EFFECT_BILLBOARD_NORMAL,
		delay, endFrame, 1,
		mover, rotator )
end


function createElement_GameStart_In( delay, endFrame, x, y )
	
	local mover = Effect.CreateAnimator_Dynamics(
		x, y, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	local rotator = Effect.CreateAnimator_Still(
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	Effect.CreateElement_Model(
		"game_start",
		s*0.5, s, INTERPOLATION_EASE_OUT,
		0.0, 1.0, INTERPOLATION_LINEAR,
		EFFECT_BLEND_NORMAL, 
		delay, endFrame, 1,
		0,
		mover,
		rotator )
end

function createElement_GameStart( delay, endFrame, x, y )
	
	local mover = Effect.CreateAnimator_Dynamics(
		x, y, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	local rotator = Effect.CreateAnimator_Still(
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	Effect.CreateElement_Model(
		"game_start",
		s, s*1.08, INTERPOLATION_EASE_OUT2,
		1.0, 1.0, INTERPOLATION_LINEAR,
		EFFECT_BLEND_NORMAL, 
		delay, endFrame, 1,
		0,
		mover,
		rotator )
end

function createElement_GameStart_Out( delay, endFrame, x, y )
	
	local mover = Effect.CreateAnimator_Dynamics(
		x, y, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	local rotator = Effect.CreateAnimator_Still(
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	Effect.CreateElement_Model(
		"game_start",
		s*1.08, s*2.0, INTERPOLATION_EASE_IN,
		1.0, 0.0, INTERPOLATION_EASE_IN,
		EFFECT_BLEND_NORMAL, 
		delay, endFrame, 1,
		0,
		mover,
		rotator )
end



function createElement_Flash_In( delay, endFrame, x, y, spdY )
	
	local mover = Effect.CreateAnimator_Dynamics(
		x, y, 0.0,
		0.0, 0.0, 0.0,
		0.0, spdY, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	local rotator = Effect.CreateAnimator_Still(
		0.0, 0.0, 0.0,
		0.0, 0.0, 0.0 )
	
	Effect.CreateElement_Circle(
		32,FLASH_R,FLASH_G,FLASH_B,
		0,FLASH_R,FLASH_G,FLASH_B,
		0,FLASH_R,FLASH_G,FLASH_B,
		0,FLASH_R,FLASH_G,FLASH_B,
		FLASH_MAX, FLASH_MAX,
		INTERPOLATION_LINEAR,
		EFFECT_BLEND_ADD,
		EFFECT_BILLBOARD_NORMAL,
		delay, endFrame, 1,
		mover, rotator )
end



frames_0 = 68
frames_1 = 5
frames_2 = 35
frames_3 = 10


for idx = 1, 5 do
	x = math.random() * 20.0 - 10.0
	y = math.random() * 20.0 - 10.0
	scale = math.random() * 8.5 + 0.5
	endFrame = 4 * scale
	endFrame = 30
end



w = 520.0 / 400.0 * 1.333 * PROJ_HALF_WIDTH
sw = - w / 2.0

for idx = 0, 9 do
	createElement_Back_In( frames_0, frames_1, sw + w*idx/9.0, 0.0, 0.0 )
end
for idx = 0, 9 do
	createElement_Back( frames_0+frames_1, frames_2, sw + w*idx/9.0, 0.0, 0.0 )
end
for idx = 0, 9 do
	createElement_Back_Out( frames_0+frames_1+frames_2, frames_3, sw + w*idx/9.0, 0.0, 0.0 )
end


createElement_GameStart_In( frames_0, frames_1, 0.0, 0.0 )
createElement_GameStart( frames_0+frames_1, frames_2, 0.0, 0.0 )
createElement_GameStart_Out( frames_0+frames_1+frames_2, frames_3, 0.0, 0.0 )


w = 520.0 / 400.0 * 1.333 * PROJ_HALF_WIDTH
sw = - w / 2.0



