let ZakoColor=[255,255,255];
let ZakoMagicColor=[255,255,255];
let BulletNum;
let DrawZakoZAngle=0;
let imgCircle=csd~"..\img\circle.png";
let DamageRate=100;
let BombDamageRate=100;
let EnemyGroundShotSeal=false;
let EnemyGroundShotSealtime=0;

function MSDSetCollisionAForBigEnemy(x,y,Radius)
{
	if(GetDistanceToPlayer<=Radius)
	{
		SetCollisionA(x,y,(GetDistanceToPlayer+Radius)/2);
	}
	else
	{
		SetCollisionA(x,y,Radius);
	}
}

function MSDSetCollisionB(x,y,Radius)
{
	if(GetCommonData("BURSTLEVEL")==0)
	{
		if(GetDistanceToPlayer<=Radius && GetTimeOfPlayerInvincibility==0)
		{
			ItemSet(GetX,GetY,-1);
		}
	}
}

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

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

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

task MagicColor//封印時の色変更
{
SealEnemy;
loop
{
	if(!EnemyGroundShotSeal)
	{
		ZakoMagicColor=[255,255,255];
	}
	else
	{
		ZakoMagicColor=[255,150,150];
	}
yield;
}
}

task SealEnemy
{
	loop
	{
		if(GetDistanceToPlayer<=90)
		{
			EnemyGroundShotSealtime=30;
		}
		else
		{
			EnemyGroundShotSealtime-=1;
		}
		if(EnemyGroundShotSealtime>0)
		{
			EnemyGroundShotSeal=true;
		}
		else
		{
			EnemyGroundShotSeal=false;
		}
	yield;
	}
}

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

function GetDistanceToPlayer//敵とプレイヤーとも距離を返す
{
	let dis=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	return(dis);
}

function SkyCreateShot01(X,Y,Speed,Angle,Graphic,Delay)
{
	if(GetCommonData("BURSTLEVEL")==3)
	{
		Speed=Speed*(1+0.5*GetCommonData("BURSTRANK")/10000);
	}
	CreateShot01(X,Y,Speed,Angle,Graphic,Delay);
}

function GroundCreateShot01(X,Y,Speed,Angle,Graphic,Delay)
{//封印されるCreateShot01
	if(GetCommonData("BURSTLEVEL")==3)
	{
		Speed=Speed*(1+0.5*GetCommonData("BURSTRANK")/10000);
	}
	if(!EnemyGroundShotSeal)
	{
		CreateShot01(X,Y,Speed,Angle,Graphic,Delay);
	}
}

function FinalizeItemAndShotnum(num)
{
	let BurstErazeCircleRangeRate=GetCommonData("BurstErazeCircleRangeRate");
	FinalizeItemSet(num);

	if(!BeVanished && !OnBomb)
	{
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			ReturnBurstShotnum((num+1));
		}
		case("Extream")
		{
			ReturnBurstShotnum((num+1));
			ReturnPowerShotnum((num+1));
		}
		case("Apocalypse")
		{
			BurstErazeCircleRangeRate+=0.3;
			ReturnBurstShotnum((num+1));
		}
	}

	if(GetCommonData("BURSTLEVEL")==3)
	{
		let RedBullet=GetEnemyShotCountEx(GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate,9);
		let BlueBullet=GetEnemyShotCountEx(GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate,14);
		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+BlueBullet];//
		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);

	if(!BeVanished)
	{
		if(!OnBomb)
		{
			alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
			case("Moderate")
			{
				ReturnBurstShotnum((num+1));
			}
			case("Extream")
			{
				ReturnBurstShotnum((num+1));
				ReturnPowerShotnum((num+1));
			}
			case("Apocalypse")
			{
				BurstErazeCircleRangeRate+=0.3;
				ReturnBurstShotnum((num+1));
			}
		}
		if(GetCommonData("BURSTLEVEL")==0)
		{
			SetCommonData("DeleteBulletNum",BulletNum);
			SetCommonData("DeleteBulletX",GetX);
			SetCommonData("DeleteBulletY",GetY);
			DeleteEnemyShotToItem(SHOT);
		}
	}
	BurstErazeCircleRangeRate*=1.2;
	if(GetCommonData("BURSTLEVEL")==3)
	{
		let RedBullet=GetEnemyShotCountEx(GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate,9);
		let BlueBullet=GetEnemyShotCountEx(GetX,GetY,(num*5+5)*BurstErazeCircleRangeRate,14);
		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+BlueBullet];//
		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), 30, 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), 30, 8);
			}
		}
	}
}

