let ZakoColor=[255,255,255];
let ZakoMagicColor=[255,255,255];
let BulletNum;
let DrawZakoZAngle=0;
let imgCircle=csd~"..\img\circle.png";
function MSDSetCollisionB(x,y,Radius)
{
	if(GetCommonData("BURSTLEVEL")==0)
	{
		SetCollisionB(x,y,Radius);
	}
}

task GetDamege//ショットが当たった時色変更
{
GetDamegeItem;
loop
{
	if(GetHitCount!=0)
	{
		ZakoColor=[150,150,255];

		wait(10);
	}
	else
	{
		ZakoColor=[255,255,255];
	}
yield;
}
}

task GetDamegeItem//近接打ち込み
{
loop
{
		if(GetHitCount!=0 && GetDistanceToPlayer<=GetCommonData("MagicAbsorbShortRange"))
		{
			if(GetCommonData("BURSTLEVEL")==0)
			{
			ItemSet(GetX,GetY,2);
			ItemSet(GetX,GetY,2);
			}
			if(GetCommonData("BURSTLEVEL")==3)
			{
			ItemSet(GetX,GetY,8);
			ItemSet(GetX,GetY,8);
			}
		}
yield;
}
}

task MagicColor//封印時の色変更
{
loop
{
	if(GetDistanceToPlayer>90)
	{
		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)
{//封印されるCreateShot01
	if(GetDistanceToPlayer>90)
	{
		CreateShot01(X,Y,Speed,Angle,Graphic,Delay);
	}
}

function FinalizeItemAndShotnum(num)
{
	let BurstErazeCircleRangeRate=GetCommonData("BurstErazeCircleRangeRate");
	FinalizeItemSet(num);
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
		if(!BeVanished)
		{
		ReturnBurstShotnum((num+1)*3);
		}
	}
	case("Extream")
	{
		if(!BeVanished)
		{
		ReturnBurstShotnum((num+1)*3);
		ReturnPowerShotnum((num+1)*3);
		}
	}
	case("Apocalypse")
	{
		if(!BeVanished)
		{
		BurstErazeCircleRangeRate+=0.5;
		ReturnBurstShotnum((num+1)*3);
		}
	}

	if(GetCommonData("BURSTLEVEL")==3)
	{
		let RedBullet=GetEnemyShotCountEx(GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate,9);
		let BuleNife=GetEnemyShotCountEx(GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate,150);
		DeleteEnemyShotImmediatelyInCircle(SHOT,GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate);
		loop(RedBullet+BuleNife)
		{
			ItemSet(GetX,GetY,8);
		}
		let BMEBN=GetCommonDataDefault("BurstModeErazeBulletNum",[]);//共通データ内容を変数に渡す
		BMEBN=BMEBN~[RedBullet+BuleNife];//
		SetCommonData("BurstModeErazeBulletNum",BMEBN);//共通データに変更後の配列を渡す

		let BMEBE=GetCommonDataDefault("BurstModeErazeBulletEffect",[]);//共通データ内容を変数に渡す
		BMEBE=BMEBE~[GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate];//
		SetCommonData("BurstModeErazeBulletEffect",BMEBE);//共通データに変更後の配列を渡す
	}
	
}

function FinalizeItemAndShotnumWithDelete(num)
{
	let BurstErazeCircleRangeRate=GetCommonData("BurstErazeCircleRangeRate");
	FinalizeItemSet(num);
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
		if(!BeVanished)
		{
		ReturnBurstShotnum((num+1)*3);
		}
	}
	case("Extream")
	{
		if(!BeVanished)
		{
		BurstErazeCircleRangeRate+=0.5;
		ReturnBurstShotnum((num+1)*3);
		}
		if(GetCommonData("BURSTLEVEL")==0)
		{
			if(!BeVanished)
			{
				SetCommonData("DeleteBulletNum",BulletNum);
				SetCommonData("DeleteBulletX",GetX);
				SetCommonData("DeleteBulletY",GetY);
				DeleteEnemyShotToItem(ALL);
			}
		}
		ReturnPowerShotnum((num+1)*3);
	}
	case("Apocalypse")
	{
		if(!BeVanished)
		{
		BurstErazeCircleRangeRate+=1.0;
		ReturnBurstShotnum((num+1)*3);
		}
		if(GetCommonData("BURSTLEVEL")==0)
		{
			if(!BeVanished)
			{
				SetCommonData("DeleteBulletNum",BulletNum);
				SetCommonData("DeleteBulletX",GetX);
				SetCommonData("DeleteBulletY",GetY);
				DeleteEnemyShotToItem(ALL);
			}
		}
	}

	if(GetCommonData("BURSTLEVEL")==3)
	{
		let RedBullet=GetEnemyShotCountEx(GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate,9);
		let BuleNife=GetEnemyShotCountEx(GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate,150);
		DeleteEnemyShotImmediatelyInCircle(SHOT,GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate);
		loop(RedBullet+BuleNife)
		{
			ItemSet(GetX,GetY,8);
		}
		let BMEBN=GetCommonDataDefault("BurstModeErazeBulletNum",[]);//共通データ内容を変数に渡す
		BMEBN=BMEBN~[RedBullet+BuleNife];//
		SetCommonData("BurstModeErazeBulletNum",BMEBN);//共通データに変更後の配列を渡す
		let BMEBE=GetCommonDataDefault("BurstModeErazeBulletEffect",[]);//共通データ内容を変数に渡す
		BMEBE=BMEBE~[GetX,GetY,(num*5+5)*GetCommonData("BurstErazeCircleRangeRate")];//
		SetCommonData("BurstModeErazeBulletEffect",BMEBE);//共通データに変更後の配列を渡す
	}
}

