
task CheckMagicCircle
{
let ItemCheck=0;//共通データの配列の長さをチェックする変数
let XY=[];//共通データの書き換えにワンクッション置くための変数
//let ItemPerFrame=60;//１フレームあたりの最大アイテム生成数（処理落ち対策）
loop
{
	ItemCheck=length(GetCommonDataDefault("MagicCircleBreak",[]));//毎フレーム共通データの長さチェック
	if(ItemCheck>0)
	{//配列に中身がある（アイテム発生フラグ立っている）場合の処理
		loop
		{
			XY=GetCommonDataDefault("MagicCircleBreak",[]);//共通データ内容を変数に渡す

			if(XY[2]<10)
			{
				MagicCircleBreak(XY[0],XY[1],XY[2],XY[3]);//アイテム生成。順番にX座標、Y座標、アイテムの種類
				CreateDefeatEffect(XY[0],XY[1]);
			}
			else if(XY[2]<100)
			{
				CallMagicEffect(XY[0],XY[1],XY[2],XY[3]);
			}
			else if(XY[2]<1000)
			{
				EliminateBurstReturnShotNum+=1;
				CallMagicShotEffect(XY[0],XY[1],XY[2],XY[3]);
			}
			else
			{
				CallDollDefeatEffect(XY[0],XY[1],XY[2],XY[3]);
			}
			loop(4)
			{
				XY=erase(XY, 0);
			}//生成したのでその要素を配列から削除
			if(length(XY)==0)
			{//削除後の配列が空になった場合
				SetCommonData("MagicCircleBreak",[]);//共通データを空にして
				break;//アイテム生成ループ脱出
		
			}
			else
			{
				SetCommonData("MagicCircleBreak",XY);
			}//配列が空でない場合共通データに変更後の配列を渡す
		}
	}
yield;
}
}

task CallDollDefeatEffect(x,y,type,scale)
{
	DollDefeatEffect(x,y,type,scale);
}

task DollDefeatEffect(x,y,type,scale)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgDoll);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -16, -16);
		ObjEffect_SetVertexXY(obj, 1, 16,  -16);
		ObjEffect_SetVertexXY(obj, 2, 16, 16);
		ObjEffect_SetVertexXY(obj, 3,  -16,  16);

		ObjEffect_SetVertexUV(obj, 0,  768,  0);
		ObjEffect_SetVertexUV(obj, 1,  800, 0);
		ObjEffect_SetVertexUV(obj, 2, 800,  32);
		ObjEffect_SetVertexUV(obj, 3, 768, 32);
		
		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		let speed=0;
		Obj_SetSpeed(obj,1.0);
		Obj_SetAngle(obj,90);
		let Alpha=255;
		let Scale=1.5;
		let StandardScale=Scale;
		let Zangle=0;
		loop(60)
		{
			ObjEffect_SetAngle(obj,0,0,Zangle);
			ObjEffect_SetScale(obj,Scale,Scale);
			Obj_SetSpeed(obj,speed);
			speed+=2/60;
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			Zangle+=3;
			Scale-=0.003;
			Alpha-=255/60;
			yield;
		}
		Obj_Delete(obj);
}

task CreateDefeatEffect(x,y)
{
			let R;let G;let B;
			alternative(StageProgress)
			case(1){R=0;G=250;B=154;}
			case(2){R=255;G=100;B=0;}
			case(3){R=148;G=0;B=211;}
			case(4){R=0;G=100;B=255;}
			case(5){R=255;G=255;B=0;}

	ZakoCircleExplosion(x,y,1.2,[R,G,B],15);
	//ZakoCircleExplosion(x,y,1.2,[255,255,255],15);
}

task ZakoCircleExplosion(x,y,size,color,time)
{
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgEffects);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);

	ObjEffect_SetLayer(obj,2);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ADD);

	ObjEffect_SetVertexUV(obj, 0, 128, 0);
	ObjEffect_SetVertexUV(obj, 1, 256, 0);
	ObjEffect_SetVertexUV(obj, 2, 256, 128);
	ObjEffect_SetVertexUV(obj, 3, 128, 128);

	ObjEffect_SetVertexXY(obj, 0, -64, -64);
	ObjEffect_SetVertexXY(obj, 1, 64,  -64);
	ObjEffect_SetVertexXY(obj, 2,  64,  64);
	ObjEffect_SetVertexXY(obj, 3,  -64, 64);

	Obj_SetPosition(obj, x,y);
	let Alpha=150;
	let Xangle=rand(0,360);
	let Yangle=rand(0,360);
	let Zangle=rand(0,360);
	let Xangle=0;
	let Yangle=0;
	let Zangle=0;
	ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

	let Xsize=size;
	let Ysize=size;
	let alphaPlus=Alpha/time;
	let frame=0;
	let dir=rand_int(0,1)*2-1;
	loop(time)
	{
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
	//	Xangle+=3*dir;
		ObjEffect_SetScale(obj,sin(frame*(90/time))*Xsize,sin(frame*(90/time))*Ysize);
		Alpha-=alphaPlus;
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,color[0],color[1],color[2]);
		}
		frame++;
		yield;
	}
	Obj_Delete(obj);
}

task ZakoEnemyExplosion(x,y,scale,color,scalePlus,type,frames)
{
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgEffects);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ADD);

	ObjEffect_SetVertexUV(obj, 0, 0, 40);
	ObjEffect_SetVertexUV(obj, 1, 50, 40);
	ObjEffect_SetVertexUV(obj, 2, 50, 90);
	ObjEffect_SetVertexUV(obj, 3, 0, 90);
	ObjEffect_SetVertexXY(obj, 0, -15, -15);
	ObjEffect_SetVertexXY(obj, 1, 15,  -15);
	ObjEffect_SetVertexXY(obj, 2,  15,  15);
	ObjEffect_SetVertexXY(obj, 3,  -15, 15);

	Obj_SetPosition   (obj, x,y);
	Obj_SetSpeed      (obj, 0);

	ObjEffect_SetScale(obj,1,1);
	if(type==0)
	{
		ObjEffect_SetAngle(obj,rand(-80,80),rand(-80,80),rand(0,360));
	}
	else
	{
		ObjEffect_SetAngle(obj,0,0,rand(0,360));
	}

	ObjEffect_SetLayer(obj,2);


	let alpha=240;
	loop(frames)
	{
		Obj_SetPosition(obj,x+ScreenShakeX,y+ScreenShakeY);
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,alpha,color[0],color[1],color[2]);
		}
		ObjEffect_SetScale(obj,scale/2,scale/2);
		alpha-=240/frames;
		scale+=scalePlus*2;
		wait(1);
	}
	Obj_Delete(obj);
}

task CallMagicShotEffect(x,y,type,scale)
{
	loop(3)
	{
	MagicShotEffect(x,y,type,scale);
	}
}

task MagicShotEffect(x,y,type,scale)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let R;let G;let B;
		alternative(type)
		case(100){R=0;G=255;B=0;}
		case(101){R=255;G=183;B=76;}
		case(102){R=200;G=0;B=0;}
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,155,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		let speed=rand(1,5);
		let angle=rand(0,360);
		let Scale=rand(0.75,1.5);
		let StandardScale=Scale;
		if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){Obj_Delete(obj);return;}
		loop(30)
		{
			Scale-=StandardScale/30;
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			ObjEffect_SetScale(obj,Scale,Scale);
			yield;
		}
		Obj_Delete(obj);
}

task CallMagicEffect(x,y,type,scale)
{
	loop(5)
	{
	MagicEffect(x,y,type,scale);
	}
}

task MagicEffect(x,y,type,scale)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let R;let G;let B;
		alternative(type)
		case(10){R=255;G=0;B=0;}
		case(11){R=0;G=0;B=255;}
		case(12){R=0;G=255;B=0;}
		case(13){R=255;G=255;B=0;}
		case(14){R=rand(0,255);G=rand(0,255);B=rand(0,255);}
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,155,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		let speed=rand(1,5);
		let angle=rand(0,360);
		let Scale=rand(1.0,2.0);
		let StandardScale=Scale;
		if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){Obj_Delete(obj);return;}
		loop(30)
		{
			Scale-=StandardScale/30;
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			ObjEffect_SetScale(obj,Scale,Scale);
			yield;
		}
		Obj_Delete(obj);
}

task MagicCircleBreak(x,y,type,scale)
{
	let angle=rand(0,360);
	if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){return;}
	let way=6;
	ascent(i in 0..way)
	{
	MagicCircleBreakEffect(x,y,type,scale*1.2,angle+i*360/way,way);
	}
}

task MagicCircleBreakEffect(x,y,type,scale,angle,way)
{
	let r=128;
	let X=[0,0,0,0,0,0];
	let Y=[0,0,0,0,0,0];
	X[0]=0;
	X[1]=r/2*cos(angle);
	X[2]=r/2*cos(angle+360/way);
	X[3]=r*cos(angle);
	X[4]=r*cos(angle+180/way);
	X[5]=r*cos(angle+360/way);

	Y[0]=0;
	Y[1]=r/2*sin(angle);
	Y[2]=r/2*sin(angle+360/way);
	Y[3]=r*sin(angle);
	Y[4]=r*sin(angle+180/way);
	Y[5]=r*sin(angle+360/way);

	MagicCircleBreakEffectTriangle(x,y,X[0],X[1],X[2],Y[0],Y[1],Y[2],type,scale);
	MagicCircleBreakEffectTriangle(x,y,X[1],X[3],X[4],Y[1],Y[3],Y[4],type,scale);
	MagicCircleBreakEffectTriangle(x,y,X[2],X[4],X[5],Y[2],Y[4],Y[5],type,scale);
	MagicCircleBreakEffectTriangle(x,y,X[1],X[2],X[4],Y[1],Y[2],Y[4],type,scale);
}

task MagicCircleBreakEffectTriangle(x,y,x1,x2,x3,y1,y2,y3,type,scale)
{
		let CX=128;
		let CY=128;
		let TriCX=(x1+x2+x3)/3;
		let TriCY=(y1+y2+y3)/3;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBreakCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 3);
		ObjEffect_SetVertexXY(obj, 0, x1-TriCX, y1-TriCY);
		ObjEffect_SetVertexXY(obj, 1, x2-TriCX, y2-TriCY);
		ObjEffect_SetVertexXY(obj, 2, x3-TriCX, y3-TriCY);
		
		ObjEffect_SetVertexUV(obj, 0,  x1+CX,  y1+CY);
		ObjEffect_SetVertexUV(obj, 1,  x2+CX, y2+CY);
		ObjEffect_SetVertexUV(obj, 2, x3+CX,  y3+CY);

		ObjEffect_SetLayer(obj,2);

		if(type==2)
		{
			ascent(let i in 0..3)
			{
				ObjEffect_SetVertexColor(obj,i,255,63,82,255);
			}
		}
		if(type==0)
		{
			let R;let G;let B;
			alternative(StageProgress)
			case(1){R=0;G=250;B=154;}
			case(2){R=255;G=100;B=0;}
			case(3){R=148;G=0;B=211;}
			case(4){R=0;G=100;B=255;}
			case(5){R=0;G=250;B=154;}
			ascent(let i in 0..3)
			{
				ObjEffect_SetVertexColor(obj,i,255,R,G,B);
			}
		}

		Obj_SetPosition(obj,x+TriCX*scale,y+TriCY*scale);

		ObjEffect_SetScale(obj, scale,scale);

		let Sscale=scale;
		let speed=((TriCX)^2+(TriCY)^2)^0.5*0.05;
		let Angle=atan2(TriCY,TriCX);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,Angle);
		let Xangle=0;
		let Yangle=0;
		let Zangle=0;
		let XangleRotate=rand(-10,10);
		let YangleRotate=rand(-10,10);
		let ZangleRotate=rand(-10,10);
		loop(30)
		{
			ObjEffect_SetScale(obj, scale,scale);
			scale-=Sscale/30;
			Xangle+=XangleRotate;
			Yangle+=YangleRotate;
			Zangle+=ZangleRotate;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			yield;
		}
		Obj_Delete(obj);
}

////////////////////////////////////////////////////////////////////////
////////////////////////エネミーライフ部////////////////////////////////
//////////////////////////////////////////////////////////////////////////

task EnemyLifeDisplay//下部に敵のライフを表示
{let judg=0;
loop
{
if(IsBossExisting==true && GetEnemyLife>1)
{
BossLifeBerDisplay;
BossLifeDisplay;
while(GetEnemyLife>1){yield}
}
if(GetCommonDataDefault("IsMSDBossExisting",false)==true && GetCommonDataDefault("BossLife",0)>1)
{
BossLifeBerDisplay;
BossLifeDisplay;
if(judg==0)
{
TotalBossLifeBerDisplay;
TotalBossLifeDisplay;
}
judg+=1;
while(GetCommonDataDefault("BossLife",0)>1){yield}
if(GetCommonDataDefault("Playermissed",true))
{
	AchievementNotice(91);
}
}
if(!GetCommonDataDefault("IsMSDBossExisting",false))
{
	judg=0;
}
yield;
}
}

