
#Title[妹紅１]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_mokou.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let Step2=false;
	let wIni=60;
let TimeCounter=56*60;
let StandardTimeCounter=TimeCounter;
    @Initialize {
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
	//SetShotAutoDeleteClip(32,32,32,32);
        SetLife(2500);
	InitializeAction();
	SetEnemyMarker(true);
        TMainGrobal;
    }

    @MainLoop {
	SetCommonData("BossX",GetX);
	SetCommonData("BossY",GetY);
	SetCommonData("BossLife",GetLife);
	BulletNum=GetEnemyShotCount;
	TimeCounter-=1;
        yield;
    }

    @DrawLoop {
	if(TimeCounter<StandardTimeCounter-210)
	{
	DrawBoss( imgBoss );
	}
    }

    @Finalize {
	DeleteAllEnemyWithoutBoss;
	SetCommonData("BossX",GetX);
	SetCommonData("BossY",GetY);
	SetCommonData("BossLife",GetLife);
	DeleteEnemyShotToItem(ALL);
		if(!IsTimeOut)
		{
		SetCommonData("DeleteBulletNum",BulletNum);
		SetCommonData("DeleteBulletX",GetX);
		SetCommonData("DeleteBulletY",GetY);
		}

	SetCommonData("VanishSignal",false);
	SetCommonData("TimeBonus",TimeCounter/StandardTimeCounter);
	SetCommonData("BossRate",15000);
    }

    // メインタスク
task TMainGrobal
{
	yield;
	Wing;
	Collision;
	GetDamege;
	OutDamageRateZero;
	standBy;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}
	DamageRateChange;
}

sub standBy//初期位置へ
{
	SetX(GetClipMinX-256);
	SetY(GetPlayerY);
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
		exclamation(GetPlayerY);
		exclamation(GetPlayerY+55);
		exclamation(GetPlayerY-55);
	}
	case("Extream")
	{
		exclamation(GetPlayerY);
		exclamation(GetPlayerY+55);
		exclamation(GetPlayerY-55);
		exclamation(GetPlayerY+110);
		exclamation(GetPlayerY-110);
	}
	case("Apocalypse")
	{
		exclamation(GetPlayerY);
		exclamation(GetPlayerY+55);
		exclamation(GetPlayerY-55);
		exclamation(GetPlayerY+110);
		exclamation(GetPlayerY-110);
		exclamation(GetPlayerY+165);
		exclamation(GetPlayerY-165);
	}
	wait(120);
	SetAngle(0);
	SetSpeed(14);
	//Lissajous(255,100,0);
	BossShadowAnimation(imgBoss2,55,255,100,0);
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
		Explode(5,0.5);
		wait(60);
	}
	case("Extream")
	{
		Explode(8,0.8);
		wait(20);
		let angle=rand(0,360);
		loop(6)
		{
			ascent(let i in 0..36)
			{
				CreateShot01(GetX,GetY,3,angle+i*10,9,10);
			}
			wait(5);
		}
		wait(10);
	}
	case("Apocalypse")
	{
		Explode(12,1.2);
		let angle=GetAngleToPlayer;
		wait(20);
		loop(5)
		{
			ascent(let i in 0..36)
			{
				CreateShot01(GetX,GetY,3.5,angle+i*10,9,10);
				CreateShot01(GetX,GetY,3.25,angle+i*10,9,10);
				CreateShot01(GetX,GetY,3.0,angle+i*10,9,10);
			}
			wait(6);
		}
		wait(10);
	}

	SetAction(ACT_MOVE, 120);
	SetMovePosition03(xIni, yIni, 20,8);
	wait(90);
	Concentration01(30);

	task Explode(size,sizePlus)
	{
	loop(60)
	{
		CreateExplosion(GetX+50,GetY,size,[255,30,30],sizePlus,rand(20,40));
		yield;
	//	yield;
	}
	}
}