function ReturnBurstShotnum(num)
{//バーストでの撃ち返し発生
	if(GetCommonData("BURSTLEVEL")==3)
	{
		ascent(let i in 0..num)
		{
			CreateShotFromScript( "BurstReturnShot",GetX, GetY, 3+rand(-0.75,0.75), GetAngleToPlayer+rand(-30,30), i*2, 8);
		}
		if(GetCommonData("MAGICCOUNTER")>=10000)
		{
			ascent(let i in 0..num)
			{
				CreateShotFromScript( "BurstReturnShot",GetX, GetY, 3+rand(-0.75,0.75), GetAngleToPlayer+rand(-30,30), i*2, 8);
			}
		}
	}
}

function ReturnPowerShotnum(num)
{//マジック反応弾撃ち返し発生
	if(GetCommonData("BURSTLEVEL")==0)
	{
		ascent(let i in 0..num)
		{
			if(GetDistanceToPlayer>90)
			{
				CreateShotFromScript( "PowerReturnShot",GetX, GetY, 3+rand(-0.75,0.75), GetAngleToPlayer+rand(-30,30), i*2, 8);
			}
			else
			{
				ItemSet(GetX,GetY,7);
			}
		}
		if(GetCommonData("MAGICCOUNTER")>=10000)
		{
			if(GetDistanceToPlayer>90)
			{
				CreateShotFromScript( "PowerReturnShot",GetX, GetY, 3+rand(-0.75,0.75), GetAngleToPlayer+rand(-30,30), i*2, 8);
			}
			else
			{
				ItemSet(GetX,GetY,7);
			}
		}
	}
}

