let ZakoColor=[255,255,255];
let ZakoMagicColor=[255,255,255];
let BulletNum;
task GetDamege
{
loop
{
	if(GetHitCount!=0)
	{
		ZakoColor=[150,150,255];
		wait(10);
	}
	else
	{
		ZakoColor=[255,255,255];
	}
yield;
}
}

task MagicColor
{
loop
{
	if(GetDistanceToPlayer>75)
	{
		ZakoMagicColor=[255,255,255];
	}
	else
	{
		ZakoMagicColor=[255,150,150];
	}
yield;
}
}

function wait(w) 
{
	loop(w){yield;}
}

function GetDistanceToPlayer
{
	let dis=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	return(dis);
}

function GroundCreateShot01(X,Y,Speed,Angle,Graphic,Delay)
{
	if(GetDistanceToPlayer>75)
	{
		CreateShot01(X,Y,Speed,Angle,Graphic,Delay);
	}
}

function FinalizeItemSet(num)
{
let type;
alternative(GetCommonData("BURSTLEVEL"))
case(0)
{
	type=3;
}
case(1)
{
	type=4;
}
case(2)
{
	type=4;
}
case(3)
{
	type=4;
}
		if(!BeVanished)
		{
		loop(num)
		{
			ItemSet(GetX,GetY,type);
			if(GetDistanceToPlayer<=60)
			{
				ItemSet(GetX,GetY,3);
			}
			if(GetDistanceToPlayer<=90)
			{
				ItemSet(GetX,GetY,3);
			}
			if(GetDistanceToPlayer<=120)
			{
				ItemSet(GetX,GetY,3);
			}
			if(GetDistanceToPlayer<=150)
			{
				ItemSet(GetX,GetY,3);
			}
		}
		}
}

function ItemSet(x,y,type)//アイテム生成関数
{
	let XY=GetCommonDataDefault("ItemXY",[]);//共通データ内容を変数に渡す
	XY=XY~[x,y,type];//
	SetCommonData("ItemXY",XY);//共通データに変更後の配列を渡す
}

task OutDamageRateZero
{
loop
{
	if(GetX<GetClipMinX-16 || GetClipMaxX+16<GetX || GetY<GetClipMinY-16 || GetClipMaxY+16<GetY)
	{
		SetDamageRate(0,0);
	}
	else
	{
		if(GetDistanceToPlayer<=60)
		{
			SetDamageRate(105,105);
		}
		if(GetDistanceToPlayer<=150)
		{
			SetDamageRate(102.5,102.5);
		}
		else
		{
			SetDamageRate(100,100);
		}
	}

yield;
}
}

task AutoErazeTime(w)
{
ZakoEnemyLifeDisplay;
loop(w)
{
if(GetCommonDataDefault("VanishSignal",false))
{
	VanishEnemy;
	return;
}
yield;
}
VanishEnemy;
}


task ZakoEnemyLifeDisplay//下部に敵のライフを表示
{
//ZakoLifeBerDisplay;
ZakoLifeDisplay;
}

task ZakoLifeBerDisplay//ライフバーの枠の設定
{
	let BossLifeMax=GetLife;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd ~ "..\img\ber.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -71, -5);
		ObjEffect_SetVertexXY(obj, 1, 71,  -5);
		ObjEffect_SetVertexXY(obj, 2, 71, 5);
		ObjEffect_SetVertexXY(obj, 3,  -71,  5);
		
		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, 0.5,0.16);

		while(GetLife>0)
		{
			Obj_SetPosition(obj,GetX,GetY-16);
			yield
		}
		Obj_Delete(obj);
}