task Collision
{
	wait(120);
	loop(60)
	{
       		SetCollisionA(GetX, GetY, 48);
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			SetCollisionB(GetX, GetY, 75);
			MSDSetCollisionB(GetX, GetY, 75);
			if(((GetPlayerY-GetY)^2+(GetPlayerX-GetX)^2)^0.5<=75 && GetTimeOfPlayerInvincibility==0)
			{
				SetCommonDataEx(NsScore,NsAchievement[91],1);
			}
		}
		case("Extream")
		{

			SetCollisionB(GetX, GetY, 125);
			MSDSetCollisionB(GetX, GetY, 125);
			if(((GetPlayerY-GetY)^2+(GetPlayerX-GetX)^2)^0.5<=125 && GetTimeOfPlayerInvincibility==0)
			{
				SetCommonDataEx(NsScore,NsAchievement[91],1);
			}
		}
		case("Apocalypse")
		{
			SetCollisionB(GetX, GetY, 175);
			MSDSetCollisionB(GetX, GetY, 175);
			if(((GetPlayerY-GetY)^2+(GetPlayerX-GetX)^2)^0.5<=175 && GetTimeOfPlayerInvincibility==0)
			{
				SetCommonDataEx(NsScore,NsAchievement[91],1);
			}
		}
		yield;
	}
	loop(90)
	{
        SetCollisionA(GetX, GetY, 48);
	yield;
	}
	loop
	{
        SetCollisionA(GetX, GetY, 48);
        MSDSetCollisionB(GetX, GetY, 16);
	yield;
	}

}

task DamageRateChange
{
loop
{
	DamageRate=100-80*(GetEnemyNum-1)/8;
yield;
}
}

task shotM
{
let looptime=-1;
let r=50;
wait(30);
loop
{
	let waittime=30;
	let speed=2.5;
	SetAction(ACT_SHOT_A,240);
	loop(6)
	{
	let angle=rand(0,360);
	let X=rand(GetCenterX-80,GetCenterX);
	let Y=rand(GetClipMinY+16,GetClipMinY+64);
	let angle=atan2(GetPlayerY-Y,GetPlayerX-X);
		ascent(let i in 0..floor(360/(9-looptime)))
		{
			CreateShot01(X,Y,speed,angle+i*(9-looptime),89,5);
		}
	wait(waittime);
	let angle=rand(0,360);
	let X=rand(GetCenterX,GetCenterX+80);
	let Y=rand(GetClipMinY+16,GetClipMinY+64);
	let angle=atan2(GetPlayerY-Y,GetPlayerX-X)+(9-looptime)/2;
		ascent(let i in 0..floor(360/(9-looptime)))
		{
			CreateShot01(X,Y,speed,angle+i*(9-looptime),95,5);
		}
	wait(waittime);
	waittime-=5;
	speed+=0.3;
	}
	wait(60);
	SetAction(ACT_SHOT_B,60);
	SpellDraw(6,750);
	summon;
	loop(750)
	{
		if(GetEnemyNum==1){SpellDrawStop;break;}
		yield;
	}
	wait(60);
	if(looptime<1)
	{
	looptime+=1;
	}
	if(looptime<3)
	{
	//looptime+=2;
	}
}


task Phoenix(x,y,speed,angle)
{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		Obj_SetAutoDelete(obj,false);
		ObjShot_SetGraphic(obj, 25);
		ObjShot_SetDelay(obj, 5);
	//	Obj_SetAlpha(obj, 5);

			PhoenixBullet(obj,0,12,angle);
			PhoenixBullet(obj,0,24,angle);
			PhoenixBullet(obj,0,-12,angle);
			PhoenixBullet(obj,0,-24,angle);

		ascent(let i in 0..4)
		{
			PhoenixBullet(obj,15+15*i,-7.5*i,angle);
			PhoenixBullet(obj,-15-15*i,-7.5*i,angle);
		}

		ascent(let i in 0..4)
		{
			PhoenixBullet(obj,30+15*i,-20-10*i,angle);
			PhoenixBullet(obj,-30-15*i,-20-10*i,angle);
		}

		ascent(let i in 0..4)
		{
			PhoenixBullet(obj,40+15*i,-40-12.5*i,angle);
			PhoenixBullet(obj,-40-15*i,-40-12.5*i,angle);
		}
		wait(600);
		Obj_Delete(obj);
}

task PhoenixBullet(Cobj,x,y,angle)
{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, Obj_GetX(Cobj)+x*cos(angle-90)+y*cos(angle),Obj_GetY(Cobj)+x*sin(angle-90)+y*sin(angle));
		ObjShot_SetGraphic(obj, 162);
		ObjShot_SetDelay(obj, 5);
		Obj_SetAngle(obj, angle);
		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj, Obj_GetX(Cobj)+x*cos(angle-90)+y*cos(angle),Obj_GetY(Cobj)+x*sin(angle-90)+y*sin(angle));
			yield;
		}
}

