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(2000);
        SetDamageRate(100,100);
	SetTexture(imgEnemy);
	Initialize_Fairy(7);
	Tmain;
	}

    @MainLoop {
	if(GetLife<=1000){VanishEnemy;}
	BulletNum=GetEnemyShotCount;
	SetSkyCollision(GetX,GetY,48);
	yield;
    }

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

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

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

summon(GetX,GetY);

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

wait(1190);
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 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);
}

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

task move
{
	let angle=-10;
	SetSpeed(1.5);
	SetAngle(angle);
	wait(180);
	loop(90)
	{
		angle+=100/90;
		SetAngle(angle);
		yield;
	}
	wait(60);
	loop(90)
	{
		angle+=110/90;
		SetAngle(angle);
		yield;
	}
	wait(120);
	loop(60)
	{
		angle+=150/90;
		SetAngle(angle);
		yield;
	}
}

task shotM
{
wait(30);
loop
{
let angle=rand(-3,3);
	ascent(let i in -10..11)
	{
		SkyCreateShot01(GetX,GetY,3,GetAngle+angle+i*6,9,5);
	}
wait(30);
}
}

task shotE
{
wait(30);
loop
{
let angle=rand(-3,3);
	ascent(let i in -15..16)
	{
		SkyCreateShot01(GetX,GetY,2.5,GetAngle+angle+i*6.0,9,5);
	}
wait(20);
}
}

task shotA
{
wait(30);
loop
{
let angle=rand(-3,3);
	ascent(let i in -15..16)
	{
		SkyCreateShot01(GetX,GetY,3.0,GetAngle+angle+i*6.5,9,5);
	}
wait(15);
}
}
#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;
    @Initialize {
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(50000);
        SetDamageRateEx(100,0,50,0);
	TMain;
    }

    @MainLoop {
	SetSkyCollision(GetX,GetY,48);
        yield;
	if(GetCommonDataDefault("STAGE3HAYAWAMASHI",false))
	{
		SetSpeed(0);
	}
    }

    @DrawLoop {
       // DrawGraphic(GetX, GetY);
    }
        @Finalize
        {
		FinalizeItemAndShotnum(1);
		MagicCircleBreak(GetX,GetY,13,0.3);
        } 

    task TMain {
        yield;
	ElementalEffect(255,255,0,1.0);
	ElementalAutoErazeTime(1190);
	OutDamageRateZero;
	GetDamege;
	move;
	Break;
alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
case("Moderate")
{
shotM;
}
case("Extream")
{
shotE;
}
case("Apocalypse")
{
shotA;
}
    }

task Break
{
loop
{
	if(GetCommonDataDefault("STAGE3HAYAWAMASHI",false))
	{
		wait(num*3+15);
		AddLife(-GetLife);
	}
yield;
}
}

task move
{
	let angle=-10;
	SetSpeed(1.5);
	SetAngle(angle);
	wait(180);
	loop(90)
	{
		angle+=100/90;
		SetAngle(angle);
		yield;
	}
	wait(60);
	loop(90)
	{
		angle+=110/90;
		SetAngle(angle);
		yield;
	}
	wait(120);
	loop(60)
	{
		angle+=150/90;
		SetAngle(angle);
		yield;
	}
}

task shotM
{
let r=20;
wait(30);
	loop
	{
	if(GetCommonDataDefault("STAGE3HAYAWAMASHI",false)){break;}
	shot1;
	wait(15);
	}

	task shot1
	{
		SkyCreateShot01(GetX+r*cos(GetAngle-90),GetY+r*sin(GetAngle-90),4,GetAngle-90,9,5);
		SkyCreateShot01(GetX+r*cos(GetAngle+90),GetY+r*sin(GetAngle+90),4,GetAngle+90,9,5);
	}
}
///////////////////////////////////////////////////////////////
task shotE
{
let r=20;
wait(30);
	loop
	{
	if(GetCommonDataDefault("STAGE3HAYAWAMASHI",false)){break;}
	shot1;
	wait(10);
	}

	task shot1
	{
		SkyCreateShot01(GetX+r*cos(GetAngle-90),GetY+r*sin(GetAngle-90),3,GetAngle-90,9,5);
		SkyCreateShot01(GetX+r*cos(GetAngle+90),GetY+r*sin(GetAngle+90),3,GetAngle+90,9,5);
	}
}
//////////////////////////////////////////////////////////////
task shotA
{
let r=20;
wait(30);
	loop
	{
	if(GetCommonDataDefault("STAGE3HAYAWAMASHI",false)){break;}
	shot1;
	wait(5);
	}

	task shot1
	{
		SkyCreateShot01(GetX+r*cos(GetAngle-90),GetY+r*sin(GetAngle-90),3,GetAngle-90,9,5);
		SkyCreateShot01(GetX+r*cos(GetAngle+90),GetY+r*sin(GetAngle+90),3,GetAngle+90,9,5);
	}

}

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

script_enemy Dummy {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
	let PastX=[];
	let PastY=[];
    @Initialize {
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(50000);
        SetDamageRateEx(100,0,50,0);
	TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
       // DrawGraphic(GetX, GetY);
    }
        @Finalize
        {
		FinalizeItemAndShotnum(1);
		MagicCircleBreak(GetX,GetY,13,0.3);
        } 

    task TMain {
        yield;
	ElementalAutoErazeTime(1190);
	OutDamageRateZero;
	GetDamege;
	move;
	Break;
	SavePosition;
    }

task SavePosition
{
loop
{
PastX=PastX~[GetX];
PastY=PastY~[GetY];
yield;
}
}

task Break
{
loop
{
	if(GetCommonDataDefault("STAGE3HAYAWAMASHI",false))
	{
		AddLife(-GetLife);
	}
yield;
}
}

task move
{
	let angle=-10;
	SetSpeed(1.5);
	SetAngle(angle);
	wait(180);
	loop(90)
	{
		angle+=100/90;
		SetAngle(angle);
		yield;
	}
	wait(60);
	loop(90)
	{
		angle+=110/90;
		SetAngle(angle);
		yield;
	}
	wait(120);
	loop(60)
	{
		angle+=150/90;
		SetAngle(angle);
		yield;
	}
}

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


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