function FinalizeItemSet(num)
{
if(GetX<GetClipMinX-16 || GetClipMaxX+16<GetX || GetY<GetClipMinY-16 || GetClipMaxY+16<GetY)
{

}
else
{
let type;
alternative(GetCommonData("BURSTLEVEL"))
case(0)
{
	type=3;
}
case(3)
{
	type=5;
}
		if(!BeVanished)
		{
		loop(num)
		{
			ItemSet(GetX,GetY,type);
			if(GetCommonData("MAGICCOUNTER")>=10000)
			{
				ItemSet(GetX,GetY,type);
			}
			if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbShortRange"))
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbLongRange"))
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetCommonData("MAGICPOWER")>=1000)
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Apocalypse")
			{
				ItemSet(GetX,GetY,9);
				ItemSet(GetX,GetY,9);
			}
		}
		if(num==0)
		{
			if(GetCommonData("MAGICCOUNTER")>=10000)
			{
				ItemSet(GetX,GetY,type);
			}
			if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbShortRange"))
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbLongRange"))
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetCommonData("MAGICPOWER")>=1000)
			{
				ItemSet(GetX,GetY,1);
			}
			if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Apocalypse")
			{
				ItemSet(GetX,GetY,9);
				ItemSet(GetX,GetY,9);
			}
		}
		}
}
}

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

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

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

task OutDamageRateZero
{
loop
{
	if(GetX<GetClipMinX-16 || GetClipMaxX+16<GetX || GetY<GetClipMinY-16 || GetClipMaxY+16<GetY)
	{
		SetDamageRate(0,0);
	}
	else
	{
		if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbShortRange"))
		{
			SetDamageRate(110,110);
		}
		if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbLongRange"))
		{
			SetDamageRate(105,105);
		}
		else
		{
			SetDamageRate(100,100);
		}
	}

yield;
}
}

task OutDamageRateZeroOnSet(ShotDamage,BombDamage)
{
loop
{
	if(GetX<GetClipMinX-16 || GetClipMaxX+16<GetX || GetY<GetClipMinY-16 || GetClipMaxY+16<GetY)
	{
		SetDamageRate(0,0);
	}
	else
	{
		if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbShortRange"))
		{
			SetDamageRate(ShotDamage*1.10,BombDamage*1.10);
		}
		if(GetDistanceToPlayer<=GetCommonData("MagicAbsorbLongRange"))
		{
			SetDamageRate(ShotDamage*1.05,BombDamage*1.05);
		}
		else
		{
			SetDamageRate(ShotDamage,BombDamage);
		}
	}

yield;
}

}

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

if(GetX<GetClipMinX-120 || GetClipMaxX+120<GetX || GetY<GetClipMinY-120 || GetClipMaxY+120<GetY)
{
	break;
}

yield;
}
VanishEnemy;
}

task ElementalAutoErazeTime(w)
{
loop(w)
{
if(GetCommonDataDefault("VanishSignal",false))
{
	break;
}

if(GetX<GetClipMinX-120 || GetClipMaxX+120<GetX || GetY<GetClipMinY-120 || GetClipMaxY+120<GetY)
{
	break;
}

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)
{
if(GetCommonDataDefault("LightMode",0)==1)
{
	LightModeZakoEffect1(R,G,B);
}
loop
{
	ZakoEffect1(R,G,B);
yield;
}
}

task RainbowZakoEffect
{
let R;
let B;
let G;
let HueCount=0;
let MinColor=50;
loop
{
	if(0<HueCount && HueCount<=60)
	{
		R=255;
		G=255*(HueCount)/60;
		B=0;
	}
	else if(HueCount<=120)
	{
		R=255*(120-HueCount)/60;
		G=255;
		B=0;
	}
	else if(HueCount<=180)
	{
		R=0;
		G=255;
		B=255*(HueCount-120)/60;
	}
	else if(HueCount<=240)
	{
		R=0;
		G=255*(240-HueCount)/60;
		B=255;
	}
	else if(HueCount<=300)
	{
		R=255*(HueCount-240)/60;
		G=0;
		B=255;
	}
	else if(HueCount<=360)
	{
		R=255;
		G=0;
		B=255*(360-HueCount)/60;
	}
	HueCount+=3;
	if(HueCount>=361){HueCount=1;}
	ZakoEffect1(R,G,B);
yield;
}

}

task ZakoEffect1(R,G,B)
{
		let randrect=5;
	let XYrect=[];
	loop(8)
	{
	XYrect=XYrect~[48/2+rand(-randrect,randrect)];
	}
	if(GetCommonDataDefault("LightMode",0)==1){return;}

		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, -XYrect[0], -XYrect[1]);
	ObjEffect_SetVertexXY(obj, 1, XYrect[2], -XYrect[3]);
	ObjEffect_SetVertexXY(obj, 2, XYrect[4], XYrect[5]);
	ObjEffect_SetVertexXY(obj, 3, -XYrect[6], XYrect[7]);
		
		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+GetSpeed*cos(GetAngle),GetY+GetSpeed*sin(GetAngle));
		//Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, scax,scay);

		ObjEffect_SetLayer(obj,2);

		Obj_SetSpeed(obj,1);
		Obj_SetAngle(obj,-90);
		loop(10)
		{
			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-=100/10;
			yield;
		}
		Obj_Delete(obj);
}