function ReturnPowerShotnum(num)
{//マジック反応弾撃ち返し発生
	if(GetCommonData("BURSTLEVEL")==0)
	{
		ascent(let i in 0..num)
		{
			if(GetCommonDataDefault("SlowMoveSwitch",false))
			{
				ItemSet(GetX,GetY,7);
			}
			else
			{
				ItemSet(GetX,GetY,75);
			}
			if(GetCommonData("MAGICCOUNTER")>=10000)
			{
				if(GetCommonDataDefault("SlowMoveSwitch",false))
				{
					ItemSet(GetX,GetY,7);
				}
				else
				{
					ItemSet(GetX,GetY,75);
				}
			}
		}
	}
}

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

}
else
{
let type;
let GreenItem=0;
//let SRange=GetCommonData("MagicAbsorbShortRange");
//let LRange=GetCommonData("MagicAbsorbLongRange");
let SRange=60;
let LRange=150;
alternative(GetCommonData("BURSTLEVEL"))
case(0)
{
	type=3;
}
case(3)
{
	type=5;
}
		if(!BeVanished)
		{
		loop(num)
		{
			ItemSet(GetX,GetY,type);
		}
		if(num==0){num=1;}
		loop(num)
		{
			if(GetCommonData("MAGICCOUNTER")>=10000)
			{
				ItemSet(GetX,GetY,type);
			}
			if(GetCommonData("MAGICPOWER")>=1000)
			{	
				ItemSet(GetX,GetY,type);
			}
			if(GetDistanceToPlayer<=SRange)
			{
				GreenItem=10;
			}
			else if(GetDistanceToPlayer<=LRange)
			{
				GreenItem=10*(GetDistanceToPlayer-LRange)/(SRange-LRange);
			}
			else
			{
				GreenItem=0;
			}
			loop(trunc(GreenItem))
			{
				alternative(GetCommonData("BURSTLEVEL"))
				case(0)
				{
					ItemSet(GetX,GetY,1);
				}
				case(3)
				{
					ItemSet(GetX,GetY,10);
				}
			}
		}
		}
}
}

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
{
let DamegeCoefficient=0;
//let SRange=GetCommonData("MagicAbsorbShortRange");
//let LRange=GetCommonData("MagicAbsorbLongRange");
let SRange=60;
let LRange=150;
loop
{
	if(GetX<GetClipMinX-16 || GetClipMaxX+16<GetX || GetY<GetClipMinY-16 || GetClipMaxY+16<GetY)
	{
		SetDamageRate(0,0);
	}
	else
	{
		if(GetDistanceToPlayer<=SRange)
		{
			DamegeCoefficient=1.2;
		}
		else if(GetDistanceToPlayer<=LRange)
		{
			DamegeCoefficient=1+0.2*(GetDistanceToPlayer-LRange)/(SRange-LRange);
		}
		else
		{
			DamegeCoefficient=1.0;
		}
		SetDamageRate(DamageRate*DamegeCoefficient,BombDamageRate);
	}

yield;
}
}

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

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

yield;
}
VanishEnemy;
}

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

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

yield;
}
VanishEnemy;
}


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

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

task RainbowZakoEffect
{
let R=255;
let B=255;
let G=255;
let HueCount=0;
let MinColor=50;
	if(GetCommonDataDefault("LightMode_ElementalBlur",0)==1)
	{
		LightModeRainbowZakoEffect1(-1);
		LightModeRainbowZakoEffect1(1);
	}
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 LightModeRainbowZakoEffect1(dir)
{
let R=255;
let B=255;
let G=255;
		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);
			}
		let HueCount=0;
		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;}
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,alpha,R,G,B);
			}
			Obj_SetPosition(obj,GetX,GetY);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=3*dir;
			yield;
		}
		Obj_Delete(obj);
}

task ZakoEffect1(R,G,B)
{
		let randrect=4;
	let XYrect=[];
	loop(8)
	{
	XYrect=XYrect~[48/2+rand(-randrect,randrect)];
	}
	if(GetCommonDataDefault("LightMode_ElementalBlur",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=150;
  		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(3)
		{
			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-=150/5;
			yield;
		}
		Obj_Delete(obj);
}

task LightModeZakoEffect1(R,G,B,dir)
{

		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);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=3*dir;
			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);
		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_ElementalBlur",0)==1)
{
	LightModeElementalEffect1(R,G,B,scale,1);
	LightModeElementalEffect1(R,G,B,scale,-1);
}
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_ElementalBlur",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=200;
  		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(3)
		{
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,alpha,R,G,B);
			}
			ObjEffect_SetScale(obj, scax,scay);
			scax+=0.3/5*2;
			scay+=0.3/5*2;
			alpha-=200/5*2;
			yield;
		}
		Obj_Delete(obj);
}

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

		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);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=3*dir;
			yield;
		}
		Obj_Delete(obj);
}



task ShotElementalEffect(x,y,R,G,B,scale)
{
if(GetCommonDataDefault("LightMode_ElementalBlur",0)==1)
{
	ShotLightModeElementalEffect1(x,y,R,G,B,scale);
}
	ShotElementalEffect1(x,y,R,G,B,scale);
}

task ShotElementalEffect1(x,y,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=200;
  		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,x+GetSpeed*cos(GetAngle),y+GetSpeed*sin(GetAngle));
		//Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, scax,scay);
		Obj_SetSpeed(obj,1);
		Obj_SetAngle(obj,-90);
		loop(3)
		{
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,alpha,R,G,B);
			}
			ObjEffect_SetScale(obj, scax,scay);
			scax+=0.3/5*2;
			scay+=0.3/5*2;
			alpha-=200/5*2;
			yield;
		}
		Obj_Delete(obj);
}

task ShotLightModeElementalEffect1(x,y,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,x,y);
		//Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetScale(obj, scax,scay);

		ObjEffect_SetLayer(obj,2);

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