task LightBer(Point)
{
		let R=255;
		let G=255*0;
		let B=255*0;
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		ObjEffect_SetScale(obj,0.5,0.5);

		let Xleng=127;
		if(Point>=Xleng*2.5+9.6+Xleng*2.5+9.6)
		{
			Point-=Xleng*2.5+9.6+Xleng*2.5+9.6;
		}
		if(Point<=Xleng*2.5)
		{
		Obj_SetPosition(obj,GetCenterX-177+Point,GetClipMinY+10-4.8);
		}
		else if(Point>Xleng*2.5 && Point<=Xleng*2.5+9.6)
		{
		Obj_SetPosition(obj,GetCenterX-177+Xleng*2.5,GetClipMinY+10-4.8+Point-Xleng*2.5);
		}
		else if(Point>Xleng*2.5+9.6 && Point<=Xleng*2.5+9.6+Xleng*2.5)
		{
		Obj_SetPosition(obj,GetCenterX-177+Xleng*2.5-(Point-Xleng*2.5-9.6),GetClipMinY+10+4.8);
		}
		else if(Xleng*2.5+9.6+Xleng*2.5 && Point<=Xleng*2.5+9.6+Xleng*2.5+9.6)
		{
		Obj_SetPosition(obj,GetCenterX-177,GetClipMinY+10+4.8-(Point-Xleng*2.5-9.6-Xleng*2.5));
		}
		let Alpha=150;
		loop(3)
		{
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
				Alpha-=150/3;
			}
		yield;
		}
		Obj_Delete(obj)
}

task TotalBossLifeBerDisplay//ライフバーの枠の設定
{
	let BossLifeArray=[GetCommonDataDefault("BossLife",0)];
	if(GetCommonDataDefault("STAGE1BOSS",false))
	{
		BossLifeArray=[2700,3500];
	}
	if(GetCommonDataDefault("STAGE2BOSS",false))
	{
		BossLifeArray=[2500,4600];
	}
	if(GetCommonDataDefault("STAGE3BOSS",false))
	{
		BossLifeArray=[3600,4800,2600];
	}
	if(GetCommonDataDefault("STAGE4BOSS",false))
	{
		BossLifeArray=[5200,8000,5200];
	}
	if(GetCommonDataDefault("STAGE5BOSS",false))
	{
		BossLifeArray=[10500,11000,22000,15000];
	}
	if(GetCommonDataDefault("TrueBossFlag",false))
	{
		BossLifeArray=[12500,13500];
	}
	if(GetCommonDataDefault("LastTrueBossFlag",false))
	{
		BossLifeArray=[9500];
	}

	let BossLifeMax=GetEnemyLife;
	let scale=0;
	if(IsBossExisting)
	{
		BossLifeMax=GetEnemyLife;
	}
	else if(length(BossLifeArray)==0)
	{
		BossLifeMax=GetCommonDataDefault("BossLife",0);
	}
	else
	{
		ascent(i in 0..length(BossLifeArray))
		{
		BossLifeMax+=BossLifeArray[i];
		}
	}
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer2);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, 0, -6);
		ObjEffect_SetVertexXY(obj, 1, 128,  -6);
		ObjEffect_SetVertexXY(obj, 2, 128, 6);
		ObjEffect_SetVertexXY(obj, 3,  0,  6);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  37);
		ObjEffect_SetVertexUV(obj, 1,  148, 37);
		ObjEffect_SetVertexUV(obj, 2, 148,  47);
		ObjEffect_SetVertexUV(obj, 3, 6, 47);
		ObjEffect_SetLayer(obj,2);
		ObjEffect_SetScale(obj, 2.5,0.8);
		Obj_SetPosition(obj,GetCenterX-177,GetClipMinY+10);

		let PauseBossLife=0;
		let Num=length(BossLifeArray)-1;
		let Num2=Num;
		loop(length(BossLifeArray)-1)
		{
			ascent(i in 0..Num)
			{
				PauseBossLife+=BossLifeArray[Num2-i];			
			}
			PauseBerDisplay(BossLifeArray,PauseBossLife/BossLifeMax);
			Num-=1;
			PauseBossLife=0;
		}
			
		let UVCount=0;
		let Alpha=255;
		loop(60)
		{
			ObjEffect_SetScale(obj, scale,0.8);
			scale+=2.5/60;
			ObjEffect_SetVertexUV(obj, 0,  6,  37);
			ObjEffect_SetVertexUV(obj, 1,  6+UVCount*71*2, 37);
			ObjEffect_SetVertexUV(obj, 2, 6+UVCount*71*2,  47);
			ObjEffect_SetVertexUV(obj, 3,6, 47);
			UVCount+=1/60;



			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			yield;
		}
		ObjEffect_SetVertexUV(obj, 0,  6,  37);
		ObjEffect_SetVertexUV(obj, 1,  148, 37);
		ObjEffect_SetVertexUV(obj, 2, 148,  47);
		ObjEffect_SetVertexUV(obj, 3, 6, 47);
			ObjEffect_SetScale(obj, 2.5,0.8);

		loop(length(BossLifeArray))
		{
			while(GetCommonDataDefault("BossLife",0)>0)
			{
				if(GetCommonDataDefault("LifeBerReproduction",false)){break;}

				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
				}
				yield;
			}
			if(GetCommonDataDefault("LifeBerReproduction",false)){break;}
			yield;
		}

		if(GetCommonDataDefault("LifeBerReproduction",false))
		{
			yield;
			SetCommonData("LifeBerReproduction",false);
			Obj_Delete(obj);

			ReProductLifeBerFrame;

			function ReProductLifeBerFrame
			{

			let obj2 = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetTexture(obj2, imgBer2);
			ObjEffect_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
		//	ObjEffect_SetRenderState(obj2, ADD); 
			ObjEffect_CreateVertex(obj2, 4);
			ObjEffect_SetVertexXY(obj2, 0, 0, -6);
			ObjEffect_SetVertexXY(obj2, 1, 128,  -6);
			ObjEffect_SetVertexXY(obj2, 2, 128, 6);
			ObjEffect_SetVertexXY(obj2, 3,  0,  6);
		
			ObjEffect_SetVertexUV(obj2, 0,  6,  37);
			ObjEffect_SetVertexUV(obj2, 1,  148, 37);
			ObjEffect_SetVertexUV(obj2, 2, 148,  47);
			ObjEffect_SetVertexUV(obj2, 3, 6, 47);
			ObjEffect_SetLayer(obj2,2);
			ObjEffect_SetScale(obj2, 2.5,0.8);
			Obj_SetPosition(obj2,GetCenterX-177,GetClipMinY+10);

			let PauseBossLife=0;
			let Num=length(BossLifeArray)-1;
			let Num2=Num;

			loop(length(BossLifeArray)-1)
			{
			ascent(i in 0..Num)
			{
				PauseBossLife+=BossLifeArray[Num2-i];			
			}
			PauseBerDisplay2(BossLifeArray,PauseBossLife/BossLifeMax);
			Num-=1;
			PauseBossLife=0;
			}

			let UVCount=0;
			let Alpha=255;
	
			ObjEffect_SetVertexUV(obj2, 0,  6,  37);
			ObjEffect_SetVertexUV(obj2, 1,  148, 37);
			ObjEffect_SetVertexUV(obj2, 2, 148,  47);
			ObjEffect_SetVertexUV(obj2, 3, 6, 47);
			ObjEffect_SetScale(obj2, 2.5,0.8);
		
			loop(length(BossLifeArray))
			{
			while(GetCommonDataDefault("BossLife",0)>0)
			{
				if(GetCommonDataDefault("LifeBerReproduction",false)){break;}

				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj2,i,Alpha,255,255,255);
				}
				yield;
			}
			if(GetCommonDataDefault("LifeBerReproduction",false)){break;}
			yield;
			}
			if(GetCommonDataDefault("LifeBerReproduction",false))
			{
				yield;
				SetCommonData("LifeBerReproduction",false);
				Obj_Delete(obj2);
			
				ReProductLifeBerFrame;
			}
			else
			{
			Obj_SetPosition(obj2,GetCenterX-17,GetClipMinY+10);
			ObjEffect_SetVertexXY(obj2, 0, -64, -6);
			ObjEffect_SetVertexXY(obj2, 1, 64,  -6);
			ObjEffect_SetVertexXY(obj2, 2, 64, 6);
			ObjEffect_SetVertexXY(obj2, 3,  -64,  6);

			let UVCount=0;

			loop(60)
			{
			ObjEffect_SetScale(obj2, scale,0.8);
			scale-=2.5/60;
			ObjEffect_SetVertexUV(obj2, 0,  6+UVCount*71,  37);
			ObjEffect_SetVertexUV(obj2, 1,  148-UVCount*71, 37);
			ObjEffect_SetVertexUV(obj2, 2, 148-UVCount*71,  47);
			ObjEffect_SetVertexUV(obj2, 3, 6+UVCount*71, 47);
			UVCount+=1/60;

				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
				}
			yield;
			}
			Obj_Delete(obj2);
			}
			}
		}
		else
		{
		Obj_SetPosition(obj,GetCenterX-17,GetClipMinY+10);
		ObjEffect_SetVertexXY(obj, 0, -64, -6);
		ObjEffect_SetVertexXY(obj, 1, 64,  -6);
		ObjEffect_SetVertexXY(obj, 2, 64, 6);
		ObjEffect_SetVertexXY(obj, 3,  -64,  6);

		let UVCount=0;

		loop(60)
		{
			ObjEffect_SetScale(obj, scale,0.8);
			scale-=2.5/60;
			ObjEffect_SetVertexUV(obj, 0,  6+UVCount*71,  37);
			ObjEffect_SetVertexUV(obj, 1,  148-UVCount*71, 37);
			ObjEffect_SetVertexUV(obj, 2, 148-UVCount*71,  47);
			ObjEffect_SetVertexUV(obj, 3, 6+UVCount*71, 47);
			UVCount+=1/60;

				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
				}
			yield;
		}
		Obj_Delete(obj);
		}
}

task PauseBerDisplay(BossLifeArray,Percent)//ライフバーの枠の設定
{
	let scale=0;
	let Alpha=255;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer2);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -1, -6);
		ObjEffect_SetVertexXY(obj, 1, 1,  -6);
		ObjEffect_SetVertexXY(obj, 2, 1, 6);
		ObjEffect_SetVertexXY(obj, 3,  -1,  6);
		
		ObjEffect_SetVertexUV(obj, 0,  150,  37);
		ObjEffect_SetVertexUV(obj, 1,  152, 37);
		ObjEffect_SetVertexUV(obj, 2, 152,  47);
		ObjEffect_SetVertexUV(obj, 3, 150, 47);
		ObjEffect_SetLayer(obj,2);
		ObjEffect_SetScale(obj, 2.5,0.8);
		Obj_SetPosition(obj,GetCenterX-177+Percent*320,GetClipMinY+10);

		loop(60)
		{
			ObjEffect_SetScale(obj, scale,0.8);
			scale+=1.0/60;

				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
				}
			yield;
		}
		ObjEffect_SetScale(obj, scale,0.8);

		loop(length(BossLifeArray))
			{
			while(GetCommonDataDefault("BossLife",0)>0)
			{	
				if(GetCommonDataDefault("LifeBerReproduction",false)){break;}

				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
				}
				yield;
			}
			if(GetCommonDataDefault("LifeBerReproduction",false)){Obj_Delete(obj);break;}
			yield;
		}

		loop(60)
		{
			ObjEffect_SetScale(obj, scale,0.8);
			scale-=1.0/60;

				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
				}
			yield;
		}
		Obj_Delete(obj);
}

task PauseBerDisplay2(BossLifeArray,Percent)//ライフバーの枠の設定
{
	let scale=1.0;
	let Alpha=255;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer2);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -1, -6);
		ObjEffect_SetVertexXY(obj, 1, 1,  -6);
		ObjEffect_SetVertexXY(obj, 2, 1, 6);
		ObjEffect_SetVertexXY(obj, 3,  -1,  6);
		
		ObjEffect_SetVertexUV(obj, 0,  150,  37);
		ObjEffect_SetVertexUV(obj, 1,  152, 37);
		ObjEffect_SetVertexUV(obj, 2, 152,  47);
		ObjEffect_SetVertexUV(obj, 3, 150, 47);
		ObjEffect_SetLayer(obj,2);
		ObjEffect_SetScale(obj, 2.5,0.8);
		Obj_SetPosition(obj,GetCenterX-177+Percent*320,GetClipMinY+10);

			ObjEffect_SetScale(obj, scale,0.8);

		loop(length(BossLifeArray))
		{
			while(GetCommonDataDefault("BossLife",0)>0)
			{	

				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
				}
				yield;
			}
			yield;
		}

		loop(60)
		{
			ObjEffect_SetScale(obj, scale,0.8);
			scale-=1.0/60;

				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
				}
			yield;
		}
		Obj_Delete(obj);
}


