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

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

task CreateShot01ToItem(let x,let y,let speed, let angle, let color,let delay)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, color);
	ObjShot_SetDelay(obj, delay);
//	ObjShot_ToItem(obj,false);
	while(!Obj_BeDeleted(obj))
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	if(!OnPlayerMissed)
	{
	CreateShotChengeToItem(itemx,itemy);
	}
}

task CreateShotChengeToItem(let x,let y)
{
	if(GetClipMinX<x && x<GetClipMaxX && GetClipMinY<y && y<GetClipMaxY)
	{
		if(OnBomb)
		{
			ItemSet(x,y,13);
		}
		else if(GetCommonDataDefault("BarrirShrinkRemoveBullet",false)==true)
		{
			ItemSet(x,y,13);
		}
		else if(GetCommonDataDefault("BarrirBreakRemoveBullet",false)==true)
		{
			ItemSet(x,y,11);
		}
		else if(GetCommonDataDefault("BarrirBreakRemoveBulletNoShot",false)==true)
		{
			ItemSet(x,y,12);
		}
	}
}


task AutoErazeTime(w)
{
wait(w);
VanishEnemy;
}

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);
}