task ZakoLifeDisplay//ライフバーのバー部分の設定
{
	let ZakoLifeMax=GetLife;
	if(ZakoLifeMax<=20){return;}
	let scale=0.5;
	let Sscale=0.5;
	let XAdjust=25;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd ~ "..\img\ber.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, 0, -3);
		ObjEffect_SetVertexXY(obj, 1, 100,  -3);
		ObjEffect_SetVertexXY(obj, 2, 100, 3);
		ObjEffect_SetVertexXY(obj, 3,  0,  3);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  206, 27);
		ObjEffect_SetVertexUV(obj, 2, 206,  33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);
		ObjEffect_SetLayer(obj,2);
		ObjEffect_SetScale(obj, scale,0.16);

		ObjEffect_SetVertexColor(obj,0,150,255,255,0);
		ObjEffect_SetVertexColor(obj,1,150,255,0,0);
		ObjEffect_SetVertexColor(obj,2,150,255,0,0);
		ObjEffect_SetVertexColor(obj,3,150,255,255,0);

		while(GetLife>0)
		{
			Obj_SetPosition(obj,GetX-XAdjust,GetY-16);
			scale=Sscale*GetLife/ZakoLifeMax;
			ObjEffect_SetVertexColor(obj,0,255,255,255,0);
			ObjEffect_SetVertexColor(obj,1,255,255,255-255*GetLife/ZakoLifeMax,0);
			ObjEffect_SetVertexColor(obj,2,255,255,255-255*GetLife/ZakoLifeMax,0);
			ObjEffect_SetVertexColor(obj,3,255,255,255,0);
			if(GetLife==ZakoLifeMax)
			{
			ObjEffect_SetVertexColor(obj,0,0,255,255,0);
			ObjEffect_SetVertexColor(obj,1,0,255,255-255*GetLife/ZakoLifeMax,0);
			ObjEffect_SetVertexColor(obj,2,0,255,255-255*GetLife/ZakoLifeMax,0);
			ObjEffect_SetVertexColor(obj,3,0,255,255,0);
			}
			ObjEffect_SetScale(obj, scale,0.8);
			yield;
		}
		Obj_Delete(obj);
}

task ZakoEffect(R,G,B)
{
	ZakoEffect0(R,G,B);
loop
{
	ZakoEffect1(R,G,B);
yield;
}
}

task ZakoEffect0(R,G,B)
{
		let scax=1.0;
		let scay=1.0;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
		let alpha=100;
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\CircleEffect.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -24, -24);
		ObjEffect_SetVertexXY(obj, 1,  24, -24);
		ObjEffect_SetVertexXY(obj, 2,  24,  24);
		ObjEffect_SetVertexXY(obj, 3, -24,  24);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  48, 0);
		ObjEffect_SetVertexUV(obj, 2, 48,  48);
		ObjEffect_SetVertexUV(obj, 3, 0, 48);

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

		ObjEffect_SetScale(obj, scax,scay);
		loop
		{
		Obj_SetPosition(obj,GetX,GetY);
			yield;
		}
}


task ZakoEffect1(R,G,B)
{
		let randrect=5;
		let scax=1.0;
		let scay=1.0;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
		let alpha=50;
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\CircleEffect.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -24+rand(-randrect,randrect), -24+rand(-randrect,randrect));
		ObjEffect_SetVertexXY(obj, 1,  24+rand(-randrect,randrect), -24+rand(-randrect,randrect));
		ObjEffect_SetVertexXY(obj, 2,  24+rand(-randrect,randrect),  24+rand(-randrect,randrect));
		ObjEffect_SetVertexXY(obj, 3, -24+rand(-randrect,randrect),  24+rand(-randrect,randrect));
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  48, 0);
		ObjEffect_SetVertexUV(obj, 2, 48,  48);
		ObjEffect_SetVertexUV(obj, 3, 0, 48);


		Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, scax,scay);
		loop(10)
		{
			Obj_SetY(obj,Obj_GetY(obj)-1);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,alpha,R,G,B);
			}
			ObjEffect_SetScale(obj, scax,scay);
			scax+=0.3/10;
			scay+=0.3/10;
			alpha-=50/10;
		if(GetX==Obj_GetX(obj) && GetY==Obj_GetY(obj))
		{
			alpha-=50/10;
			scax+=0.3/10;
			scay+=0.3/10;
		}
			yield;
		}
		Obj_Delete(obj);
}