task TotalBossLifeDisplay//ライフバーのバー部分の設定
{
	let BossLifeArray=[GetCommonDataDefault("BossLife",0)];

	if(GetCommonDataDefault("STAGE1BOSS",false))
	{
		BossLifeArray=[2700,3500];
	}
	if(GetCommonDataDefault("STAGE2BOSS",false))
	{
		BossLifeArray=[2500,4600];
	}
	if(GetCommonDataDefault("STAGE3BOSS",false))
	{
		BossLifeArray=[3600,4800,2600];
	}
	if(GetCommonDataDefault("STAGE4BOSS",false))
	{
		BossLifeArray=[5200,8000,5200];
	}
	if(GetCommonDataDefault("STAGE5BOSS",false))
	{
		BossLifeArray=[10500,11000,22000,15000];
	}
	if(GetCommonDataDefault("TrueBossFlag",false))
	{
		BossLifeArray=[12500,12000];
	}
	if(GetCommonDataDefault("LastTrueBossFlag",false))
	{
		BossLifeArray=[9500];
	}

	let Color=[];

	let BossLifeMax=0;
	let BossLife=0;
	let scale=2.5;
	let BerLeng=0;
	if(IsBossExisting)
	{
		BossLifeMax=GetEnemyLife;
	}
	else if(length(BossLifeArray)==0)
	{
		BossLifeMax=GetCommonDataDefault("BossLife",0);
	}
	else
	{
		ascent(i in 0..length(BossLifeArray))
		{
		BossLifeMax+=BossLifeArray[i];
		}
	}
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer2);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, 0, -3);
		ObjEffect_SetVertexXY(obj, 1, BerLeng,  -3);
		ObjEffect_SetVertexXY(obj, 2, BerLeng, 3);
		ObjEffect_SetVertexXY(obj, 3,  0,  3);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  51);
		ObjEffect_SetVertexUV(obj, 1,  148, 51);
		ObjEffect_SetVertexUV(obj, 2, 148,  57);
		ObjEffect_SetVertexUV(obj, 3, 6, 57);
		ObjEffect_SetLayer(obj,3);
		ObjEffect_SetScale(obj, scale,1.0);

		ascent(let i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,120,255,200,255);
		}

		Obj_SetPosition(obj,GetCenterX-177,GetClipMinY+10);
		let HueCount=0;

		let PauseBossLife;
		let Num=length(BossLifeArray)-1;

		let Alpha=255;

		loop(60)
		{
			BossLife=GetCommonDataDefault("BossLife",0);
			if(IsBossExisting)
			{
				scale=2.5*GetEnemyLife/BossLifeMax;
			}
			else if(length(BossLifeArray)==1)
			{
				scale=2.5*BossLife/BossLifeMax;
			}
			else
			{
				ascent(i in 1..length(BossLifeArray))
				{
				BossLife+=BossLifeArray[i];
				}
				scale=2.5*(BossLife)/BossLifeMax;
			}
			ObjEffect_SetVertexXY(obj, 0, 0, -4);
			ObjEffect_SetVertexXY(obj, 1, BerLeng,  -4);
			ObjEffect_SetVertexXY(obj, 2, BerLeng, 4);
			ObjEffect_SetVertexXY(obj, 3,  0,  4);
			Color=HueDifine(HueCount);
			ObjEffect_SetScale(obj, scale,1.0);

			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255-Color[0]/5, 200-Color[1]/5,255-Color[2]/5);
			}
			HueCount+=3;
			BerLeng+=128/60;
			yield;
		}
			ObjEffect_SetVertexXY(obj, 0, 0, -4);
			ObjEffect_SetVertexXY(obj, 1, BerLeng,  -4);
			ObjEffect_SetVertexXY(obj, 2, BerLeng, 4);
			ObjEffect_SetVertexXY(obj, 3,  0,  4);

		loop(length(BossLifeArray))
		{
		while(GetCommonDataDefault("BossLife",0)>0)
		{
			BossLife=GetCommonDataDefault("BossLife",0);
			if(length(BossLifeArray)==1)
			{
				scale=2.5*BossLife/BossLifeMax;
			}
			else
			{
				ascent(i in 1..length(BossLifeArray))
				{
				BossLife+=BossLifeArray[i];
				}
				scale=2.5*BossLife/BossLifeMax;
			}
			//scale=2.5*GetCommonDataDefault("BossLife",0)/BossLifeMax;
			Color=HueDifine(HueCount);
			ObjEffect_SetScale(obj, scale,1.0);

			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255-Color[0]/5, 200-Color[1]/5,255-Color[2]/5);
			}
			HueCount+=3;
			if(GetCommonDataDefault("LifeBerReproduction",false)){break;}
			yield;
		}
		BossLifeArray=erase(BossLifeArray, 0);
		if(GetCommonDataDefault("LifeBerReproduction",false)){break;}
		yield;
		}

		if(GetCommonDataDefault("LifeBerReproduction",false))
		{
			yield;
			Obj_Delete(obj);

			ReProductLifeBer;

			function ReProductLifeBer
			{

			let obj2 = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetTexture(obj2, imgBer2);
			ObjEffect_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_SetRenderState(obj2, ADD); 
			ObjEffect_CreateVertex(obj2, 4);
			ObjEffect_SetVertexXY(obj2, 0, 0, -3);
			ObjEffect_SetVertexXY(obj2, 1, BerLeng,  -3);
			ObjEffect_SetVertexXY(obj2, 2, BerLeng, 3);
			ObjEffect_SetVertexXY(obj2, 3,  0,  3);
		
			ObjEffect_SetVertexUV(obj2, 0,  6,  51);
			ObjEffect_SetVertexUV(obj2, 1,  148, 51);
			ObjEffect_SetVertexUV(obj2, 2, 148,  57);
			ObjEffect_SetVertexUV(obj2, 3, 6, 57);
			ObjEffect_SetLayer(obj2,3);
			ObjEffect_SetScale(obj2, scale,1.0);

			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj2,i,120,255,200,255);
			}

			Obj_SetPosition(obj2,GetCenterX-177,GetClipMinY+10);
		//	let HueCount=0;

			let PauseBossLife;
			let Num=length(BossLifeArray)-1;

			let Alpha=255;

			loop(60)
			{
			BossLife=GetCommonDataDefault("BossLife",0);
			if(IsBossExisting)
			{
				scale=2.5*GetEnemyLife/BossLifeMax;
			}
			else if(length(BossLifeArray)==1)
			{
				scale=2.5*BossLife/BossLifeMax;
			}
			else
			{
				ascent(i in 1..length(BossLifeArray))
				{
				BossLife+=BossLifeArray[i];
				}
				scale=2.5*(BossLife)/BossLifeMax;
			}
			ObjEffect_SetVertexXY(obj2, 0, 0, -4);
			ObjEffect_SetVertexXY(obj2, 1, BerLeng,  -4);
			ObjEffect_SetVertexXY(obj2, 2, BerLeng, 4);
			ObjEffect_SetVertexXY(obj2, 3,  0,  4);
			Color=HueDifine(HueCount);
			ObjEffect_SetScale(obj2, scale,1.0);

			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj2,i,Alpha,255-Color[0]/5, 200-Color[1]/5,255-Color[2]/5);
			}
		//	HueCount+=3;
		//	BerLeng+=128/60;
			//Alpha+=255/60;
		//	yield;
		}
			ObjEffect_SetVertexXY(obj2, 0, 0, -4);
			ObjEffect_SetVertexXY(obj2, 1, BerLeng,  -4);
			ObjEffect_SetVertexXY(obj2, 2, BerLeng, 4);
			ObjEffect_SetVertexXY(obj, 3,  0,  4);
		SetCommonData("asdfg",BossLifeArray);
		let ArrayPlus=GetCommonData("SetBossLifeArray");
		if(length(ArrayPlus)!=0)
		{
		BossLifeArray=BossLifeArray~ArrayPlus;
		}
		loop(length(BossLifeArray))
		{
		while(GetCommonDataDefault("BossLife",0)>0)
		{
			BossLife=GetCommonDataDefault("BossLife",0);
			if(length(BossLifeArray)==1)
			{
				scale=2.5*BossLife/BossLifeMax;
			}
			else
			{
				ascent(i in 1..length(BossLifeArray))
				{
				BossLife+=BossLifeArray[i];
				}
				scale=2.5*BossLife/BossLifeMax;
			}
			//scale=2.5*GetCommonDataDefault("BossLife",0)/BossLifeMax;
			Color=HueDifine(HueCount);
			ObjEffect_SetScale(obj2, scale,1.0);

			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj2,i,Alpha,255-Color[0]/5, 200-Color[1]/5,255-Color[2]/5);
			}
			HueCount+=3;
			if(GetCommonDataDefault("LifeBerReproduction",false)){break;}
			yield;
		}
		BossLifeArray=erase(BossLifeArray, 0);
		if(GetCommonDataDefault("LifeBerReproduction",false)){break;}
		yield;
		}
		if(GetCommonDataDefault("LifeBerReproduction",false))
		{
			yield;
			Obj_Delete(obj2);

			ReProductLifeBer;
		}
		else
		{
		Obj_Delete(obj2);
		}

			}

		}
		else
		{
		Obj_Delete(obj);
		}
}


task BossLifeBerDisplay//ライフバーの枠の設定
{
	let BossLifeMax=GetEnemyLife;
	let scale=0;
	if(IsBossExisting)
	{
		BossLifeMax=GetEnemyLife;
	}
	else
	{
		BossLifeMax=GetCommonDataDefault("BossLife",0);
	}
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer2);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, 0, -8);
		ObjEffect_SetVertexXY(obj, 1, 142,  -8);
		ObjEffect_SetVertexXY(obj, 2, 142, 8);
		ObjEffect_SetVertexXY(obj, 3,  0,  8);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  11);
		ObjEffect_SetVertexUV(obj, 1,  148, 11);
		ObjEffect_SetVertexUV(obj, 2, 148,  21);
		ObjEffect_SetVertexUV(obj, 3, 6, 21);
		ObjEffect_SetLayer(obj,8);
		ObjEffect_SetScale(obj, 2.5,0.8);
		Obj_SetPosition(obj,GetCenterX-177,GetClipMaxY+8);

		loop(60)
		{
			ObjEffect_SetScale(obj, scale,0.8);
			scale+=2.5/60;
			yield;
		}
			ObjEffect_SetScale(obj, scale,0.8);
		if(IsBossExisting)
		{
			while(GetEnemyLife>0)
			{
				yield;
			}
		}
		else
		{
			while(GetCommonDataDefault("BossLife",0)>0)
			{
				yield;
			}
		}

		Obj_SetPosition(obj,GetCenterX,GetClipMaxY+8);
		ObjEffect_SetVertexXY(obj, 0, -71, -8);
		ObjEffect_SetVertexXY(obj, 1, 71,  -8);
		ObjEffect_SetVertexXY(obj, 2, 71, 8);
		ObjEffect_SetVertexXY(obj, 3,  -71,  8);
		loop(60)
		{
			ObjEffect_SetScale(obj, scale,0.8);
			scale-=2.5/60;
			yield;
		}
		Obj_Delete(obj);
}


