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(5500);
        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(150)
			{
				ItemSet(GetX+rand(10,30)*cos(rand(0,360)),GetY+rand(10,30)*sin(rand(0,360)),1);
			}
			ItemSet(GetX,GetY,5);
		}
	DeleteEnemyShotToItem(SHOT);
        } 

task Tmain
{
yield;
GetDamege;
move;
shot;
subshot;
summon;
Explode(1);
ItemDrop;

eraze;
}

task ItemDrop
{
	while(GetLife>1000)
	{
		yield;
	}
		if(!BeVanished)
		{
			loop(150)
			{
				ItemSet(GetX+rand(10,30)*cos(rand(0,360)),GetY+rand(10,30)*sin(rand(0,360)),1);
			}
			ItemSet(GetX,GetY,5);
		}
	DeleteEnemyShotToItem(SHOT);
	SetCommonData("GaraVanish",true);
	VanishEnemy;
}

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

task move
{
	SetMovePosition03(GetX,GetCenterY-100,20,5);
	wait(3600);
	SetSpeed(2);
	SetAngle(-90);
}

task shot
{
wait(240);
loop
{
	loop(2)
	{
		CShot(GetX-70,GetY);
		wait(60);
		CShot(GetX+70,GetY);
		wait(60);
		CShot(GetX-140,GetY-50);
		wait(60);
		CShot(GetX+140,GetY-50);
		wait(60);
	}
	wait(60);
	loop(2)
	{
		CShot(GetX-140,GetY-50);
		wait(20);
		CShot(GetX-70,GetY);
		wait(20);
		CShot(GetX+70,GetY);
		wait(20);
		CShot(GetX+140,GetY-50);
		wait(20);
	}
	wait(120);
}
}

task CShot(x,y)
{
alternative(SelectedDifficult)
case("Easy")
{
//	CreateShot01(x,y,6,atan2(GetPlayerY-y,GetPlayerX-x),165,20);
	CreateShot01ToItem(x,y,6,atan2(GetPlayerY-y,GetPlayerX-x),165,20);
	loop(12)
	{
	//	CreateShot01(x,y,rand(4,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-4,4),25,20);
		CreateShot01ToItem(x,y,rand(4,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-4,4),25,20);
	}
	loop(24)
	{
	//	CreateShot01(x,y,rand(1,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-10,10),9,20);
		CreateShot01ToItem(x,y,rand(1,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-10,10),9,20);
	}
}
case("Normal")
{
//	CreateShot01(x,y,6,atan2(GetPlayerY-y,GetPlayerX-x),165,20);
	CreateShot01ToItem(x,y,6,atan2(GetPlayerY-y,GetPlayerX-x),165,20);
	loop(18)
	{
	//	CreateShot01(x,y,rand(4,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-5,5),25,20);	
		CreateShot01ToItem(x,y,rand(4,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-5,5),25,20);	
	}
	loop(36)
	{
	//	CreateShot01(x,y,rand(1,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-15,15),9,20);	
		CreateShot01ToItem(x,y,rand(1,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-15,15),9,20);	
	}
}
case("Hard")
{
//	CreateShot01(x,y,6,atan2(GetPlayerY-y,GetPlayerX-x),165,20);
	CreateShot01ToItem(x,y,6,atan2(GetPlayerY-y,GetPlayerX-x),165,20);
	loop(24)
	{
	//	CreateShot01(x,y,rand(4,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-6,6),25,20);
		CreateShot01ToItem(x,y,rand(4,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-6,6),25,20);	
	}
	loop(45)
	{
	//	CreateShot01(x,y,rand(1,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-18,18),9,20);	
		CreateShot01ToItem(x,y,rand(1,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-18,18),9,20);	
	}
}
case("Lunatic")
{
//	CreateShot01(x,y,6,atan2(GetPlayerY-y,GetPlayerX-x),165,20);
	CreateShot01ToItem(x,y,6,atan2(GetPlayerY-y,GetPlayerX-x),165,20);
	loop(30)
	{
	//	CreateShot01(x,y,rand(4,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-8,8),25,20);	
		CreateShot01ToItem(x,y,rand(4,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-8,8),25,20);	
	}
	loop(54)
	{
	//	CreateShot01(x,y,rand(1,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-18,18),9,20);	
		CreateShot01ToItem(x,y,rand(1,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-18,18),9,20);	
	}
}

case("Extra")
{
//	CreateShot01(x,y,6,atan2(GetPlayerY-y,GetPlayerX-x),165,20);
	CreateShot01ToItem(x,y,6,atan2(GetPlayerY-y,GetPlayerX-x),165,20);
	loop(36)
	{
	//	CreateShot01(x,y,rand(4,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-8,8),25,20);	
		CreateShot01ToItem(x,y,rand(4,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-8,8),25,20);	
	}
	loop(60)
	{
	//	CreateShot01(x,y,rand(1,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-18,18),9,20);	
		CreateShot01ToItem(x,y,rand(1,6),atan2(GetPlayerY-y,GetPlayerX-x)+rand(-18,18),9,20);	
	}
}

}

task subshot
{
wait(240);
	if(SelectedDifficult!="Extra")
	{
		return;
	}
	loop
	{
		ascent(let i in 0..16)
		{
			CreateShot01ToItem(GetX,GetY,1,GetAngleToPlayer+i*22.5,RED03,20);
		}
		wait(90);
	}
}

task summon
{
	wait(120);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, 0,1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, 0, -1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, 0,2);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, 0, -2);
}

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(),48);
	if(GetCommonDataDefault("GaraVanish",false)==true)
	{
		loop(10)
		{
			ItemSet(GetX+rand(-20,20),GetY+rand(-20,20),1);
		}
		VanishEnemy;
	}
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

        @Finalize
        {
		if(!BeVanished)
		{
			loop(10)
			{
				ItemSet(GetX+rand(-20,20),GetY+rand(-20,20),1);
			}
		}
        } 

    task TMain {
        yield;
	move;
    }

task move
{
	SetMovePosition03(GetCenterX+num*70,GetCenterY-100-(absolute(num)-1)*50,20,5);
}

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