script_enemy_main
{
        let csd     = GetCurrentScriptDirectory;
	let speed = GetSpeed;
	let angle = GetAngle;
	let num = GetArgument;
	let imgEnemy=csd~"..\lib\fairy_red.png";
	let imgFam  = csd ~ "..\img\familiar.png";
	let SelectedDifficult=GetCommonDataDefault("SELECTEDDIFFICULT","Normal");
    @Initialize {
        SetLife(3000);
        SetDamageRate(100,100);
	SetInvincibility(300);
	SetTexture(imgEnemy);
	SetTexture(imgFam);
	Initialize_Fairy(7);
	Tmain;
	}

    @MainLoop {
	SetCollisionA(GetX(),GetY(),48);
        SetCollisionB(GetX(),GetY(),8);
	yield;
    }

        @DrawLoop {
		DrawFairy(imgEnemy );
	}

        @Finalize
        {
		if(!BeVanished)
		{
			loop(60)
			{
				ItemSet(GetX+rand(-20,20),GetY+rand(-20,20),2);
			}
		}
	DeleteAllEnemyWithoutBoss;
	DeleteEnemyShotToItem(SHOT);
        } 

task Tmain
{
yield;
GetDamege;
move;
Subshot;
summon;
eraze;
Explode(1);
ItemDrop;
}

task ItemDrop
{
	while(GetLife>1000)
	{
		yield;
	}
		if(!BeVanished)
		{
			loop(60)
			{
				ItemSet(GetX+rand(-20,20),GetY+rand(-20,20),2);
			}
		}
	DeleteEnemyShotToItem(SHOT);
	SetCommonData("kyodaizakoVanish",true);
	VanishEnemy;
}

task GetDamege
{
loop
{
	if(GetHitCount!=0)
	{
		SetColor(150,150,255);
		wait(10);
	}
	else
	{
		SetColor(255,255,255);
		if(GetLife<1500)
		{
			SetColor(255,150,150);
		}
	}
yield;
}
}

task move
{
	SetMovePosition03(GetX,GetCenterY-140,20,5);
	wait(240);
	SetSpeed(0.1);
	SetAngle(90);
}

task summon
{
wait(120);
alternative(SelectedDifficult)
case("Easy")
{
	ascent(let i in 0..4)
	{
	CreateEnemyFromScript("Familiar", GetX, GetY,2, i*90,1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, i*90, -1);
	}
}
case("Normal")
{
	ascent(let i in 0..6)
	{
	CreateEnemyFromScript("Familiar", GetX, GetY,2, i*60,1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, i*60, -1);
	}
}
case("Hard")
{
	ascent(let i in 0..8)
	{
	CreateEnemyFromScript("Familiar", GetX, GetY,2, i*45,1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, i*45, -1);
	}
}
case("Lunatic")
{
	ascent(let i in 0..10)
	{
	CreateEnemyFromScript("Familiar", GetX, GetY,2, i*36,1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, i*36, -1);
	}
}
case("Extra")
{
	ascent(let i in 0..12)
	{
	CreateEnemyFromScript("Familiar", GetX, GetY,2, i*30,1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, i*30, -1);
	}
}
}

task Subshot
{
wait(240);
let r=2;
let angle=90;
alternative(SelectedDifficult)
case("Easy")
{
	loop
	{
		ascent(let i in -2..3)
		{
			ascent(let k in 0..6)
			{
		//	CreateShot01(GetX,GetY,2,GetAngleToPlayer+1.5*i,9,10);
			CreateShot01ToItem(GetX,GetY,2,GetAngleToPlayer+1.5*i+60*k,9,10);
			}
		}
		wait(120);
	}
}
case("Normal")
{
	loop
	{
		ascent(let i in -3..4)
		{
			ascent(let k in 0..6)
			{
		//	CreateShot01(GetX,GetY,3,GetAngleToPlayer+1.5*i,9,10);
			CreateShot01ToItem(GetX,GetY,3,GetAngleToPlayer+1.5*i+k*60,9,10);
			}
		}
		wait(120);
	}
}
case("Hard")
{
	loop
	{
		ascent(let i in -4..5)
		{
			ascent(let k in 0..6)
			{
		//	CreateShot01(GetX,GetY,3.5,GetAngleToPlayer+1.5*i,9,10);
			CreateShot01ToItem(GetX,GetY,3.5,GetAngleToPlayer+1.5*i+60*k,9,10);
			}
		}
		wait(120);
	}
}
case("Lunatic")
{
	loop
	{
		ascent(let i in -5..6)
		{
			ascent(let k in 0..6)
			{
		//	CreateShot01(GetX,GetY,4,GetAngleToPlayer+1.5*i,9,10);
			CreateShot01ToItem(GetX,GetY,4,GetAngleToPlayer+1.5*i+60*k,9,10);
			}
		}
		wait(120);
	}
}

case("Extra")
{
	loop
	{
		ascent(let i in -6..7)
		{
			ascent(let k in 0..6)
			{
		//	CreateShot01(GetX,GetY,4,GetAngleToPlayer+1.5*i,9,10);
			CreateShot01ToItem(GetX,GetY,4,GetAngleToPlayer+1.5*i+k*60,9,10);
			}
		}
		wait(90);
	}
}

}

task eraze
{
while(!BeVanished)
{
        	if(GetX<GetClipMinX-64||GetX>GetClipMaxX+64||GetY<GetClipMinY-32||GetY>GetClipMaxY+32)
        	{
        		VanishEnemy();
        	}
yield;
}
}


#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 dir = num;
	let angle=GetAngle;
	let speed=GetSpeed;
	let X=GetX;
	let Y=GetY;
	let SelectedDifficult=GetCommonDataDefault("SELECTEDDIFFICULT","Normal");
    @Initialize {
        SetLife(10000);
	SetDamageRateEx(100,100,100,1);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

    @MainLoop {
	SetCollisionA(GetX(),GetY(),32);
	if(GetCommonDataDefault("kyodaizakoVanish",false)==true)
	{
		ItemSet(GetX+rand(-20,20),GetY+rand(-20,20),1);
		VanishEnemy;
	}
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

        @Finalize
        {
		if(!BeVanished)
		{
			ItemSet(GetX,GetY,1);
		}
        } 

    task TMain {
        yield;
	move;
	shot;
    }

task move
{
let r=0;
loop(60)
{
	SetX(X+r*cos(angle));
	SetY(Y+r*sin(angle));
	r+=1.1+0.4*dir;
	angle+=5*dir;
	yield;
}
loop
{
SetCoordinateType(COODINATE_TYPE_PARENT);
	SetX(r*cos(angle));
	SetY(r*sin(angle));
SetCoordinateType(COODINATE_TYPE_ABSOLUTE);
	angle+=5*dir;
	yield;
}
VanishEnemy;
}

task shot
{
wait(60);
alternative(SelectedDifficult)
case("Easy")
{
	loop
	{
	//	CreateShot01(GetX,GetY,1.5,angle,33,0);
		CreateShot01ToItem(GetX,GetY,1.5,angle,33,0);
		wait(5);
	}
}
case("Normal")
{
	loop
	{
	//	CreateShot01(GetX,GetY,1.5,angle,33,0);
		CreateShot01ToItem(GetX,GetY,1.5,angle,33,0);
		wait(5);
	}
}
case("Hard")
{
	loop
	{
	//	CreateShot01(GetX,GetY,1.5,angle,33,0);
		CreateShot01ToItem(GetX,GetY,1.5,angle,33,0);
		wait(5);
	}
}
case("Lunatic")
{
	loop
	{
	//	CreateShot01(GetX,GetY,1.5,angle,33,0);
		CreateShot01ToItem(GetX,GetY,1.5,angle,33,0);
		wait(5);
	}
}
case("Extra")
{
	loop
	{
	//	CreateShot01(GetX,GetY,1.5,angle,33,0);
		CreateShot01ToItem(GetX,GetY,1.5,angle,33,0);
		wait(5);
	}
}
}


    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#include_function ".\..\txt/StageEnemydata.txt"
}
#include_script ".\..\txt/EnemyShotData.txt"