task BossLifeDisplay//ライフバーのバー部分の設定
{
	let Color=[];

	let BossLifeMax=GetEnemyLife;
	let scale=2.5;
	let BerLeng=0;
	if(IsBossExisting)
	{
		BossLifeMax=GetEnemyLife;
	}
	else
	{
		BossLifeMax=GetCommonDataDefault("BossLife",0);
	}
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer2);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, 0, -4);
		ObjEffect_SetVertexXY(obj, 1, BerLeng,  -4);
		ObjEffect_SetVertexXY(obj, 2, BerLeng, 4);
		ObjEffect_SetVertexXY(obj, 3,  0,  4);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  148, 27);
		ObjEffect_SetVertexUV(obj, 2, 148,  33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);
		ObjEffect_SetLayer(obj,8);
		ObjEffect_SetScale(obj, scale,1.0);

		ascent(let i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,120,255,200,255);
		}

		Obj_SetPosition(obj,GetCenterX-177,GetClipMaxY+8);
		let HueCount=0;
		loop(60)
		{
			if(IsBossExisting)
			{
				scale=2.5*GetEnemyLife/BossLifeMax;
			}
			else
			{
				scale=2.5*GetCommonDataDefault("BossLife",0)/BossLifeMax;
			}
			ObjEffect_SetVertexXY(obj, 0, 0, -4);
			ObjEffect_SetVertexXY(obj, 1, BerLeng,  -4);
			ObjEffect_SetVertexXY(obj, 2, BerLeng, 4);
			ObjEffect_SetVertexXY(obj, 3,  0,  4);
			Color=HueDifine(HueCount);
			ObjEffect_SetScale(obj, scale,1.0);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,120,255-Color[0]/5, 200-Color[1]/5,255-Color[2]/5);
			}
			HueCount+=3;
			BerLeng+=142/60;
			yield;
		}
			ObjEffect_SetVertexXY(obj, 0, 0, -4);
			ObjEffect_SetVertexXY(obj, 1, BerLeng,  -4);
			ObjEffect_SetVertexXY(obj, 2, BerLeng, 4);
			ObjEffect_SetVertexXY(obj, 3,  0,  4);
		if(IsBossExisting)
		{
		while(GetEnemyLife>0)
		{
			scale=2.5*GetEnemyLife/BossLifeMax;
			Color=HueDifine(HueCount);
			ObjEffect_SetScale(obj, scale,1.0);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,120,255-Color[0]/5, 200-Color[1]/5,255-Color[2]/5);
			}
			HueCount+=3;
			yield;
		}
		}
		else
		{
		while(GetCommonDataDefault("BossLife",0)>0)
		{
			scale=2.5*GetCommonDataDefault("BossLife",0)/BossLifeMax;
			Color=HueDifine(HueCount);
			ObjEffect_SetScale(obj, scale,1.0);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,120,255-Color[0]/5, 200-Color[1]/5,255-Color[2]/5);
			}
			HueCount+=3;
			yield;
		}
		}
		Obj_Delete(obj);
}


task CheckBMEBE
{
let ItemCheck=0;
let XY=[];
loop
{
	ItemCheck=length(GetCommonDataDefault("BurstModeErazeBulletEffect",[]));
	if(ItemCheck>0)
	{
		loop
		{
			XY=GetCommonDataDefault("BurstModeErazeBulletEffect",[]);

			BurstModeErazeBulletEffect(XY[0],XY[1],XY[2]);
	
			loop(3)
			{
				XY=erase(XY, 0);
			}
			if(length(XY)==0)
			{
				SetCommonData("BurstModeErazeBulletEffect",[]);
				break;
			}
			else
			{
				SetCommonData("BurstModeErazeBulletEffect",XY);
			}
		}
	}
yield;
}
}

task BurstModeErazeBulletEffect(x,y,R)
{
		let scx=1;
		let scy=1;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -R, -R);
		ObjEffect_SetVertexXY(obj, 1,R,  -R);
		ObjEffect_SetVertexXY(obj, 2,R, R);
		ObjEffect_SetVertexXY(obj, 3,  -R,  R);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  128, 0);
		ObjEffect_SetVertexUV(obj, 2, 128, 128);
		ObjEffect_SetVertexUV(obj, 3, 0, 128);

		let Alpha=255;
		let R=100;let G=100; let B=255;

		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		
		ObjEffect_SetScale(obj, scx,scy);

		loop(30)
		{
			scx-=1/30;
			scy-=1/30;
			ObjEffect_SetScale(obj, scx,scy);
			yield;
		}
		Obj_Delete(obj);
}

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

