
let bSpell = false;
let current = GetCurrentScriptDirectory();

@Initialize
{
	SetAutoDeleteObject(true);
	SetCameraFocusX(0);
	SetCameraFocusY(30);
	SetCameraFocusZ(-100);
	SetCameraRadius(300);
	SetCameraElevationAngle(5);
	SetCameraAzimuthAngle(90);

	SetFogParam(0, 1000, 32, 32, 32);

	TBackground;
}

@MainLoop
{

	let objScene = GetEnemyBossSceneObjectID();
	if(objScene != ID_INVALID && ObjEnemyBossScene_GetInfo(objScene, INFO_IS_SPELL))
		{
		bSpell = true;
		}
	else
		{
		bSpell = false;
		}
	

	yield;
}

task TBackground
{
	let spellA = 0;

	let count = 2;

	let obj = [];
	ascent(i in 0..count)
		{
		obj = obj ~ [ObjPrim_Create(OBJ_SPRITE_2D)];
		ObjPrim_SetTexture(obj[i],GetCurrentScriptDirectory ~ "img/Back_SpellM.png");
		ObjSprite2D_SetSourceRect(obj[i],0,0,128,128);
		ObjRender_SetPosition(obj[i],GetStgFrameWidth/2,GetStgFrameHeight/2,0);
		ObjRender_SetScaleXYZ(obj[i],GetStgFrameHeight/127,GetStgFrameWidth/127,0);
		ObjRender_SetAngleZ(obj[i],90);
		Obj_SetRenderPriority(obj[i],0.24+i*0.02);
		ObjSprite2D_SetDestCenter(obj[i]);
		}
	ObjRender_SetColorHSV(obj[0],0,0,120);
	ObjRender_SetColorHSV(obj[1],0,0,175);

	let enemy = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(enemy,GetCurrentScriptDirectory ~ "img/Face/Tewi.png");
	ObjSprite2D_SetSourceRect(enemy,0,0,172,357);
	ObjRender_SetPosition(enemy,GetStgFrameWidth/2,GetStgFrameHeight/2+5,0);
	ObjRender_SetScaleXYZ(enemy,1.125,1.125,0);
	Obj_SetRenderPriority(enemy,0.25);
	ObjRender_SetColorHSV(enemy,0,0,0);
	ObjSprite2D_SetDestCenter(enemy);

	let anim = 0;
	let alpha = 0;
	let alphaA = 45;
	loop
		{
		if(bSpell == false)	
			{
			spellA = 0;
			}
		else if(spellA < 1)
			{
			spellA += 1/20;
			}
		anim+=1;
		alpha = 215*cos(alphaA);
		ascent(i in 0..2)
			{
			let dist = (i*2-1)*(i+1)*0.25*anim;
			ObjSprite2D_SetSourceRect(obj[i],0,dist,128,128+dist);
			}
		ObjRender_SetAlpha(obj[0],190*spellA);
		ObjRender_SetAlpha(obj[1],alpha*spellA);
		ObjRender_SetAlpha(enemy,255*spellA);
		yield;
		}
		
}