task PhoenixWingEffect(Cobj,x,y,angle)
{
	while(!Obj_BeDeleted(Cobj))
	{
		PhoenixEffect(Obj_GetX(Cobj)+x*cos(angle-90)+y*cos(angle),Obj_GetY(Cobj)+x*sin(angle-90)+y*sin(angle));
		yield;
	}
}

task PhoenixEffect(x,y)
{
		let R=255;let G=0;let B=0;
		let randrect=3;
		let scax=0.3;
		let scay=0.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, -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,x,y);
		ObjEffect_SetScale(obj, scax,scay);
		Obj_SetSpeed(obj,0.2);
		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);
			alpha-=10;
			yield;
		}
		Obj_Delete(obj);
}

}
/////////////////////////////////////////////////////////////////////////////
task shotE
{
let looptime=0;
let r=50;
wait(30);
loop
{
	SetAction(ACT_SHOT_A,240);
	Shot1;
	Shot2;
	wait(270);
	SetAction(ACT_SHOT_B,60);
	SpellDraw(6,750);
	summon;
	loop(750)
	{
		if(GetEnemyNum==1){SpellDrawStop;break;}
		yield;
	}
	wait(60);
	if(looptime<1)
	{
	looptime+=1;
	}
	if(looptime<3)
	{
	looptime+=2;
	}
}

task Shot1
{
	let waittime=30;
	let speed=3.0;
	loop(6)
	{
	//let angle=rand(0,360);
	let X=rand(GetCenterX-80,GetCenterX);
	let Y=rand(GetClipMinY+16,GetClipMinY+64);
	let angle=atan2(GetPlayerY-Y,GetPlayerX-X);
		ascent(let i in 0..floor(360/(9-looptime)))
		{
			CreateShot01(X,Y,speed,angle+i*(9-looptime),95,5);
		}
	wait(waittime);
	let angle=rand(0,360);
	let X=rand(GetCenterX,GetCenterX+80);
	let Y=rand(GetClipMinY+16,GetClipMinY+64);
	let angle=atan2(GetPlayerY-Y,GetPlayerX-X)+(9-looptime)/2;
		ascent(let i in 0..floor(360/(9-looptime)))
		{
			CreateShot01(X,Y,speed,angle+i*(9-looptime),95,5);
		}
	wait(waittime);
	waittime-=5;
}
}

task Shot2
{
	let waittime=30;
	let speed=1.75;
	loop(12)
	{
		let X=rand(GetCenterX-80,GetCenterX);
		let Y=rand(GetClipMinY+16,GetClipMinY+64);
		let angle=rand(0,360);
		ascent(let i in 0..24)
		{
			CreateShot01(X,Y,speed,angle+i*15,89,5);
		}
		wait(10);
		let X=rand(GetCenterX+80,GetCenterX);
		let Y=rand(GetClipMinY+48,GetClipMinY+96);
		let angle=rand(0,360);
		ascent(let i in 0..24)
		{
			CreateShot01(X,Y,speed,angle+i*15,89,5);
		}
		wait(10);
	}
}

}
//////////////////////////////////////////////////////////////////////
task shotA
{
let looptime=0;
let r=50;
wait(30);
loop
{
	let waittime=30;
	let speed=5;
	SetAction(ACT_SHOT_A,240);
	loop(12)
	{
	let angle=rand(0,360);
	let X=rand(GetCenterX-100,GetCenterX);
	let Y=rand(GetClipMinY+16,GetClipMinY+64);
		ascent(let i in 0..360/(8-looptime))
		{
			CreateShot01(X,Y,speed,angle+i*(9-looptime),95,5);
		}
	wait(10);
	let angle=rand(0,360);
	let X=rand(GetCenterX,GetCenterX+100);
	let Y=rand(GetClipMinY+16,GetClipMinY+64);
		ascent(let i in 0..360/(8-looptime))
		{
			CreateShot01(X,Y,speed,angle+i*(9-looptime),95,5);
		}
	wait(10);
	}
	wait(30);
	SetAction(ACT_SHOT_B,60);
	SpellDraw(6,750);
	summon;
	loop(780)
	{
		if(GetEnemyNum==1){SpellDrawStop;break;}
		yield;
	}
	wait(60);
	if(looptime<1)
	{
	looptime+=1;
	}
	if(looptime<3)
	{
	looptime+=2;
	}
}

}
/////////////////////////////////////////////////////////////////////////
task summon
{
	ascent(let i in 0..4)
	{
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 90*i, 1);
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 90*i+45, -1);
	}
}

	task Wing{
		wait(120);
		let lifetime=30;
		let speed=5.5;
		let angle=0;
		if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){lifetime=15;speed=11;}
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			lifetime=30;
		}
		case("Extream")
		{
			lifetime=40;
		}
		case("Apocalypse")
		{
			lifetime=50;
		}
		let lifetime2=lifetime;
		if(GetY<=GetPlayerY)
		{
			lifetime*=1.25;
		}
		else
		{
			lifetime2*=1.25;
		}
		loop(1){
			ascent(j in 0..90){
				WingPart(GetX,GetY,angle+70+5*sin(3*j),lifetime,speed);
				WingPart(GetX,GetY,angle-70-5*sin(3*j),lifetime2,speed);

				WingPart(GetX,GetY,angle+90+5*sin(3*j),lifetime*3/4,speed);
				WingPart(GetX,GetY,angle-90-5*sin(3*j),lifetime2*3/4,speed);

				WingPart(GetX+20*cos(angle),GetY+20*sin(angle),angle+70+5*sin(3*j),lifetime*5/4,speed);
				WingPart(GetX+20*cos(angle),GetY+20*sin(angle),angle-70-5*sin(3*j),lifetime2*5/4,speed);

				WingPart(GetX,GetY,angle+105+5*sin(3*j),lifetime/2,speed);
				WingPart(GetX,GetY,angle-105-5*sin(3*j),lifetime2/2,speed);

				WingPart(GetX,GetY,angle+165-1*sin(6*j),lifetime*5/12,speed);
				WingPart(GetX,GetY,angle+180-1*sin(6*j),lifetime/2,speed);
				WingPart(GetX,GetY,angle-165-1*sin(6*j),lifetime*5/12,speed);

				yield;
				}
			}
		}

	task WingPart(let x,let y,let angle,let lifetime,let speed){
		function randrect
		{
			return(rand(-2,2));
		}
		let WingUV=[0,0,48,48];
		let WingXY=[-24+randrect,-24+randrect,24+randrect,24+randrect];
		let obj= Obj_Create(OBJ_EFFECT);
		let scale=0.5;
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			scale=0.5;
		}
		case("Extream")
		{
			scale=0.5;
		}
		case("Apocalypse")
		{
			scale=0.5;
		}
		let r=0;
		Obj_SetX(obj, x+r*cos(angle));
		Obj_SetY(obj, y+r*sin(angle));
        	ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\CircleEffect.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, scale,scale);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0,WingXY[0],WingXY[1]);
		ObjEffect_SetVertexXY(obj, 1,WingXY[0],WingXY[3]);
		ObjEffect_SetVertexXY(obj, 2,WingXY[2],WingXY[1]);
		ObjEffect_SetVertexXY(obj, 3,WingXY[2],WingXY[3]);
		
		ObjEffect_SetVertexUV(obj, 0, WingUV[0],WingUV[1]);
		ObjEffect_SetVertexUV(obj, 1, WingUV[0],WingUV[3]);
		ObjEffect_SetVertexUV(obj, 2, WingUV[2],WingUV[1]);
		ObjEffect_SetVertexUV(obj, 3, WingUV[2],WingUV[3]);

		let Alpha=255;
		let StandardScale=scale;
		ObjEffect_SetLayer(obj,1);
		Obj_SetSpeed(obj,speed*0);
		Obj_SetAngle(obj,angle*0);
		let cnt=1;
		let WS=rand(12,14);
		loop(lifetime){
cnt+=1;
if(cnt%10==0)
{
//FireEffect(Obj_GetX(obj),Obj_GetY(obj),255);
}

			Obj_SetX(obj,Obj_GetX(obj)+speed*cos(angle)+WS);
			Obj_SetY(obj,Obj_GetY(obj)+speed*sin(angle));
			r+=speed;
			scale-=StandardScale/lifetime;
			Alpha-=255/lifetime;
			ObjEffect_SetScale(obj, scale,scale);		
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,30,30);
			}
   			yield;
			if(GetCommonDataDefault("BossLife",0)==0){break;}
			}
		Obj_Delete(obj);
		}