task EnemyMagicCircle//敵スペルカード発動時のエフェクト
{
loop
{
if(GetCommonDataDefault("BossLastAttack",false)==true)
{
let BMcolor=GetCommonData("BossLastAttackColor");

if(GetCommonDataDefault("TrueBossFlag",false))
{
TrueMagicCircleAppear1(1);
TrueMagicCircleAppear1(-1);
TrueBossConcentAppearEffect();
}
else
{
MagicCircleAppear1(BMcolor[0],BMcolor[1],BMcolor[2],1);
MagicCircleAppear1(BMcolor[0],BMcolor[1],BMcolor[2],-1);
BossConcentEffect(BMcolor[0],BMcolor[1],BMcolor[2]);
}

//BombBarrier;

while(GetCommonDataDefault("BossLastAttack",false)==true){yield;}
}
yield;
}
}

	task BombBarrier{	//ボムバリアエフェクト
		let killtime=GetTimeOfPlayerInvincibility;
		let expand=80;
		let width=6;
		let grf=GREEN01;
		let delay=60;
		let size=50;
		let dis=300;
		let rotq=MakeRotate(0.877,0.488,1.55);

		let G=(1+5^0.5)/2;
		let va=[1*size,G*size,0];
		let vb=[-1*size,G*size,0];
		let vc=[1*size,-G*size,0];
		let vd=[-1*size,-G*size,0];

		let ve=[0,1*size,G*size];
		let vf=[0,-1*size,G*size];
		let vg=[0,1*size,-G*size];
		let vh=[0,-1*size,-G*size];

		let vi=[G*size,0,1*size];
		let vj=[G*size,0,-1*size];
		let vk=[-G*size,0,1*size];
		let vl=[-G*size,0,-1*size];

		OrbitLaser3D(va[0],va[1],va[2],		vb[0],vb[1],vb[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(va[0],va[1],va[2],		ve[0],ve[1],ve[2],	rotq,expand,width,killtime,dis,grf+1,delay);

		OrbitLaser3D(va[0],va[1],va[2],		vg[0],vg[1],vg[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(va[0],va[1],va[2],		vi[0],vi[1],vi[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(va[0],va[1],va[2],		vj[0],vj[1],vj[2],	rotq,expand,width,killtime,dis,grf+1,delay);

		OrbitLaser3D(vd[0],vd[1],vd[2],		vc[0],vc[1],vc[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vd[0],vd[1],vd[2],		vf[0],vf[1],vf[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vd[0],vd[1],vd[2],		vh[0],vh[1],vh[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vd[0],vd[1],vd[2],		vk[0],vk[1],vk[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vd[0],vd[1],vd[2],		vl[0],vl[1],vl[2],	rotq,expand,width,killtime,dis,grf+1,delay);

		OrbitLaser3D(vb[0],vb[1],vb[2],		ve[0],ve[1],ve[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vb[0],vb[1],vb[2],		vg[0],vg[1],vg[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vb[0],vb[1],vb[2],		vk[0],vk[1],vk[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vb[0],vb[1],vb[2],		vl[0],vl[1],vl[2],	rotq,expand,width,killtime,dis,grf-1,delay);


		OrbitLaser3D(vc[0],vc[1],vc[2],		vf[0],vf[1],vf[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vc[0],vc[1],vc[2],		vh[0],vh[1],vh[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vc[0],vc[1],vc[2],		vi[0],vi[1],vi[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vc[0],vc[1],vc[2],		vj[0],vj[1],vj[2],	rotq,expand,width,killtime,dis,grf+1,delay);

		OrbitLaser3D(ve[0],ve[1],ve[2],		vf[0],vf[1],vf[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(ve[0],ve[1],ve[2],		vi[0],vi[1],vi[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(ve[0],ve[1],ve[2],		vk[0],vk[1],vk[2],	rotq,expand,width,killtime,dis,grf+1,delay);

		OrbitLaser3D(vf[0],vf[1],vf[2],		vi[0],vi[1],vi[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vf[0],vf[1],vf[2],		vk[0],vk[1],vk[2],	rotq,expand,width,killtime,dis,grf+1,delay);

		OrbitLaser3D(vg[0],vg[1],vg[2],		vh[0],vh[1],vh[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vg[0],vg[1],vg[2],		vj[0],vj[1],vj[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vg[0],vg[1],vg[2],		vl[0],vl[1],vl[2],	rotq,expand,width,killtime,dis,grf+1,delay);

		OrbitLaser3D(vh[0],vh[1],vh[2],		vj[0],vj[1],vj[2],	rotq,expand,width,killtime,dis,grf+1,delay);
		OrbitLaser3D(vh[0],vh[1],vh[2],		vl[0],vl[1],vl[2],	rotq,expand,width,killtime,dis,grf+1,delay);

		OrbitLaser3D(vi[0],vi[1],vi[2],		vj[0],vj[1],vj[2],	rotq,expand,width,killtime,dis,grf+1,delay);

		OrbitLaser3D(vk[0],vk[1],vk[2],		vl[0],vl[1],vl[2],	rotq,expand,width,killtime,dis,grf-1,delay);
/*
		let va=[0,0,6^0.5/2*size];
		let vb=[3^0.5*2/3*size,0,-6^0.5/6*size];
		let vc=[-3^0.5/3*size,size,-6^0.5/6*size];
		let vd=[-3^0.5/3*size,-size,-6^0.5/6*size];
		OrbitLaser3D(va[0],va[1],va[2],		vb[0],vb[1],vb[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(va[0],va[1],va[2],		vc[0],vc[1],vc[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(va[0],va[1],va[2],		vd[0],vd[1],vd[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(vb[0],vb[1],vb[2],		vc[0],vc[1],vc[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(vc[0],vc[1],vc[2],		vd[0],vd[1],vd[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(vd[0],vd[1],vd[2],		vb[0],vb[1],vb[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(-va[0],-va[1],-va[2],	-vb[0],-vb[1],-vb[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(-va[0],-va[1],-va[2],	-vc[0],-vc[1],-vc[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(-va[0],-va[1],-va[2],	-vd[0],-vd[1],-vd[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(-vb[0],-vb[1],-vb[2],	-vc[0],-vc[1],-vc[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(-vc[0],-vc[1],-vc[2],	-vd[0],-vd[1],-vd[2],	rotq,expand,width,killtime,dis,grf,delay);
		OrbitLaser3D(-vd[0],-vd[1],-vd[2],	-vb[0],-vb[1],-vb[2],	rotq,expand,width,killtime,dis,grf,delay);
*/
	}

	task OrbitLaser3D(	//ボスの周りを3D回転するレーザー。ボムバリア演出用。
		sx,		//始端座標	※展開完了時の倍率を1とする。
		sy,
		sz,
		ex,		//終端座標
		ey,
		ez,
		rotq,		//どうせ複数オブジェクトで同一パターン回転なのでまとめて四元数
		expand,		//展開完了までの時間
		width,		//レーザー幅
		killtime,	//終了時間。負数ならスペル終了まで。
		dis,		//視点距離
		grf,
		delay
	){
		let obj=Obj_Create(OBJ_LASER);
		Obj_SetAutoDelete(obj,false);
		ObjShot_SetGraphic(obj,grf);
		ObjShot_SetDelay(obj,delay);
		ObjShot_SetBombResist(obj,true);
		ObjLaser_SetWidth(obj,width);
		ObjLaser_SetSource(obj,false);
		let spos=[0,sx,sy,sz];
		let epos=[0,ex,ey,ez];
		if(expand<1){expand=1;}	//ゼロ割回避
		let expspd=1/expand;
		expand=0;	//現在の展開倍率として再利用

		let enemyX=GetCommonDataDefault("BossX",0);
		let enemyY=GetCommonDataDefault("BossY",0);
		while(!Obj_BeDeleted(obj)){
			enemyX=GetCommonDataDefault("BossX",0);
			enemyY=GetCommonDataDefault("BossY",0);
			spos=Rotate3D_B(spos,rotq);
			epos=Rotate3D_B(epos,rotq);
			Obj_SetPosition(obj,Perspective(spos[1],spos[3],dis)*expand+enemyX,Perspective(spos[2],spos[3],dis)*expand+enemyY);
			Obj_SetAngle(obj,atan2(Perspective(epos[2],epos[3],dis)*expand+enemyY-Obj_GetY(obj),Perspective(epos[1],epos[3],dis)*expand+enemyX-Obj_GetX(obj)));
			ObjLaser_SetLength(obj,Distance(Obj_GetX(obj),Obj_GetY(obj),Perspective(epos[1],epos[3],dis)*expand+enemyX,Perspective(epos[2],epos[3],dis)*expand+enemyY));
			Obj_SetAlpha(obj,(spos[3]+epos[3])+172);
			yield;
			if(expand<1){expand+=expspd;}
			if(killtime>0){killtime--;}
			if(killtime==0){Obj_Delete(obj);}
		}
	}

	function Distance(xa,ya,xb,yb){
			return(((xa-xb)^2+(ya-yb)^2)^0.5);
	}

task BorderLaser(xangle,yangle,anglePlus)
{
	let R=0;

	let Rmax=100;
	//let anglePlus=0;
	let ExpandTime=60;
	//let xangle=rand(0,360);
	//let yangle=rand(0,360);
	while(1)
	{
		BorderLaserEffect(R,xangle,yangle,anglePlus);
		if(R<Rmax)
		{
		R+=Rmax/ExpandTime;
		}
		anglePlus+=1;
		xangle+=1;
		yangle+=1;
		yield;
	}
}

task BorderLaserEffect(R,xangle,yangle,angle)
{
		let Scale=1.5*R/100;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgIneDeltaLine);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -55, -66);
		ObjEffect_SetVertexXY(obj, 1,55,  -66);
		ObjEffect_SetVertexXY(obj, 2,55, 33);
		ObjEffect_SetVertexXY(obj, 3,  -55,  33);
		
		ObjEffect_SetVertexUV(obj, 0,  8,  13);
		ObjEffect_SetVertexUV(obj, 1,  118, 13);
		ObjEffect_SetVertexUV(obj, 2, 118, 111);
		ObjEffect_SetVertexUV(obj, 3, 8, 111);

		let Alpha=200;
		if(OnPlayerMissed){Alpha=0;}

		let R=255;let G=255;let B=255;

		alternative(GetPlayerInfo(PLAYER_SPEED_HIGH))
		case(4){R=100;G=100;B=255;}
		case(4/2){R=100;G=100;B=255;}
		case(5/2){R=255;G=100;B=100;}
		case(5){R=255;G=100;B=100;}
		case(5.5){R=255;G=100;B=255;}
		case(5.5/5){R=255;G=100;B=255;}
		case(4.5){R=50;G=205;B=50;}
		case(4.5/2){R=50;G=205;B=50;}

		Obj_SetPosition(obj,GetCommonDataDefault("BossX",0),GetCommonDataDefault("BossY",0));
		Obj_SetAngle(obj,angle);
		ObjEffect_SetAngle(obj,xangle,yangle,angle);
		ObjEffect_SetScale(obj,Scale,Scale);

		loop(3)
		{
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		Alpha-=200/3;
		if(OnPlayerMissed){Alpha=0;}
		yield;
		}
		Obj_Delete(obj);
}

task MagicCircleBorder(R,G,B)//円形バーストゲージの表示
{
		let PowerLeft=0;
		let PowerAngle=0;
		let randvertex=0;
		let Vertex=16;
		let Radius=[140,160];
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,imgCircleBorder);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj,Vertex);
		ascent(let i in 0..Vertex)
		{
			ObjEffect_SetVertexXY(obj, i, Radius[i%2]*cos(360/(Vertex-1)*i), Radius[i%2]*sin(360/(Vertex-1)*i));
		}
		ascent(let i in 0..Vertex)
		{	
			ObjEffect_SetVertexUV(obj, i,  256/(Vertex)*i,  7+7*(i%2));
		}

		ObjEffect_SetLayer(obj,3);

		ObjEffect_SetAngle(obj,0,0,180);
		let Alpha=100;

		while(1)
		{

			PowerLeft=360;
			PowerAngle=PowerLeft/(Vertex-2);
			ascent(i in 0..Vertex)
			{
				alternative(i)
				case(0, 1){ObjEffect_SetVertexXY(obj,i,Radius[i%2]*sin(0),Radius[i%2]*cos(0)); }
				case(Vertex-2, Vertex-1){ObjEffect_SetVertexXY(obj,i,Radius[i%2]*sin(PowerLeft),Radius[i%2]*cos(PowerLeft)); }
				others{ObjEffect_SetVertexXY(obj,i,Radius[i%2]*sin(PowerAngle*i),Radius[i%2]*cos(PowerAngle*i));}			
				ObjEffect_SetVertexColor(obj, i,Alpha,255,255,255);
			}

			Obj_SetPosition(obj,GetCommonDataDefault("BossX",0),GetCommonDataDefault("BossY",0));
		yield;
		}
		Obj_Delete(obj);
}

task MagicCircleAppear1(R,G,B,dir)//魔方陣その１
{
		let scale=0.0;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
		ObjEffect_SetTexture(obj,imgBreakCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, scale,scale);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -128, -128);
		ObjEffect_SetVertexXY(obj, 1,  128, -128);
		ObjEffect_SetVertexXY(obj, 2,  128,  128);
		ObjEffect_SetVertexXY(obj, 3, -128,  128);
		
		ObjEffect_SetVertexUV(obj, 0,  256,  256);
		ObjEffect_SetVertexUV(obj, 1,  512, 256);
		ObjEffect_SetVertexUV(obj, 2, 512,  512);
		ObjEffect_SetVertexUV(obj, 3, 256, 512);

		ObjEffect_SetLayer(obj,2);

		let Alpha=50;
		let ColorCount=0;

		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}

		let BossX=GetEnemyX;
		let BossY=GetEnemyY;
		let ScaleAngle=90;
		loop(90)
		{
			ObjEffect_SetScale(obj, scale,scale);
		//	scale+=1/90;
			scale+=(1.05+dir*0.15*cos(ScaleAngle))/90;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			Xangle+=3*dir;
			Yangle+=3;
			Zangle+=RotateAngle;
			Alpha=75+25*dir*cos(ScaleAngle);
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}	
			yield;
		}
		let UVAngle=0;
		if(IsBossExisting)
		{
		while(GetEnemyLife>0)
		{
			scale=1.05+dir*0.15*cos(ScaleAngle);
			ScaleAngle+=1;
			ObjEffect_SetScale(obj, scale,scale);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			Zangle+=RotateAngle;
			Alpha=75+25*dir*cos(ScaleAngle);
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		}
		else
		{
		while(GetCommonDataDefault("BossLife",0)>0)
		{
			scale=1.05+dir*0.15*cos(ScaleAngle);
			ScaleAngle+=1;
			ObjEffect_SetScale(obj, scale,scale);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			Zangle+=RotateAngle;
			Alpha=75+25*dir*cos(ScaleAngle);
			Obj_SetPosition(obj,GetCommonDataDefault("BossX",0),GetCommonDataDefault("BossY",0));	
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		}
		let DisScale=1-scale;
		let count=0;
		if(dir==1)
		{
			BossDefeatEffect(GetCommonDataDefault("BossX",0),GetCommonDataDefault("BossY",0));
		}
		while(GetCommonDataDefault("BossLastAttack",false)==true)
		{
			scale+=DisScale/210;
			ObjEffect_SetScale(obj, scale,scale);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
		//	Xangle+=3*dir;
		//	Yangle+=3+dir*1.5;
			Zangle+=RotateAngle;
			if(IsBossExisting)
			{
				Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
			}
			else
			{
			Obj_SetPosition(obj,GetCommonDataDefault("BossX",0),GetCommonDataDefault("BossY",0));
			}
			BossX=GetEnemyX;
			BossY=GetEnemyY;
			if(count%10==0)
			{
			//	MagicCircleBreak(GetEnemyX+rand(-50,50),GetEnemyY+rand(-50,50),0,0.15);	
			}
			count+=1;
			yield;
		}
		Obj_Delete(obj);
		if(dir==1)
		{
			BossMagicCircleBreak(BossX,BossY,1,1,Zangle,R,G,B);
		}
}

task TrueMagicCircleAppear1(dir)//魔方陣その１
{
		let R;let G;let B;
		let HueCount=0;
		let color=HueDifine(HueCount);
		R=color[0];
		G=color[1];
		B=color[2];
		let scale=0.0;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
		ObjEffect_SetTexture(obj,imgBreakCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, scale,scale);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -128, -128);
		ObjEffect_SetVertexXY(obj, 1,  128, -128);
		ObjEffect_SetVertexXY(obj, 2,  128,  128);
		ObjEffect_SetVertexXY(obj, 3, -128,  128);
		
		ObjEffect_SetVertexUV(obj, 0,  256,  256);
		ObjEffect_SetVertexUV(obj, 1,  512, 256);
		ObjEffect_SetVertexUV(obj, 2, 512,  512);
		ObjEffect_SetVertexUV(obj, 3, 256, 512);

		ObjEffect_SetLayer(obj,2);

		let Alpha=50;
		let ColorCount=0;

		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}

		let BossX=GetEnemyX;
		let BossY=GetEnemyY;
		let ScaleAngle=90;
		loop(90)
		{
		color=HueDifine(HueCount);
		R=color[0];
		G=color[1];
		B=color[2];
			ObjEffect_SetScale(obj, scale,scale);
		//	scale+=1/90;
			scale+=(1.05+dir*0.15*cos(ScaleAngle))/90;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			Xangle+=3*dir;
			Yangle+=3;
			Zangle+=RotateAngle;
			Alpha=75+25*dir*cos(ScaleAngle);
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}	
			HueCount+=3;
			yield;
		}
		let UVAngle=0;

		while(GetCommonDataDefault("BossLife",0)>0)
		{
		color=HueDifine(HueCount);
		R=color[0];
		G=color[1];
		B=color[2];
			scale=1.05+dir*0.15*cos(ScaleAngle);
			ScaleAngle+=1;
			ObjEffect_SetScale(obj, scale,scale);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			Zangle+=RotateAngle;
			Alpha=75+25*dir*cos(ScaleAngle);
			Obj_SetPosition(obj,GetCommonDataDefault("BossX",0),GetCommonDataDefault("BossY",0));	
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			HueCount+=3;
			yield;
		}

		let DisScale=1-scale;
		let count=0;
		if(dir==1)
		{
			TrueBossDefeatEffect(GetCommonDataDefault("BossX",0),GetCommonDataDefault("BossY",0));
		}
		while(GetCommonDataDefault("BossLastAttack",false)==true)
		{
		color=HueDifine(HueCount);
		R=color[0];
		G=color[1];
		B=color[2];
			scale+=DisScale/540;
			ObjEffect_SetScale(obj, scale,scale);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
		//	Xangle+=3*dir;
		//	Yangle+=3+dir*1.5;
			Zangle+=RotateAngle;
			if(IsBossExisting)
			{
				Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
			}
			else
			{
			Obj_SetPosition(obj,GetCommonDataDefault("BossX",0),GetCommonDataDefault("BossY",0));
			}
			BossX=GetEnemyX;
			BossY=GetEnemyY;
			if(count%10==0)
			{
			//	MagicCircleBreak(GetEnemyX+rand(-50,50),GetEnemyY+rand(-50,50),0,0.15);	
			}
			count+=1;
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			HueCount+=3;
			yield;
		}
		Obj_Delete(obj);
		if(dir==1)
		{
			TrueBossMagicCircleBreak(BossX,BossY,1,1,Zangle,HueCount);
		}
}

task TrueBossDefeatEffect(x,y){
/////////////////////////siori
	let color1=240;
	let color2=100;
	let color=0;
	let R=255;let G=255;let B=255;
	alternative(StageProgress)
	case(1){R=0;G=250;B=154;color=100;}
	case(2){R=255;G=100;B=0;color=0;}
	case(3){R=148;G=0;B=211;color=300;}
	case(4){R=0;G=100;B=255;color=230;}
	case(5){R=255;G=255;B=0;color=50;}
	//BossBreakMagicEffect(x,y,R,G,B);
//return;

	TrueBossRayEffectTask;

	task TrueBossRayEffectTask
	{
	let wtime=28;
	let sc=1;
		loop(30)
		{
		loop(4)
		{
		let color=HueDifine(rand_int(0,360));
		let R=color[0];
		let G=color[1];
		let B=color[2];
		let Angle=[rand(-70,70),rand(-70,70),rand(0,360)];
		let Speed=rand(-1.5,1.5);
		LightRay(x,y,Angle,Speed,sc,90,30,0,[R,G,B]);
		loop(5)
		{
		TrueBossDefestMagicEffect(x,y,R,G,B);
		}
		}
		wait(wtime);
		wtime-=1;
		sc+=0.15;
		}


	}

	let Angle=[0,0,0];
	let Speed=0;
	let delay=[0,20,35,45];
/*
	ascent(i in 0..4)
	{
		loop(4)
		{
		Angle=[rand(-70,70),rand(-70,70),rand(0,360)];
		Speed=rand(-1.5,1.5);
		LightRay(x,y,Angle,Speed,2,70-delay[i],90,delay[i],[(255+R)/2,(255+G)/2,(255+B)/2]);
		}
	}
*/
	sub CExplode
	{
		let waittime=15;
		let colors=HueDifine(rand_int(0,360));
		let size=5;
		loop(75)
		{
			TrueBossDefeatMagicExplosion(x,y,1,colors,60,60);

			CircleExplosion(x,y,size,colors,60,20);
			wait(waittime);
			waittime-=15/60;
			colors=HueDifine(rand_int(0,360));
		}
	}

	CExplode;

	wait(55);

//	wait(120);

	ascent(i in 0..15)
	{
		color=rand_int(0,360);
		Angle=[rand(-70,70),rand(-70,70),rand(0,360)];
		Speed=rand(-1.5,1.5);
		LightRay(x,y,Angle,Speed,rand(4,6),i*5+30,60,i,HueDifine(color+rand(-20,20)));
		Angle=[rand(-70,70),rand(-70,70),rand(0,360)];
		Speed=rand(-1.5,1.5);
		LightRay(x,y,Angle+[0,0,180],Speed,rand(4,6),i*5+30,60,i,HueDifine(color+rand(-20,20)));
	}
	TrueBossExplode(x,y,R,G,B);
	ScreenShake(3,180);

	wait(180);
}

task TrueBossExplode(x,y,R,G,B)
{
	let color=HueDifine(rand_int(0,360));
	let R=color[0];
	let G=color[1];
	let B=color[2];
	let expand=8;
	let frame=0;
	loop(180)
	{
		color=HueDifine(rand_int(0,360));
		 R=color[0];
		G=color[1];
		B=color[2];
		EnemyExplosion(x,y,0.1,[(rand(0,765)+R)/4,(rand(0,765)+G)/4,(rand(0,765)+B)/4],expand*rand(0.3,1),frame%2,15);
		TrueBossDefeatMagicExplosion(x,y,expand/8*0.75,color,60,60);
		expand-=8/180;
		frame++;
		yield;
	}
}

task TrueBossDefestMagicEffect(x,y,R,G,B)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let Alpha=250;
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		let Scale=rand(0.25,0.75);
		let StandardScale=Scale;
		//if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){Obj_Delete(obj);return;}

		Obj_SetPosition(obj,x,y);
		let ContX=[GetCenterX+rand(-450,450),GetCenterX+rand(-450,450)];
		let ContY=[GetCenterY-120+rand(-450,450),GetCenterY-120+rand(-450,450)];
		let EndX=GetCenterX+rand(-200,200);
		let EndY=GetCenterY+rand(-250,250);
		if(rand_int(0,1)==0)
		{
			EndX+=rand(-50,50);
			EndY+=rand(-50,50);
		}
		let time=rand_int(50,150);
		Obj_SetMovePositionBezier(obj,ContX,ContY,EndX,EndY,time);
		let HueCount=rand_int(0,360);
		let color=[];
		loop(time)
		{
			color=HueDifine(HueCount);
			ObjEffect_SetScale(obj, Scale,Scale);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,(color[0]+R*9)/10,(color[1]+G*9)/10,(color[2]+B*9)/10);
			}
		//	Scale-=StandardScale/90;
			Alpha-=150/time;
			HueCount+=6;
			yield;
		}
		Obj_Delete(obj);
}

task TrueBossMagicCircleBreak(x,y,type,scale,Zangle,HueCount)
{
	//if(GetCommonDataDefault("LightMode",0)==1){return;}
	ascent(i in 0..36)
	{
	TrueBossMagicCircleBreakEffect(x,y,type,scale*1.2,Zangle+i*10,HueCount);
	}
}

task TrueBossMagicCircleBreakEffect(x,y,type,scale,angle,HueCount)
{
	let r=128;
	let way=36;

	let X=[0,0,0,0,0,0,0,0,0,0];
	let Y=[0,0,0,0,0,0,0,0,0,0];
	X[0]=0;
	X[1]=r/3*cos(angle);
	X[2]=r/3*cos(angle+360/way);
	X[3]=r*2/3*cos(angle);
	X[4]=r*2/3*cos(angle+180/way);
	X[5]=r*2/3*cos(angle+360/way);
	X[6]=r*cos(angle);
	X[7]=r*cos(angle+120/way);
	X[8]=r*cos(angle+240/way);
	X[9]=r*cos(angle+360/way);

	Y[0]=0;
	Y[1]=r/3*sin(angle);
	Y[2]=r/3*sin(angle+360/way);
	Y[3]=r*2/3*sin(angle);
	Y[4]=r*2/3*sin(angle+180/way);
	Y[5]=r*2/3*sin(angle+360/way);
	Y[6]=r*sin(angle);
	Y[7]=r*sin(angle+120/way);
	Y[8]=r*sin(angle+240/way);
	Y[9]=r*sin(angle+360/way);

	TrueBossMagicCircleBreakEffectTriangle(x,y,X[0],X[1],X[2],Y[0],Y[1],Y[2],type,scale,HueCount);
	TrueBossMagicCircleBreakEffectTriangle(x,y,X[1],X[3],X[4],Y[1],Y[3],Y[4],type,scale,HueCount);
	TrueBossMagicCircleBreakEffectTriangle(x,y,X[2],X[4],X[5],Y[2],Y[4],Y[5],type,scale,HueCount);
	TrueBossMagicCircleBreakEffectTriangle(x,y,X[1],X[2],X[4],Y[1],Y[2],Y[4],type,scale,HueCount);

	TrueBossMagicCircleBreakEffectTriangle(x,y,X[3],X[6],X[7],Y[3],Y[6],Y[7],type,scale,HueCount);
	TrueBossMagicCircleBreakEffectTriangle(x,y,X[3],X[4],X[7],Y[3],Y[4],Y[7],type,scale,HueCount);
	TrueBossMagicCircleBreakEffectTriangle(x,y,X[4],X[7],X[8],Y[4],Y[7],Y[8],type,scale,HueCount);
	TrueBossMagicCircleBreakEffectTriangle(x,y,X[4],X[5],X[8],Y[4],Y[5],Y[8],type,scale,HueCount);
	TrueBossMagicCircleBreakEffectTriangle(x,y,X[5],X[8],X[9],Y[5],Y[8],Y[9],type,scale,HueCount);

}

task TrueBossMagicCircleBreakEffectTriangle(x,y,x1,x2,x3,y1,y2,y3,type,scale,HueCount)
{
		let color=HueDifine(HueCount);
		let R=color[0];
		let G=color[1];
		let B=color[2];
		let CX=384;
		let CY=384;
		if(type==2){CY=128;}
		let TriCX=(x1+x2+x3)/3;
		let TriCY=(y1+y2+y3)/3;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBreakCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 3);
		ObjEffect_SetVertexXY(obj, 0, x1-TriCX, y1-TriCY);
		ObjEffect_SetVertexXY(obj, 1, x2-TriCX, y2-TriCY);
		ObjEffect_SetVertexXY(obj, 2, x3-TriCX, y3-TriCY);
		
		ObjEffect_SetVertexUV(obj, 0,  x1+CX,  y1+CY);
		ObjEffect_SetVertexUV(obj, 1,  x2+CX, y2+CY);
		ObjEffect_SetVertexUV(obj, 2, x3+CX,  y3+CY);

		ObjEffect_SetLayer(obj,7);

		ascent(let i in 0..3)
		{
		ObjEffect_SetVertexColor(obj,i,255,R,G,B);
		}

Obj_SetPosition(obj,x+TriCX*scale,y+TriCY*scale);

ObjEffect_SetScale(obj, scale,scale);

		let Sscale=scale;
		let speed=((TriCX)^2+(TriCY)^2)^0.5*0.05/3*rand(0.85,1.15);
		let Angle=atan2(TriCY,TriCX);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,Angle);

		let Xangle=rand(0,360);
		let Yangle=rand(0,360);
		let Zangle=rand(0,360);
		let XangleRotate=rand(-10,10);
		let YangleRotate=rand(-10,10);
		let ZangleRotate=rand(-10,10);

		loop(120)
		{
			color=HueDifine(HueCount);
			R=color[0];
			G=color[1];
			B=color[2];
		ascent(let i in 0..3)
		{
		ObjEffect_SetVertexColor(obj,i,255,R,G,B);
		}
			ObjEffect_SetScale(obj, scale,scale);
			scale-=Sscale/240;
			Xangle+=XangleRotate;
			Yangle+=YangleRotate;
			Zangle+=ZangleRotate;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			yield;
		}

		loop(30)
		{
			color=HueDifine(HueCount);
			R=color[0];
			G=color[1];
			B=color[2];
		ascent(let i in 0..3)
		{
		ObjEffect_SetVertexColor(obj,i,255,R,G,B);
		}
			ObjEffect_SetScale(obj, scale,scale);
			scale-=Sscale/120;
			Xangle+=XangleRotate;
			Yangle+=YangleRotate;
			Zangle+=ZangleRotate;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			yield;
		}
		if(GetCommonDataDefault("MSDPlayer",false)==true)
		{
			ItemSet(Obj_GetX(obj),Obj_GetY(obj),100+6);
		}

		Obj_Delete(obj);

}

task BossMagicCircleBreak(x,y,type,scale,Zangle,R,G,B)
{
	//if(GetCommonDataDefault("LightMode",0)==1){return;}
	ascent(i in 0..36)
	{
	BossMagicCircleBreakEffect(x,y,type,scale*1.2,Zangle+i*10,R,G,B);
	}
}

task BossMagicCircleBreakEffect(x,y,type,scale,angle,R,G,B)
{
	let r=128;
	let way=36;

	let X=[0,0,0,0,0,0,0,0,0,0];
	let Y=[0,0,0,0,0,0,0,0,0,0];
	X[0]=0;
	X[1]=r/3*cos(angle);
	X[2]=r/3*cos(angle+360/way);
	X[3]=r*2/3*cos(angle);
	X[4]=r*2/3*cos(angle+180/way);
	X[5]=r*2/3*cos(angle+360/way);
	X[6]=r*cos(angle);
	X[7]=r*cos(angle+120/way);
	X[8]=r*cos(angle+240/way);
	X[9]=r*cos(angle+360/way);

	Y[0]=0;
	Y[1]=r/3*sin(angle);
	Y[2]=r/3*sin(angle+360/way);
	Y[3]=r*2/3*sin(angle);
	Y[4]=r*2/3*sin(angle+180/way);
	Y[5]=r*2/3*sin(angle+360/way);
	Y[6]=r*sin(angle);
	Y[7]=r*sin(angle+120/way);
	Y[8]=r*sin(angle+240/way);
	Y[9]=r*sin(angle+360/way);

	BossMagicCircleBreakEffectTriangle(x,y,X[0],X[1],X[2],Y[0],Y[1],Y[2],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[1],X[3],X[4],Y[1],Y[3],Y[4],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[2],X[4],X[5],Y[2],Y[4],Y[5],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[1],X[2],X[4],Y[1],Y[2],Y[4],type,scale,R,G,B);

	BossMagicCircleBreakEffectTriangle(x,y,X[3],X[6],X[7],Y[3],Y[6],Y[7],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[3],X[4],X[7],Y[3],Y[4],Y[7],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[4],X[7],X[8],Y[4],Y[7],Y[8],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[4],X[5],X[8],Y[4],Y[5],Y[8],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[5],X[8],X[9],Y[5],Y[8],Y[9],type,scale,R,G,B);

}

task BossMagicCircleBreakEffectTriangle(x,y,x1,x2,x3,y1,y2,y3,type,scale,R,G,B)
{
		let CX=384;
		let CY=384;
		if(type==2){CY=128;}
		let TriCX=(x1+x2+x3)/3;
		let TriCY=(y1+y2+y3)/3;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBreakCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 3);
		ObjEffect_SetVertexXY(obj, 0, x1-TriCX, y1-TriCY);
		ObjEffect_SetVertexXY(obj, 1, x2-TriCX, y2-TriCY);
		ObjEffect_SetVertexXY(obj, 2, x3-TriCX, y3-TriCY);
		
		ObjEffect_SetVertexUV(obj, 0,  x1+CX,  y1+CY);
		ObjEffect_SetVertexUV(obj, 1,  x2+CX, y2+CY);
		ObjEffect_SetVertexUV(obj, 2, x3+CX,  y3+CY);

		ObjEffect_SetLayer(obj,7);

		ascent(let i in 0..3)
		{
		ObjEffect_SetVertexColor(obj,i,255,R,G,B);
		}

Obj_SetPosition(obj,x+TriCX*scale,y+TriCY*scale);

ObjEffect_SetScale(obj, scale,scale);

		let Sscale=scale;
		let speed=((TriCX)^2+(TriCY)^2)^0.5*0.05/3*rand(0.85,1.15);
		let Angle=atan2(TriCY,TriCX);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,Angle);

		let Xangle=rand(0,360);
		let Yangle=rand(0,360);
		let Zangle=rand(0,360);
		let XangleRotate=rand(-10,10);
		let YangleRotate=rand(-10,10);
		let ZangleRotate=rand(-10,10);

		loop(120)
		{
			ObjEffect_SetScale(obj, scale,scale);
			scale-=Sscale/240;
			Xangle+=XangleRotate;
			Yangle+=YangleRotate;
			Zangle+=ZangleRotate;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			yield;
		}

		loop(30)
		{
			ObjEffect_SetScale(obj, scale,scale);
			scale-=Sscale/120;
			Xangle+=XangleRotate;
			Yangle+=YangleRotate;
			Zangle+=ZangleRotate;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			yield;
		}
		if(GetCommonDataDefault("TrueBossFlag",false)==false)
		{
			if(GetCommonDataDefault("MSDPlayer",false)==true)
			{
			ItemSet(Obj_GetX(obj),Obj_GetY(obj),100+StageProgress);
			}
		}
		else
		{
			TrueBossMagicEffect(Obj_GetX(obj),Obj_GetY(obj),R,G,B);
		}
		Obj_Delete(obj);

}


task TrueBossMagicEffect(x,y,R,G,B)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let Alpha=250;
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		let Scale=rand(0.25,0.75);
		let StandardScale=Scale;
		//if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){Obj_Delete(obj);return;}

		Obj_SetPosition(obj,x,y);
		let ContX=[GetCenterX+rand(-450,450),GetCenterX+rand(-450,450)];
		let ContY=[GetCenterY-120+rand(-450,450),GetCenterY-120+rand(-450,450)];
		let EndX=GetCenterX;
		let EndY=GetCenterY-120;
		if(rand_int(0,1)==0)
		{
			EndX+=rand(-50,50);
			EndY+=rand(-50,50);
		}
		let time=rand_int(50,150);
		Obj_SetMovePositionBezier(obj,ContX,ContY,EndX,EndY,time);
		let HueCount=rand_int(0,360);
		let color=[];
		loop(time)
		{
			color=HueDifine(HueCount);
			ObjEffect_SetScale(obj, Scale,Scale);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,(color[0]+R*9)/10,(color[1]+G*9)/10,(color[2]+B*9)/10);
			}
		//	Scale-=StandardScale/90;
			Alpha-=150/time;
			HueCount+=6;
			yield;
		}
		Obj_Delete(obj);
}

task TrueBossDefeatMagicExplosion(x,y,size,color,time,fadeintime)
{
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgEffects);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);

	ObjEffect_SetLayer(obj,2);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ADD);

	ObjEffect_SetVertexUV(obj, 0, 128, 0);
	ObjEffect_SetVertexUV(obj, 1, 256, 0);
	ObjEffect_SetVertexUV(obj, 2, 256, 128);
	ObjEffect_SetVertexUV(obj, 3, 128, 128);

	ObjEffect_SetVertexXY(obj, 0, -64, -64);
	ObjEffect_SetVertexXY(obj, 1, 64,  -64);
	ObjEffect_SetVertexXY(obj, 2,  64,  64);
	ObjEffect_SetVertexXY(obj, 3,  -64, 64);

	Obj_SetPosition(obj, x,y);
	let Alpha=100*time/60;
	let Xangle=rand(0,360);
	let Yangle=rand(0,360);
	let Zangle=rand(0,360);
	ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

	let Xsize=0;
	let Ysize=0;
	let SizePlus=rand(0.2,0.4)*time/60;
	let alphaPlus=100/fadeintime*time/60;
	let frame=0;
	let dir=rand_int(0,1)*2-1;
	loop(time)
	{
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
		ObjEffect_SetScale(obj,Xsize,Ysize);
		if(Alpha>0)
		{
			Alpha-=alphaPlus;
		}
		Xsize+=SizePlus;
		Ysize+=SizePlus;
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,color[0],color[1],color[2]);
		}
		frame++;
		yield;
	}
	Obj_Delete(obj);
}

