let objScene = GetEnemyBossSceneObjectID;
let OnSpell = false;
let CSD = GetCurrentScriptDirectory;

@Initialize
{
	SpellBG;
	BGControl;
}

@MainLoop
{
	OnSpell = (GetEnemyBossSceneObjectID != ID_INVALID && ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_IS_SPELL));
	yield; 
}

task BGControl
{
	Background;
}

task Background
{
	let alpha =255;
	let alpha2 = 0;
	let m =0;
	let x =0;
	let y=0;

	let bg = ObjPrim_Create(OBJ_SPRITE_2D);    
	ObjPrim_SetTexture(bg, GetCurrentScriptDirectory~"./StageBack.png");
	ObjSprite2D_SetSourceRect(bg,0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(bg);
	ObjRender_SetPosition(bg, GetStgFrameWidth/3, GetStgFrameHeight/2, 0);
	ObjRender_SetScaleXYZ(bg,2,2,0);
	Obj_SetRenderPriorityI(bg,20);

	loop
	{
		m+=0.7;
		ObjRender_SetAngleXYZ(bg,70,30+sin(m)*10,70);
		ObjSprite2D_SetSourceRect(bg,0-x, 0-y, 256*10-x, 256*10-y);
		ObjSprite2D_SetDestCenter(bg);
		x+=1.5;
		y+=1.5;
		yield;
	}
}




task SpellBG
{
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj1, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj1, 23);
	ObjPrim_SetTexture(obj1, GetCurrentScriptDirectory~"./SpellBack.png");
	ObjRender_SetScaleXYZ(obj1, 2, 2, 2);
	ObjSprite2D_SetSourceRect(obj1, 0, 0, 256, 256);
	ObjSprite2D_SetDestRect(obj1, -256, -256, 256, 256);

	let ang = 0;
	let ang2 = 0;
	let ang3 = rand(0,360);
	let x = 0;
	let y = 0;
	let alpha = 0;
	loop
	{
		if(OnSpell)
		{
			if(alpha < 255)
			{
				alpha += 2;
			}
		}
		else
		{
			alpha = 0;
		}

		ang3+=sin(ang)/6; ang3%=360;
		ObjRender_SetAlpha(obj1, alpha);
		
		ObjRender_SetPosition(obj1, GetStgFrameWidth/2, GetStgFrameHeight/2, 0);
		ObjRender_SetScaleXYZ(obj1, 1, 1, 0);

		ang+=0.5;
		yield;
	}
}