task FireEffect(x,y,Alpha)
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd~"..\img/Magic.png");
		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 StandardAlpha=Alpha;
		let R;let G;let B;
		R=255;G=0;B=0;
		ObjEffect_SetLayer(obj,1);
		Obj_SetPosition(obj,x+rand(-20,20),y+rand(-20,20));
		let speed=rand(0.1,0.5);
		let angle=rand(240,300);
		let Scale=rand(0.5,1.0);
		let StandardScale=Scale;
		if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){Obj_Delete(obj);return;}
		loop(5)
		{
			Alpha-=StandardAlpha/5;
			Scale-=StandardScale/5;
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			ObjEffect_SetScale(obj,Scale,Scale);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		Obj_Delete(obj);
}

	task exclamation(let y,){
		let WingUV=[0,9,384,58];
		let WingXY=[-192,-25,192,25];
		let obj= Obj_Create(OBJ_EFFECT);
		let scale=0.8;
		let r=0;
		Obj_SetX(obj, GetCenterX);
		Obj_SetY(obj, y);
        	ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\!.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, 0.95,scale);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0,WingXY[0],WingXY[1]);
		ObjEffect_SetVertexXY(obj, 1,WingXY[0],WingXY[3]);
		ObjEffect_SetVertexXY(obj, 2,WingXY[2],WingXY[1]);
		ObjEffect_SetVertexXY(obj, 3,WingXY[2],WingXY[3]);
		
		ObjEffect_SetVertexUV(obj, 0, WingUV[0],WingUV[1]);
		ObjEffect_SetVertexUV(obj, 1, WingUV[0],WingUV[3]);
		ObjEffect_SetVertexUV(obj, 2, WingUV[2],WingUV[1]);
		ObjEffect_SetVertexUV(obj, 3, WingUV[2],WingUV[3]);

		let Alpha=0;
		let Alpha2=0;

		ObjEffect_SetLayer(obj,3);
		let R=40;
		let angle=0;
		let LightCount=0;
			ascent(i in -3..4)
			{
			ShotEffect(GetCenterX+i*57.0+2,y,10,255,255,255,0,i);
			}
		loop(30)
		{	
/*
			if(LightCount%3==0)
			{
			}
*/
			ascent(let i in 0..2)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			ascent(let i in 2..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha2,255,255,255);
			}
			Alpha+=255/30;
			Alpha2+=255/40;
			angle+=5;
			LightCount+=1;
   			yield;
		}
		loop(10)
		{	
			ascent(let i in 0..2)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			ascent(let i in 2..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha2,255,255,255);
			}
			Alpha2+=255/40;
			yield;
		}
		loop(40)
		{	
			ascent(let i in 0..2)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			ascent(let i in 2..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha2,255,255,255);
			}
			yield;
		}
		loop(10)
		{	
			ascent(let i in 0..2)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			ascent(let i in 2..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha2,255,255,255);
			}
			Alpha-=255/40;
			yield;
		}
		loop(30)
		{	
			ascent(let i in 0..2)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			ascent(let i in 2..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha2,255,255,255);
			}
			Alpha-=255/40;
			Alpha2-=255/40;
   			yield;
		}
		loop(10)
		{	
			ascent(let i in 0..2)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
			ascent(let i in 2..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha2,255,255,255);
			}
			Alpha2-=255/40;
   			yield;
		}
		Obj_Delete(obj);
		}