task BossConcentEffect(R,G,B)
{
	let Radius1=180;
	let Radius2=120;
	let Angle=rand(0,360);
		ascent(i in 0..4)
		{
			BossMagicEffect(R,G,B,Radius1,Radius2,Angle+i*90,1);
			BossMagicEffect(R,G,B,Radius1,Radius2,-Angle+i*90+45,-1);
		}
}

task BossMagicEffect(R,G,B,Radius1,Radius2,Angle,dir)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let Alpha=100*0;
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		let Scale=rand(1.0,2.0);
		let StandardScale=Scale;
		//if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){Obj_Delete(obj);return;}
		let StandardRadius1=Radius1;
		let StandardRadius2=Radius2;
		let X;
		let Y;
		let GradAngle=30*dir;
		loop(90)
		{
			X=GetEnemyX+Radius1*cos(GradAngle)*cos(Angle)-Radius2*sin(GradAngle)*sin(Angle);
			Y=GetEnemyY+Radius1*sin(GradAngle)*cos(Angle)+Radius2*cos(GradAngle)*sin(Angle);
			BossMagicEffectBlur(Obj_GetX(obj),Obj_GetY(obj),R,G,B,Angle,Scale);
			ObjEffect_SetScale(obj, Scale,Scale);
			Obj_SetPosition(obj,X,Y);
			Radius1-=StandardRadius1/90;
			Radius2-=StandardRadius2/90;
			Scale-=StandardScale/90;
			Angle+=3*dir;
			yield;
		}
		Obj_Delete(obj);
}