task LightModeZakoEffect1(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,imgCircle);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		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);

		Obj_SetPosition(obj,GetX,GetY);
		//Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, 0.2,0.2);

		ObjEffect_SetLayer(obj,2);

		Obj_SetSpeed(obj,1);
		Obj_SetAngle(obj,-90);

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

		loop
		{
			Obj_SetPosition(obj,GetX,GetY);
			yield;
		}
		Obj_Delete(obj);
}


function DrawMagicCircle(Color,scale)
{
		SetTexture(imgCircle);
		if(Color=="WHITE")
		{
		SetGraphicRect(256,256,512,512);
		}
		if(Color=="BLUE")
		{
		SetGraphicRect(256,0,512,256);
		}
		SetGraphicAngle(0,0,DrawZakoZAngle);
		SetGraphicScale(scale,scale);
	//	if(Color=="WHITE")
	//	{
		SetColor(ZakoMagicColor[0],ZakoMagicColor[1],ZakoMagicColor[2]);
	//	}
		DrawGraphic(GetX,GetY);
		SetGraphicAngle(0,0,-DrawZakoZAngle);
		DrawGraphic(GetX,GetY);
		DrawZakoZAngle+=3;
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
}

task ZakoMagicCircle(let MagicColor,scale)
{
		let AY;
		if(MagicColor=="BLUE")
		{
			AY=0;
		}
		if(MagicColor=="WHITE")
		{
			AY=256;
		}
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd~"..\img\circle.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		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,  AY);
		ObjEffect_SetVertexUV(obj, 1,  512, AY);
		ObjEffect_SetVertexUV(obj, 2, 512, AY+256);
		ObjEffect_SetVertexUV(obj, 3, 256,  AY+256);
		ObjEffect_SetScale(obj, scale,scale);
//////////////////////////////////////////////////////////
		let obj2 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj2, csd~"..\img\circle.png");
		ObjEffect_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj2, ADD); 
		ObjEffect_CreateVertex(obj2, 4);
		ObjEffect_SetVertexXY(obj2, 0, -128, -128);
		ObjEffect_SetVertexXY(obj2, 1, 128, -128);
		ObjEffect_SetVertexXY(obj2, 2, 128, 128);
		ObjEffect_SetVertexXY(obj2, 3, -128, 128);
		
		ObjEffect_SetVertexUV(obj2, 0,  256,  AY);
		ObjEffect_SetVertexUV(obj2, 1,  512, AY);
		ObjEffect_SetVertexUV(obj2, 2, 512, AY+256);
		ObjEffect_SetVertexUV(obj2, 3, 256,  AY+256);