task CreateExplosion(x,y,Scale,color,ScalePlus,time)
{
  	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,csd~"..\img\effects.png");
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetRenderState(obj, ADD);
	ObjEffect_CreateVertex(obj, 4);

	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);
	let Alpha=250;
	let R=color[0];
	let G=color[1];
	let B=color[2];
	ascent(let i in 0..4)
	{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
	}
	ObjEffect_SetAngle(obj,rand(-80,80),rand(-80,80),rand(0,360));
	loop(time)
	{
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		ObjEffect_SetScale(obj, Scale, Scale);
		Alpha-=250/time;
		Scale+=ScalePlus;
		yield;
	}
	Obj_Delete(obj);
}


task ShotEffect(x,y,delay,Alpha,R,G,B,time)
{
		wait(9+time*3);
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\SquareLine.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, -32, -32);
		ObjEffect_SetVertexXY(obj, 1,32, -32);
		ObjEffect_SetVertexXY(obj, 2, 32, 32);
		ObjEffect_SetVertexXY(obj, 3, -32, 32);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  128, 0);
		ObjEffect_SetVertexUV(obj, 2, 128, 128);
		ObjEffect_SetVertexUV(obj, 3, 0,  128);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}

		Obj_SetPosition(obj,x,y);

		ObjEffect_SetLayer(obj,4);

		let Zangle=45;
		ObjEffect_SetAngle(obj,0,0,Zangle);

		let Scale=0;
		Alpha=0;
		loop(30)
		{
			ObjEffect_SetScale(obj, Scale, Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			Scale+=0.9/30;
			Alpha+=255/30;
			Zangle+=12;
			yield;
		}
			Zangle=45;
		loop(60)
		{
			ObjEffect_SetScale(obj, Scale, Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		loop(30)
		{
			ObjEffect_SetScale(obj, Scale, Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			Scale-=0.9/30;
			Alpha-=255/30;
			Zangle+=12;
			yield;
		}
		Obj_Delete(obj);
}

#include_function ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_Mokou.txt"
}

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
    @Initialize {
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(325);
        SetDamageRateEx(100,10,0,0);
	BombDamageRate=10;
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 36);
        MSDSetCollisionB(GetX, GetY, 12);
        yield;
    }

    @DrawLoop {
      //  DrawGraphic(GetX, GetY);
    }

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,10,0.3);
	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(3)
		{
		FinalizeItemSet(1);
		}
	}
        }

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	ZakoEnemyLifeDisplay;
	move;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}
	ZakoEffect(255,0,0);
    }