task BossMagicEffectBlur(x,y,R,G,B,Angle,Scale)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let Alpha=100;
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		let StandardScale=Scale;
		loop(30)
		{
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			ObjEffect_SetScale(obj, Scale,Scale);
			Scale-=StandardScale/30;
			Alpha-=100/30;
			yield;
		}
		Obj_Delete(obj);
}

task TrueBossConcentAppearEffect
{
	let R;let G;let B;
	let HueCount=0;
	let color=HueDifine(HueCount);
	R=color[0];
	G=color[1];
	B=color[2];
	let Radius1=180;
	let Radius2=120;
	let Angle=rand(0,360);
		ascent(i in 0..4)
		{
			TrueBossMagicAppearEffect(Radius1,Radius2,Angle+i*90,1);
			TrueBossMagicAppearEffect(Radius1,Radius2,-Angle+i*90+45,-1);
		}
}

task TrueBossMagicAppearEffect(Radius1,Radius2,Angle,dir)
{
	let R;let G;let B;
	let HueCount=rand(0,360);
	let color=HueDifine(HueCount);
	R=color[0];
	G=color[1];
	B=color[2];
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let Alpha=100*0;
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		let Scale=rand(1.0,2.0);
		let StandardScale=Scale;
		//if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){Obj_Delete(obj);return;}
		let StandardRadius1=Radius1;
		let StandardRadius2=Radius2;
		let X;
		let Y;
		let GradAngle=30*dir;
		loop(90)
		{
	color=HueDifine(HueCount);
	R=color[0];
	G=color[1];
	B=color[2];
			X=GetEnemyX+Radius1*cos(GradAngle)*cos(Angle)-Radius2*sin(GradAngle)*sin(Angle);
			Y=GetEnemyY+Radius1*sin(GradAngle)*cos(Angle)+Radius2*cos(GradAngle)*sin(Angle);
			TrueBossMagicAppearEffectBlur(Obj_GetX(obj),Obj_GetY(obj),R,G,B,Angle,Scale);
			ObjEffect_SetScale(obj, Scale,Scale);
			Obj_SetPosition(obj,X,Y);
			Radius1-=StandardRadius1/90;
			Radius2-=StandardRadius2/90;
			Scale-=StandardScale/90;
			Angle+=3*dir;
			HueCount+=3;
			yield;
		}
		Obj_Delete(obj);
}


task TrueBossMagicAppearEffectBlur(x,y,R,G,B,Angle,Scale)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let Alpha=100;
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		let StandardScale=Scale;
		loop(30)
		{
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			ObjEffect_SetScale(obj, Scale,Scale);
			Scale-=StandardScale/30;
			Alpha-=100/30;
			yield;
		}
		Obj_Delete(obj);
}

task BossBreakMagicEffect(x,y,R,G,B)
{
wait(120);
loop(45)
{
	DrawBossBreakMagicEffect(R,G,B);
}
wait(60);
let time=60;
loop(60)
{
MagicExplosion(x,y,1,[R,G,B],time,time);
time-=1;
yield;
}

}

task DrawBossBreakMagicEffect(R,G,B)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let Alpha=250;
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		let Scale=rand(0.25,0.75);
		let StandardScale=Scale;
		//if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){Obj_Delete(obj);return;}

		Obj_SetPosition(obj,GetEnemyX+rand(-100,100),GetEnemyY+rand(-100,100));
		let ContX=[GetEnemyX+rand(-250,250),GetEnemyX+rand(-250,250)];
		let ContY=[GetEnemyY+rand(-250,250),GetEnemyY+rand(-250,250)];
		let EndX=GetEnemyX;
		let EndY=GetEnemyY;
		if(rand_int(0,1)==0)
		{
			EndX+=rand(-150,150);
			EndY+=rand(-150,150);
		}
		Obj_SetMovePositionBezier(obj,ContX,ContY,EndX,EndY,60);
		loop(60)
		{
			ObjEffect_SetScale(obj, Scale,Scale);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
		//	Scale-=StandardScale/90;
			Alpha-=150/60;
			yield;
		}
		Obj_Delete(obj);
}

task MagicExplosion(x,y,size,color,time,fadeintime)
{
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgEffects);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);

	ObjEffect_SetLayer(obj,2);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ADD);

	ObjEffect_SetVertexUV(obj, 0, 128, 0);
	ObjEffect_SetVertexUV(obj, 1, 256, 0);
	ObjEffect_SetVertexUV(obj, 2, 256, 128);
	ObjEffect_SetVertexUV(obj, 3, 128, 128);

	ObjEffect_SetVertexXY(obj, 0, -64, -64);
	ObjEffect_SetVertexXY(obj, 1, 64,  -64);
	ObjEffect_SetVertexXY(obj, 2,  64,  64);
	ObjEffect_SetVertexXY(obj, 3,  -64, 64);

	Obj_SetPosition(obj, x,y);
	let Alpha=100*time/60;
	let Xangle=rand(0,360);
	let Yangle=rand(0,360);
	let Zangle=rand(0,360);
	ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

	let Xsize=0;
	let Ysize=0;
	let SizePlus=rand(0.2,0.4)*time/60;
	let alphaPlus=100/fadeintime*time/60;
	let frame=0;
	let dir=rand_int(0,1)*2-1;
	loop(time)
	{
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
		ObjEffect_SetScale(obj,Xsize,Ysize);
		if(Alpha>0)
		{
			Alpha-=alphaPlus;
		}
		Xsize+=SizePlus;
		Ysize+=SizePlus;
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,color[0],color[1],color[2]);
		}
		frame++;
		yield;
	}
	Obj_Delete(obj);
}

////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
task BossDefeatEffect(x,y){

	let color1=240;
	let color2=100;
	let color=0;
	let R=255;let G=255;let B=255;
	alternative(StageProgress)
	case(1){R=0;G=250;B=154;color=100;}
	case(2){R=255;G=100;B=0;color=0;}
	case(3){R=148;G=0;B=211;color=300;}
	case(4){R=0;G=100;B=255;color=230;}
	case(5){R=255;G=255;B=0;color=50;}
	BossBreakMagicEffect(x,y,R,G,B);
//return;
	let Angle=[0,0,0];
	let Speed=0;
	let delay=[0,20,35,45];
	ascent(i in 0..4)
	{
		loop(4)
		{
		Angle=[rand(-70,70),rand(-70,70),rand(0,360)];
		Speed=rand(-1.5,1.5);
		LightRay(x,y,Angle,Speed,2,70-delay[i],90,delay[i],[(510+R)/3,(510+G)/3,(510+B)/3]);
		}
	}

	task CExplode
	{
		let waittime=8;
		let colors=[255,255,255];
		let colorsPlus=-64;

		loop(15)
		{
			loop(1)
			{
			wait(waittime);
			CircleExplosion(x,y,rand(2.5,3.5),colors,waittime*3,waittime);
			}
		//	waittime-=1;
			colors+=[colorsPlus,colorsPlus,colorsPlus];
			colorsPlus/=2;
		}
	}

	CExplode;
	wait(180);
//	wait(120);

	ascent(i in 0..15)
	{
		Angle=[rand(-70,70),rand(-70,70),rand(0,360)];
		Speed=rand(-1.5,1.5);
		LightRay(x,y,Angle,Speed,rand(3,4),i*5+30,60,i,HueDifine(color+rand(-20,20)));
		Angle=[rand(-70,70),rand(-70,70),rand(0,360)];
		Speed=rand(-1.5,1.5);
		LightRay(x,y,Angle+[0,0,180],Speed,rand(3,4),i*5+30,60,i,HueDifine(color+rand(-20,20)));
	}
	BossExplode(x,y,R,G,B);
	ScreenShake(3,180);
	wait(180);
	if(GetCommonDataDefault("TrueBossFlag",false)==false)
	{

	}
	else
	{
		TrueBossAppear;
	}
}

