let GCSD=GetCurrentScriptDirectory;
let path=GCSD~"img/stage02a.png";
let path2=GCSD~"img/eff04.png";
let path3=GCSD~"img/eff04b.png";
let objScene=GetEnemyBossSceneObjectID();
let bspell=false;

@Initialize{
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(350);
	SetCameraElevationAngle(-50);
	SetFogParam(0,3000,64,0,64);
	TCallBg;
}

@MainLoop{
	if(objScene!=ID_INVALID&&ObjEnemyBossScene_GetInfo(objScene,INFO_IS_SPELL)){
		bspell=true;
	}else{
		bspell=false;
	}
	yield;
}

task TCallBg{
	while(!Obj_IsDeleted(GetEnemyBossSceneObjectID())){
	ascent(i in -3..3)
	{
		ascent(k in -2..10){
			TDraw(i*512,k*128);
		}
	}
	while(bspell==false){ yield; }
	if(bspell==true){
		TDrawSpell;
	}
	while(bspell==true){ yield; }
	}
	ascent(i in -3..3)
	{
		ascent(k in -2..10){
			TDraw(i*512,k*128);
		}
	}
}

task TDraw(x,y){
	let a=0;
	let obj=ObjPrim_Create(OBJ_SPRITE_3D);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj,20);
	ObjPrim_SetTexture(obj,path);
	ObjSprite3D_SetSourceDestRect(obj,0,0,512,128);
	ObjRender_SetPosition(obj,x+ObjRender_GetX(obj),y+ObjRender_GetY(obj),0);
	let x2=0;
	let y2=0;
	TCheck;
	loop{
		ObjSprite3D_SetSourceRect(obj,0,0+y2,512,128+y2);
		SetCameraAzimuthAngle(sin(a)*5+90);
		x2+=20;
		y2+=5;
		a+=0.75;
		yield;
	}
	task TCheck{
		let alpha=255;
		while(!Obj_IsDeleted(obj)){
			while(bspell==false){ yield; }
			loop(30){
				ObjRender_SetAlpha(obj,alpha);
				alpha-=255/30;
				yield;
			}
			Obj_Delete(obj);
		}
	}
}

task TDrawSpell{
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let obj2=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,path2);
	ObjPrim_SetTexture(obj2,path3);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetSourceRect(obj2,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjSprite2D_SetDestCenter(obj2);
	ObjRender_SetAlpha(obj,0);
	ObjRender_SetAlpha(obj2,0);
	Obj_SetRenderPriorityI(obj,20);
	Obj_SetRenderPriorityI(obj2,20);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	ObjRender_SetPosition(obj2,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	ObjRender_SetScaleXYZ(obj,1.5,1.75,1.5);
	ObjRender_SetScaleXYZ(obj2,2.35,2.35,2.35);
	let alpha=0;
	let alpha2=0;
	let spin=0;
	TCheck;
	TAction;
	loop(30){
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetAlpha(obj2,alpha2);
		alpha+=255/30;
		alpha2+=255/30;
		yield;
	}
	task TAction{
		while(bspell==true){
			ObjRender_SetAngleZ(obj2,spin);
			spin+=0.25;
			yield;
		}
	}
	task TCheck{
		while(bspell==true){ yield; }
		loop(20){
			ObjRender_SetAlpha(obj,alpha);
			ObjRender_SetAlpha(obj2,alpha2);
			alpha-=255/20;
			alpha2-=255/20;
			yield;
		}
		Obj_Delete(obj);
		Obj_Delete(obj2);
	}
}