task move
{
	let angle=GetAngle;
	let r=90-40*num;
	let rs=r;
	SetMovePosition02(r*cos(angle), r*sin(angle), 30);
	wait(30);
	loop(660)
	{
	SetX(r*cos(angle));
	SetY(r*sin(angle));
	angle+=1*num;
	yield;
	}
	loop(60)
	{
	r-=rs/60;
	SetX(r*cos(angle));
	SetY(r*sin(angle));
	angle+=1*num;
	yield;
	}
	VanishEnemy;

}

task shotM
{
wait(30);
loop(3)
{
let angle=GetAngleToPlayer;
ascent(let i in -1..2)
{
CreateShot01(GetX,GetY,3,angle+i*2,9,5);
}
wait(60);
}
wait(30);

let angle=atan2(GetEnemyY-GetY,GetEnemyX-GetX);
angle=atan2(GetPlayerY-GetEnemyY,GetPlayerX-GetEnemyX);
loop(24)
{
	angle=180+atan2(GetEnemyY-GetY,GetEnemyX-GetX);
	CreateShot01(GetX,GetY,3.25,angle,9,5);	
	wait(5);
}
wait(60);
loop(10)
{
	angle=atan2(GetPlayerY-GetEnemyY,GetPlayerX-GetEnemyX);
	CreateShot01(GetX,GetY,3,angle,9,5);	
	wait(15);
}
wait(60);
angle=rand(0,360);
ascent(let i in 0..40)
{
	CreateShot01(GetX,GetY,3.00,angle+i*9,9,5);
}

}
/////////////////////////////////////////////////////////
task shotE
{
wait(60);
loop(4)
{
let angle=GetAngleToPlayer;
loop(5)
{
	angle=GetAngleToPlayer;
	ascent(let i in -1..2)
	{
	CreateShot01(GetX,GetY,4,angle+i*4.0,9,5);
	}
	wait(3);
}
wait(30);
}
wait(60);
let angle=0;
loop(15)
{
	angle=atan2(GetPlayerY-GetEnemyY,GetPlayerX-GetEnemyX);
	CreateShot01(GetX,GetY,rand(1.5,2),angle+rand(-30,30),9,5);
	wait(12);
}
wait(60);
loop(60)
{
	angle=180+atan2(GetEnemyY-GetY,GetEnemyX-GetX);
	CreateShot01(GetX,GetY,4,angle,9,5);
	wait(3);
}


}
////////////////////////////////////////////////////////////
task shotA
{
wait(30);
loop(4)
{
	let angle=180+atan2(GetEnemyY-GetY,GetEnemyX-GetX);
	ascent(let j in 0..3)
	{
		ascent(let i in 0..12)
		{
			CreateShot01(GetX,GetY,2.5,angle+i*30+j*2.5,9,5);
		}
	}
wait(60);
}
wait(60);

loop(60)
{
	let angle=180+atan2(GetEnemyY-GetY,GetEnemyX-GetX);
	CreateShot01(GetX,GetY,4,angle+90,9,5);
	CreateShot01(GetX,GetY,4,angle-90,9,5);
	wait(3);
}

wait(60);
let angle=rand(0,360);
ascent(let i in 0..48)
{
	ascent(let j in 0..3)
	{
	CreateShot01(GetX,GetY,2.5-0.25*j,angle+i*7.5,9,5);
	}
}
}
    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#include_function ".\..\txt/StageEnemydata.txt"
}

#include_script ".\..\txt/EnemyShotData.txt"