task TrueBossAppear
{
let time=30;
let dir=rand_int(0,1)*2-1;
let HueCount=rand(0,360);
let angle=rand(0,360);
let grad1=rand(20,40);
let grad2=rand(20,40);
ascent(i in 0..7)
{
TrueBossConcentEffect(HueCount+i*360/7,240,130,angle+i*360/7,grad1,1);
TrueBossConcentEffect(HueCount+i*360/7,240,130,angle+i*360/7+360/14,grad2,-1);
}
wait(120);
TrueBossWhiteStart;
loop(120)
{
TrueBossMagicExplosion(GetCenterY,GetCenterY-120,1,HueDifine(HueCount),60,60);
HueCount+=6;
wait(1);
}
let time=60;
loop(270)
{
TrueBossMagicExplosion(GetCenterY,GetCenterY-120,1,HueDifine(HueCount),time,time);
HueCount+=6;
time-=60/270;
wait(1);
}
}

task TrueBossWhiteStart
{
wait(30);
TrueBossWhite;
wait(120);
Stage5Phase=4;
}

task TrueBossConcentEffect(HueCount,Radius1,Radius2,Angle,GradAngle,dir)
{
		let color=[0,0,0];

		let R=color[0];
		let G=color[1];
		let B=color[2];
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let Alpha=100*0;
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		let Scale=rand(4.0,4.0);
		let StandardScale=Scale;
		//if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){Obj_Delete(obj);return;}
		let StandardRadius1=Radius1;
		let StandardRadius2=Radius2;
		let X;
		let Y;
		GradAngle*=dir;
		loop(120)
		{
			color=HueDifine(HueCount);
			R=color[0];
			G=color[1];
			B=color[2];
			X=GetCenterX+Radius1*cos(Angle);
			Y=GetCenterY-120+Radius1*sin(Angle);
			X=GetCenterX+Radius1*cos(GradAngle)*cos(Angle)-Radius2*sin(GradAngle)*sin(Angle);
			Y=GetCenterY-120+Radius1*sin(GradAngle)*cos(Angle)+Radius2*cos(GradAngle)*sin(Angle);
			TrueBossConcentEffectBlur(Obj_GetX(obj),Obj_GetY(obj),R,G,B,Angle,Scale);
			ObjEffect_SetScale(obj, Scale,Scale);
			Obj_SetPosition(obj,X,Y);
			Radius1-=StandardRadius1/120;
			Radius2-=StandardRadius2/120;
			Scale-=StandardScale/120;
			Angle+=3*dir;
			HueCount+=6;
			GradAngle+=0.1*dir;
			yield;
		}
		Obj_Delete(obj);
}


task TrueBossConcentEffectBlur(x,y,R,G,B,Angle,Scale)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let Alpha=100;
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		let StandardScale=Scale;
		loop(30)
		{
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			ObjEffect_SetScale(obj, Scale,Scale);
			Scale-=StandardScale/30;
			Alpha-=100/30;
			yield;
		}
		Obj_Delete(obj);
}

task TrueBossMagicExplosion(x,y,size,color,time,fadeintime)
{
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgEffects);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);

	ObjEffect_SetLayer(obj,2);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ADD);

	ObjEffect_SetVertexUV(obj, 0, 128, 0);
	ObjEffect_SetVertexUV(obj, 1, 256, 0);
	ObjEffect_SetVertexUV(obj, 2, 256, 128);
	ObjEffect_SetVertexUV(obj, 3, 128, 128);

	ObjEffect_SetVertexXY(obj, 0, -64, -64);
	ObjEffect_SetVertexXY(obj, 1, 64,  -64);
	ObjEffect_SetVertexXY(obj, 2,  64,  64);
	ObjEffect_SetVertexXY(obj, 3,  -64, 64);

	Obj_SetPosition(obj, x,y);
	let Alpha=100*time/60;
	let Xangle=rand(0,360);
	let Yangle=rand(0,360);
	let Zangle=rand(0,360);
	ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

	let Xsize=0;
	let Ysize=0;
	let SizePlus=rand(0.2,0.4)*time/60*1.5;
	let alphaPlus=100/fadeintime*time/60;
	let frame=0;
	let dir=rand_int(0,1)*2-1;
	loop(time)
	{
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
		ObjEffect_SetScale(obj,Xsize,Ysize);
		if(Alpha>0)
		{
			Alpha-=alphaPlus;
		}
		Xsize+=SizePlus;
		Ysize+=SizePlus;
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,color[0],color[1],color[2]);
		}
		frame++;
		yield;
	}
	Obj_Delete(obj);
}

task TrueBossAppearEffect(graphic,angle,dir)
{
	let R;let G;let B;
		if(graphic%7==0){R=255;G=0;B=0;}
		if(graphic%7==1){R=255;G=165;B=0;}
		if(graphic%7==2){R=255;G=255;B=0;}
		if(graphic%7==3){R=0;G=255;B=0;}
		if(graphic%7==4){R=0;G=255;B=255;}
		if(graphic%7==5){R=0;G=0;B=255;}
		if(graphic%7==6){R=160;G=32;B=240;}

		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMagicEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  40, 0);
		ObjEffect_SetVertexUV(obj, 2, 40,  40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);
		
		let Alpha=150;
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetLayer(obj,3);
		let Scale=rand(0.25,0.25);
		let StandardScale=Scale;
	
		let Radius=200;

		Obj_SetPosition(obj,GetCenterX+Radius*cos(angle),GetCenterY-120+Radius*sin(angle));

		loop(45)
		{
			Obj_SetPosition(obj,GetCenterX+Radius*cos(angle),GetCenterY-120+Radius*sin(angle));
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			Radius-=200/45;
			angle+=3.5*dir;
		//	Scale-=StandardScale/90;
			Alpha-=150/60;
			yield;
		}
		Obj_Delete(obj);
}

task TrueBossWhite
{
		let scx=1;
		let scy=1;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgWhite);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1,192,  -224);
		ObjEffect_SetVertexXY(obj, 2,192, 224);
		ObjEffect_SetVertexXY(obj, 3,  -192,  224);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  10, 0);
		ObjEffect_SetVertexUV(obj, 2, 10, 10);
		ObjEffect_SetVertexUV(obj, 3, 0, 10);

		let Xangle=0;
		let Yangle=180;
		let Zangle=0;

		let Alpha=0;

		ObjEffect_SetLayer(obj,7);
		Obj_SetPosition(obj,GetCenterX,GetCenterY);

		ObjEffect_SetScale(obj, scx,scy);

		loop(90)
		{
			Alpha+=255/90;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, scx,scy);
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			yield;
		}
		wait(90);
		loop(90)
		{
			Alpha-=255/90;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, scx,scy);
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			yield;
		}
}

task BossExplode(x,y,R,G,B)
{
	let expand=8;
	let frame=0;
	loop(150)
	{
		EnemyExplosion(x,y,0.1,[(rand(0,765)+R)/4,(rand(0,765)+G)/4,(rand(0,765)+B)/4],expand*rand(0.3,1),frame%2,15);
		expand-=8/210;
		frame++;
		yield;
	}
	loop(30)
	{
		EnemyExplosion(x,y,0.1,[(rand(0,765)+R)/4,(rand(0,765)+G)/4,(rand(0,765)+B)/4],expand*rand(0.3,1),frame%2,15);
		expand-=8/210*2;
		frame++;
		yield;
	}
}

task LightRay(x,y,angle,rotspeed,maxscale,time,fadetime,delay,color)
{
	wait(delay);

	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgEffects);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetRenderState(obj,ADD); 

	ObjEffect_SetVertexXY(obj, 0, 0, -17);
	ObjEffect_SetVertexXY(obj, 1, 92,  -17);
	ObjEffect_SetVertexXY(obj, 2, 92, 17);
	ObjEffect_SetVertexXY(obj, 3,  0, 17);

	ObjEffect_SetVertexUV(obj, 0,  1,  3);
	ObjEffect_SetVertexUV(obj, 1,  93, 3);
	ObjEffect_SetVertexUV(obj, 2, 93,  38);
	ObjEffect_SetVertexUV(obj, 3, 1, 38);

	ObjEffect_SetLayer(obj,2);

	let scale=0;
	let rotation=0;
	let alpha=250;
	if(maxscale>=3)
	{
		alpha=100;
	}
	let ThetaAngle=rand(0,360);
	let alphaTheta=0.9+0.1*cos(ThetaAngle);
	loop(time)
	{
		Obj_SetPosition(obj,x+ScreenShakeX,y+ScreenShakeY);
		angle=angle+[0,0,rotspeed];

		ObjEffect_SetAngle(obj,angle[0],angle[1],angle[2]);
		if(scale<1)
		{
			scale+=1/15;
		}
		ObjEffect_SetScale(obj,scale*maxscale,maxscale*0.5);
		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,alpha*alphaTheta,color[0],color[1],color[2]);
		}
		alphaTheta=0.9+0.1*cos(ThetaAngle);
		ThetaAngle+=6;
		yield;
	}
	let Balpha=alpha;
	loop(fadetime)
	{
		Obj_SetPosition(obj,x+ScreenShakeX,y+ScreenShakeY);
		angle=angle+[0,0,rotspeed];

		ObjEffect_SetAngle(obj,angle[0],angle[1],angle[2]);
		alpha-=Balpha/fadetime;

		if(scale<1)
		{
			scale+=1/10;
		}
		ObjEffect_SetScale(obj,scale*maxscale,maxscale*0.5);
		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,alpha*alphaTheta,color[0],color[1],color[2]);
		}
		alphaTheta=0.9+0.1*cos(ThetaAngle);
		ThetaAngle+=6;
		yield;
	}
Obj_Delete(obj);

}


task EnemyExplosion(x,y,scale,color,scalePlus,type,frames)
{
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgEffects);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ADD);

	ObjEffect_SetVertexUV(obj, 0, 0, 40);
	ObjEffect_SetVertexUV(obj, 1, 50, 40);
	ObjEffect_SetVertexUV(obj, 2, 50, 90);
	ObjEffect_SetVertexUV(obj, 3, 0, 90);
	ObjEffect_SetVertexXY(obj, 0, -15, -15);
	ObjEffect_SetVertexXY(obj, 1, 15,  -15);
	ObjEffect_SetVertexXY(obj, 2,  15,  15);
	ObjEffect_SetVertexXY(obj, 3,  -15, 15);

	Obj_SetPosition   (obj, x,y);
	Obj_SetSpeed      (obj, 0);

	ObjEffect_SetScale(obj,1,1);
	if(type==0)
	{
		ObjEffect_SetAngle(obj,rand(-80,80),rand(-80,80),rand(0,360));
	}
	else
	{
		ObjEffect_SetAngle(obj,0,0,rand(0,360));
	}

	ObjEffect_SetLayer(obj,2);


	let alpha=240;
	loop(frames)
	{
		Obj_SetPosition(obj,x+ScreenShakeX,y+ScreenShakeY);
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,alpha,color[0],color[1],color[2]);
		}
		ObjEffect_SetScale(obj,scale/2,scale/2);
		alpha-=240/frames;
		scale+=scalePlus*2;
		wait(1);
	}
	Obj_Delete(obj);
}


task CircleExplosion(x,y,size,color,time,fadeintime)
{
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgEffects);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);

	ObjEffect_SetLayer(obj,2);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ADD);

	ObjEffect_SetVertexUV(obj, 0, 128, 0);
	ObjEffect_SetVertexUV(obj, 1, 256, 0);
	ObjEffect_SetVertexUV(obj, 2, 256, 128);
	ObjEffect_SetVertexUV(obj, 3, 128, 128);

	ObjEffect_SetVertexXY(obj, 0, -64, -64);
	ObjEffect_SetVertexXY(obj, 1, 64,  -64);
	ObjEffect_SetVertexXY(obj, 2,  64,  64);
	ObjEffect_SetVertexXY(obj, 3,  -64, 64);

	Obj_SetPosition(obj, x,y);
	let Alpha=0;
	let Xangle=rand(0,360);
	let Yangle=rand(0,360);
	let Zangle=rand(0,360);
	ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

	let Xsize=size*1;
	let Ysize=size*1;
	let alphaPlus=200/fadeintime;
	let frame=0;
	let dir=rand_int(0,1)*2-1;
	loop(time)
	{
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
		Xangle+=3*dir;
		ObjEffect_SetScale(obj,cos(frame*(90/time))*Xsize,cos(frame*(90/time))*Ysize);
		if(Alpha<200)
		{
			Alpha+=alphaPlus;
		}
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,color[0],color[1],color[2]);
		}
		frame++;
		yield;
	}
	Obj_Delete(obj);
}

task ScreenShake(intensity,time)
{
	let frame=prand_int(0,4800);
	let intensityPlus=intensity/time;
	loop(time)
	{
		ScreenShakeX=sin(frame*60)*intensity*0.5;
		ScreenShakeY=sin(frame*90)*intensity;
		intensity-=intensityPlus;
		yield;
		frame++;
	}
}


