script_enemy_main
{
        let csd     = GetCurrentScriptDirectory;
	let speed = GetSpeed;
	let angle = GetAngle;
	let num = GetArgument;
	let imgEnemy;

	imgEnemy=csd~"..\lib\fairy_red.png";

	let SelectedDifficult=GetCommonDataDefault("SELECTEDDIFFICULT","Normal");

    @Initialize {
	SpecialBreak=true;
        SetLife(2300);
        SetDamageRate(100,100);
	SetTexture(imgEnemy);
	Initialize_Fairy(7);
	Tmain;
	}

    @MainLoop {
	if(GetLife<=1000){VanishEnemy;SetCommonData("BitDefeatNum",GetCommonDataDefault("BitDefeatNum",0)+1);}
	BulletNum=GetEnemyShotCount;
	SetGroundCollision(GetX,GetY,48);
	yield;
    }

        @DrawLoop {
		SetColor(ZakoColor[0],ZakoColor[1],ZakoColor[2]);
		DrawFairy(imgEnemy);
		DrawMagicCircle("WHITE",0.50);
	}

        @Finalize
        {
		MagicCircleBreak(GetX,GetY,2,0.5);
		FinalizeItemAndShotnumWithDelete(15);
		SetCommonData("STAGE5RING1",true);
        } 

task Tmain
{
yield;
OutDamageRateZero;
SpecialAutoErazeTime(1200);
GetDamege;
MagicColor;
move;

summon(GetX,GetY);

alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
case("Moderate")
{
shotM;
}
case("Extream")
{
shotE;
}
case("Apocalypse")
{
shotA;
}

wait(890);
SpecialBreak=false;

}

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

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

yield;
}
VanishEnemy;
}


task summon(x,y)
{
	ascent(let i in 0..8)
	{
        CreateEnemyFromScript("Familiar", x, y,
                              0, 0, i);
	}
}

task move
{
	SetSpeed(0.8);
	SetAngle(135);
}

task shotM
{
wait(30);
let angle=0;
loop
{
	loop(5)
	{
	ascent(let i in 0..6)
	{
		GroundCreateShot01(GetX,GetY,3.0,angle+i*60,9,5);
	}
	angle+=3;
	wait(3);
	}
	wait(45);
	angle+=12;
}
}

task shotE
{
wait(30);
let angle=0;
loop
{
	loop(8)
	{
	ascent(let i in 0..8)
	{
		GroundCreateShot01(GetX,GetY,2.5,angle+i*45,9,5);
	}
	angle+=2;
	wait(2);
	}
	wait(45);
	angle+=6;
}
}

task shotA
{
wait(30);
let angle=0;
loop
{
	loop(12)
	{
	ascent(let i in 0..8)
	{
		GroundCreateShot01(GetX,GetY,2.5,angle+i*45,9,5);
	}
	angle+=2;
	wait(2);
	}
	wait(36);
	angle+=6;
}
}

task SpecialZakoLifeDisplay//ライフバーのバー部分の設定
{
	let ZakoLifeMax=GetLife-1000;
	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>1000)
		{
			Obj_SetPosition(obj,GetX-XAdjust,GetY-16);
			scale=Sscale*(GetLife-1000)/ZakoLifeMax;
			ObjEffect_SetVertexColor(obj,0,255,255,255,0);
			ObjEffect_SetVertexColor(obj,1,255,255,255-255*(GetLife-1000)/ZakoLifeMax,0);
			ObjEffect_SetVertexColor(obj,2,255,255,255-255*(GetLife-1000)/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-1000)/ZakoLifeMax,0);
			ObjEffect_SetVertexColor(obj,2,0,255,255-255*(GetLife-1000)/ZakoLifeMax,0);
			ObjEffect_SetVertexColor(obj,3,0,255,255,0);
			}
			ObjEffect_SetScale(obj, scale,0.8);
			yield;
		}
		Obj_Delete(obj);
}

#include_function ".\..\txt/StageEnemydata.txt"
#include_function ".\..\lib\lib_anime_fairy.txt"
}

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

    @MainLoop {
	SetGroundCollision(GetX,GetY,24);
        yield;
	if(GetCommonDataDefault("STAGE5RING1",false))
	{
		SetSpeed(0);
	}
    }

    @DrawLoop {
		SetColor(ZakoColor[0],ZakoColor[1],ZakoColor[2]);
	//	DrawFairy(imgEnemy);
		DrawMagicCircle("WHITE",0.20);
       // DrawGraphic(GetX, GetY);
    }
        @Finalize
        {
		FinalizeItemAndShotnum(2);
		MagicCircleBreak(GetX,GetY,13,0.3);
	if(GetCommonDataDefault("STAGE5RING1",false))
	{
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			CreateShotA(0,GetX,GetY,5);
			SetShotDataA(0,0,0,GetAngleToPlayer,0,0.10,6,9);
			FireShot(0);
		}
		case("Extream")
		{
			CreateShotA(0,GetX,GetY,5);
			CreateShotA(1,GetX,GetY,5);
			SetShotDataA(0,0,0,GetAngleToPlayer,0,0.10,6,9);
			SetShotDataA(1,0,0,GetAngleToPlayer,0,0.125,6,9);
			FireShot(0);
			FireShot(1);
		
		}
		case("Apocalypse")
		{	
			CreateShotA(0,GetX,GetY,5);
			CreateShotA(1,GetX,GetY,5);
			CreateShotA(2,GetX,GetY,5);
			SetShotDataA(0,0,0,GetAngleToPlayer,0,0.10,6,9);
			SetShotDataA(1,0,0,GetAngleToPlayer,0,0.125,6,9);
			SetShotDataA(2,0,0,GetAngleToPlayer,0,0.15,6,9);
			FireShot(0);	
			FireShot(1);
			FireShot(2);	
		}
	}

        } 

    task TMain {
        yield;
	//ElementalEffect(255,255,0,1.0);
	SpecialElementalAutoErazeTime(1190);
	OutDamageRateZero;
	ZakoEnemyLifeDisplay;
	GetDamege;
	MagicColor;
	move;
	Break;
	Block;
	ErazeBullet;

alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
case("Moderate")
{
shotM;
}
case("Extream")
{
shotE;
}
case("Apocalypse")
{
shotA;
}

    }


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