task Explode(color)
{
	while(GetLife>1000)
	{
		yield;
	}
//SetColor(200,200,255);
//Explosion01(GetX,GetY,10,0.1,30);
ExplodeEffect1(color);
ExplodeEffect2(color);
PlaySE("se\seEnemyExplode01.wav");
}

task ExplodeEffect1(let color)
{
		let scax=0.0;
		let scay=0.0;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
		let alpha=150;
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\effect_circle.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -64, -64);
		ObjEffect_SetVertexXY(obj, 1,  64, -64);
		ObjEffect_SetVertexXY(obj, 2,  64,  64);
		ObjEffect_SetVertexXY(obj, 3, -64,  64);
		
		ObjEffect_SetVertexUV(obj, 0,  (color-1)*128,  128);
		ObjEffect_SetVertexUV(obj, 1,  color*128, 128);
		ObjEffect_SetVertexUV(obj, 2, color*128,  256);
		ObjEffect_SetVertexUV(obj, 3, (color-1)*128, 256);

		ObjEffect_SetVertexColor(obj,0,alpha,255,255,255);
		ObjEffect_SetVertexColor(obj,1,alpha,255,255,255);
		ObjEffect_SetVertexColor(obj,2,alpha,255,255,255);
		ObjEffect_SetVertexColor(obj,3,alpha,255,255,255);

		Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, scax,scay);
		loop(20)
		{
			ObjEffect_SetVertexColor(obj,0,alpha,255,255,255);
			ObjEffect_SetVertexColor(obj,1,alpha,255,255,255);
			ObjEffect_SetVertexColor(obj,2,alpha,255,255,255);
			ObjEffect_SetVertexColor(obj,3,alpha,255,255,255);
			ObjEffect_SetScale(obj, scax,scay);
			scax+=1/12;
			scay+=1/12;
			alpha-=10;
			yield;
		}
		Obj_Delete(obj);
}

task ExplodeEffect2(let color)
{
		let scax=0.0;
		let scay=0.0;
		let angle=0;
		let Xangle=rand(10,80)*(rand_int(0,1)*2-1);
		let Yangle=rand(10,80)*(rand_int(0,1)*2-1);	
		let Zangle=rand(0,360);
		let RotateAngle=3;
		let alpha=250;
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\effect_circle.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -64, -64);
		ObjEffect_SetVertexXY(obj, 1,  64, -64);
		ObjEffect_SetVertexXY(obj, 2,  64,  64);
		ObjEffect_SetVertexXY(obj, 3, -64,  64);
		
		ObjEffect_SetVertexUV(obj, 0,  (color-1)*128,  128);
		ObjEffect_SetVertexUV(obj, 1,  color*128, 128);
		ObjEffect_SetVertexUV(obj, 2, color*128,  256);
		ObjEffect_SetVertexUV(obj, 3, (color-1)*128, 256);

		ObjEffect_SetVertexColor(obj,0,alpha,255,255,255);
		ObjEffect_SetVertexColor(obj,1,alpha,255,255,255);
		ObjEffect_SetVertexColor(obj,2,alpha,255,255,255);
		ObjEffect_SetVertexColor(obj,3,alpha,255,255,255);

		Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, scax,scay);
		ObjEffect_SetAngle(obj,0,Yangle,Zangle);
		loop(20)
		{
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetVertexColor(obj,0,alpha,255,255,255);
			ObjEffect_SetVertexColor(obj,1,alpha,255,255,255);
			ObjEffect_SetVertexColor(obj,2,alpha,255,255,255);
			ObjEffect_SetVertexColor(obj,3,alpha,255,255,255);
			ObjEffect_SetScale(obj, scax,scay);
			scax+=1/12;
			scay+=1/12;
			alpha-=15;
			yield;
		}
		Obj_Delete(obj);
}