///////////////////////////////////////////////////////////
		ObjEffect_SetLayer(obj,2);

		ascent(let i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,100,255,255,255);
		ObjEffect_SetVertexColor(obj2,i,100,255,255,255);
		}
		let ZAngle=0;
		let Sscale=scale;
		let ScaleAngle=90;
		while(GetLife>0)
		{
			Obj_SetPosition(obj,GetX+GetSpeed*cos(GetAngle),GetY+GetSpeed*sin(GetAngle));
			ObjEffect_SetAngle(obj,0,0,ZAngle);
			Obj_SetPosition(obj2,GetX+GetSpeed*cos(GetAngle),GetY+GetSpeed*sin(GetAngle));
			ObjEffect_SetAngle(obj2,0,0,-ZAngle);
			ObjEffect_SetScale(obj, Sscale,Sscale);
			ObjEffect_SetScale(obj2, Sscale,Sscale);
			Sscale=scale*(1+0.05*cos(ScaleAngle));
			ScaleAngle+=1;
			ZAngle+=3;
			if(MagicColor=="WHITE" && GetDistanceToPlayer<=90)
			{
				ascent(let i in 0..4)
				{
				ObjEffect_SetVertexColor(obj,i,100,255,100,100);
				ObjEffect_SetVertexColor(obj2,i,100,255,100,100);
				}
			}
			else
			{
				ascent(let i in 0..4)
				{
				ObjEffect_SetVertexColor(obj,i,100,255,255,255);
				ObjEffect_SetVertexColor(obj2,i,100,255,255,255);
				}
			}

			yield;
		}
		Obj_Delete(obj);
}

function moveToPlayer03(xMove, yAdd, weight,MaxSpeed, left, top, right, bottom)
{

	if(GetX>GetPlayerX)
	{
		xMove=xMove*-1;
	}

	if(GetX+xMove<left || GetX+xMove>right)
	{
		xMove=xMove*-1;
	}

	if(GetY+yAdd<top || GetY+yAdd>bottom)
	{
		yAdd=yAdd*-1;
	}


	SetMovePosition03(GetX+xMove,GetY+yAdd, weight,MaxSpeed)
}

task ElementalEffect(R,G,B,scale)
{
if(GetCommonDataDefault("LightMode",0)==1)
{
	LightModeElementalEffect1(R,G,B,scale);
}
loop
{
	ElementalEffect1(R,G,B,scale);
yield;
}
}

task ElementalEffect1(R,G,B,scale)
{
		let randrect=5;
	let XYrect=[];
	loop(8)
	{
	XYrect=XYrect~[48/2+rand(-randrect,randrect)];
	}
	if(GetCommonDataDefault("LightMode",0)==1){return;}

		let scax=scale;
		let scay=scale;
		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, -XYrect[0], -XYrect[1]);
	ObjEffect_SetVertexXY(obj, 1, XYrect[2], -XYrect[3]);
	ObjEffect_SetVertexXY(obj, 2, XYrect[4], XYrect[5]);
	ObjEffect_SetVertexXY(obj, 3, -XYrect[6], XYrect[7]);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  48, 0);
		ObjEffect_SetVertexUV(obj, 2, 48,  48);
		ObjEffect_SetVertexUV(obj, 3, 0, 48);

		ObjEffect_SetLayer(obj,2);

		Obj_SetPosition(obj,GetX+GetSpeed*cos(GetAngle),GetY+GetSpeed*sin(GetAngle));
		//Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, scax,scay);
		Obj_SetSpeed(obj,1);
		Obj_SetAngle(obj,-90);
		loop(5)
		{
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,alpha,R,G,B);
			}
			ObjEffect_SetScale(obj, scax,scay);
			scax+=0.3/5;
			scay+=0.3/5;
			alpha-=100/5;
			yield;
		}
		Obj_Delete(obj);
}

task LightModeElementalEffect1(R,G,B,scale)
{

		let scax=0.2*scale;
		let scay=0.2*scale;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
		let alpha=250;
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,imgCircle);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		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);

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

		Obj_SetPosition(obj,GetX,GetY);
		//Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, scax,scay);

		ObjEffect_SetLayer(obj,2);

		Obj_SetSpeed(obj,1);
		Obj_SetAngle(obj,-90);
		loop
		{
			Obj_SetPosition(obj,GetX,GetY);
			yield;
		}
		Obj_Delete(obj);
}