yield;
}
VanishEnemy;
}

task ErazeBullet
{
loop
{
	DeleteEnemyShotImmediatelyInCircle(SHOT,GetX,GetY,24);
	yield;
}
}

task Break
{
let RR=0;
loop
{
	if(GetCommonDataDefault("STAGE5RING1",false))
	{
	let SRR=RR;
		loop(15)
		{
			StarLaserEffect(GetX,GetY,RR,6,AngleFromParent+180);
			RR-=SRR/15;
			yield;
		}
		AddLife(-GetLife);
	}
	else
	{
		StarLaserEffect(GetX,GetY,BitRadius,6,AngleFromParent+180);
		RR=BitRadius;
	}
yield;
}
}

task move
{
	let R=0;
	let angle=num*45;
	loop
	{
		SetX(R*cos(angle));
		SetY(R*sin(angle));
		if(R<180)
		{
		R+=0.5;
		}
		angle-=0.4;
		BitRadius=R;
		AngleFromParent=angle;
		yield;
	}
}

task shotM
{
let r=29;
wait(90);
	loop(39)
	{
	if(GetCommonDataDefault("STAGE5RING1",false)){break;}
	shot1;
	wait(20);
	}

	task shot1
	{
		let angle=AngleFromParent;
		BitCreateShot01(GetX+r*cos(angle),GetY+r*sin(angle),2.5,angle,14,18);
	}
}
///////////////////////////////////////////////////////////////
task shotE
{
let r=29;
wait(90);
	loop(52)
	{
	if(GetCommonDataDefault("STAGE5RING1",false)){break;}
	shot1;
	wait(15);
	}

	task shot1
	{
		let angle=AngleFromParent;
		BitCreateShot01(GetX+r*cos(angle),GetY+r*sin(angle),2.0,angle,14,27);
	}
}
//////////////////////////////////////////////////////////////
task shotA
{
let r=29;
wait(90);
	loop(39)
	{
		loop(5)
		{
		if(GetCommonDataDefault("STAGE5RING1",false)){break;}
		shot1;
		wait(2);
		}
	wait(10);
	}

	task shot1
	{
		let angle=AngleFromParent;
		BitCreateShot01(GetX+r*cos(angle),GetY+r*sin(angle),2.0,angle,14,27);
	}

}

task BitCreateShot01(x,y,speed,angle,gra,delay)
{
	if(!EnemyGroundShotSeal)
	{
	BShot(GetX,GetY,speed,angle,gra,delay);
	/*
	ShotEffect(x,y,speed,angle,255,50,50,200);
	wait(delay);
	CreateShot01(x,y,speed,angle,gra,0);
	*/
	}
}

	task BShot(x,y,speed,angle,gra,delay)
	{

		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, gra);
		//ObjShot_SetDelay(obj, delay);
		ObjShot_SetBombResist(obj,true);
		loop(delay)
		{
			yield;
		}
		ObjShot_SetBombResist(obj,false);
	}

task ShotEffect(x,y,delay,Alpha,R,G,B)
{
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\Light.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,  64, 0);
		ObjEffect_SetVertexUV(obj, 2, 64, 64);
		ObjEffect_SetVertexUV(obj, 3, 0,  64);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}

		Obj_SetPosition(obj,x,y);

		ObjEffect_SetLayer(obj,3);

		let Zangle=rand(0,360);
		ObjEffect_SetAngle(obj,0,0,Zangle);

		let Scale=0.75;
		loop(delay)
		{
			ObjEffect_SetScale(obj, Scale, Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=6;
			Scale-=1.0/delay;
			yield;
		}
		Obj_Delete(obj);
}

task Block
{
loop
{
	while(GetDistanceToPlayer<=24)
	{
		let angle=GetAngleToPlayer;
		SetPlayerX(GetPlayerX+cos(angle));
		SetPlayerY(GetPlayerY+sin(angle));
	}
yield;
}
}

task StarLaserEffect(x,y,length,width,angle)
{
		let imgBer=csd~"..\img\ber.png";
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjShot_SetBombResist(obj,true);
		ObjEffect_SetVertexXY(obj, 0, 0, -2);
		ObjEffect_SetVertexXY(obj, 1,length,  -2);
		ObjEffect_SetVertexXY(obj, 2,length, 2);
		ObjEffect_SetVertexXY(obj, 3,  0,  2);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  228, 27);
		ObjEffect_SetVertexUV(obj, 2, 228, 33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);

		let Alpha=60;
		let R=255;
		let G=255;
		let B=255;

		R=39;
		G=64;
		B=139+61;


		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,angle);
		ObjEffect_SetAngle(obj,0,0,angle);

		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		loop(1)
		{
		Obj_SetPosition(obj,x,y);
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		Alpha-=100/15;
		//if(OnPlayerMissed){Alpha=0;}
		yield;
		}
		Obj_Delete(obj);
}

#include_function ".\..\txt/StageEnemydata.txt"
}

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