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

    @MainLoop {
	if(GetLife>1000)
	{
	SetCollisionA(GetX(),GetY(),48);
        SetCollisionB(GetX(),GetY(),8);
	}
	yield;
    }

        @DrawLoop {
	if(GetLife>1000)
	{
		DrawFairy(imgEnemy);
	}
	}

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

task Tmain
{
GetDamege;
move;
shot;
eraze;
AutoErazeTime(900);
Explode(4);
ItemDrop;
}

task ItemDrop
{
	while(GetLife>1000)
	{
		yield;
	}
		if(!BeVanished)
		{
			loop(3)
			{
			ItemSet(GetX+rand(-20,20),GetY+rand(-20,20),1);
			ItemSet(GetX+rand(-20,20),GetY+rand(-20,20),2);
			}
		}
}

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

task move
{
	SetSpeed(speed);
	SetAngle(angle);
}

task shot
{
alternative(SelectedDifficult)
case("Easy")
{
wait(20);
	loop(5)
	{
	if(GetLife<=1000)
	{
		break;
	}
		let angle=GetAngleToPlayer;
		ascent(let i in 0..3)
		{
		//	CreateShot01(GetX,GetY,2+0.5*i,angle,RED11,10);
		//	CreateShotFromScript( "shot1",GetX, GetY,2+0.5*i,angle, 10, RED11);
			CreateShot01ToItem(GetX,GetY,2+0.5*i,angle,RED11,10);
		}
		wait(60);
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in 0..8)
		{
		//	CreateShot01(GetX,GetY,2,i*45,BLUE01,10);
		//	CreateShotFromScript( "shot1",GetX, GetY,2,i*45, 10,BLUE01);
			CreateShot01ToItem(GetX,GetY,2,i*45,BLUE01,10);
		}
	}
}
case("Normal")
{
wait(20);
	loop(5)
	{
	if(GetLife<=1000)
	{
		break;
	}
		let angle=GetAngleToPlayer;
		ascent(let i in 0..3)
		{
		//	CreateShot01(GetX,GetY,3+0.5*i,angle,RED11,10);
		//	CreateShotFromScript( "shot1",GetX, GetY,3+0.5*i,angle, 10, RED11);
			CreateShot01ToItem(GetX,GetY,3+0.5*i,angle,RED11,10);
		}
		wait(60);
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in 0..12)
		{
		//	CreateShot01(GetX,GetY,2,i*30,BLUE01,10);
		//	CreateShotFromScript( "shot1",GetX, GetY,2,i*30, 10,BLUE01);
			CreateShot01ToItem(GetX,GetY,2,i*30,BLUE01,10);
		}
	}
}
case("Hard")
{
wait(20);
	loop(5)
	{
	if(GetLife<=1000)
	{
		break;
	}
		let angle=GetAngleToPlayer;
		ascent(let i in 0..4)
		{
		//	CreateShot01(GetX,GetY,2+0.5*i,angle,RED11,10);
		//	CreateShotFromScript( "shot1",GetX, GetY,2+0.5*i,angle, 10, RED11);
			CreateShot01ToItem(GetX,GetY,2+0.5*i,angle,RED11,10);
		}
		wait(60);
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in 0..15)
		{
		//	CreateShot01(GetX,GetY,2.5,i*24,BLUE01,10);
		//	CreateShotFromScript( "shot1",GetX, GetY,2.5,i*24, 10,BLUE01);
			CreateShot01ToItem(GetX,GetY,2.5,i*24,BLUE01,10);
		}
	}
}
case("Lunatic")
{
wait(20);
	loop(5)
	{
	if(GetLife<=1000)
	{
		break;
	}
		let angle=GetAngleToPlayer;
		ascent(let i in 0..5)
		{
		//	CreateShot01(GetX,GetY,2+0.5*i,angle,RED11,10);
		//	CreateShotFromScript( "shot1",GetX, GetY,2+0.5*i,angle, 10, RED11);
			CreateShot01ToItem(GetX,GetY,2+0.5*i,angle,RED11,10);
		}
		wait(60);
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in 0..18)
		{
		//	CreateShot01(GetX,GetY,3,i*20,BLUE01,10);
		//	CreateShotFromScript( "shot1",GetX, GetY,3,i*20, 10,BLUE01);
			CreateShot01ToItem(GetX,GetY,3,i*20,BLUE01,10);
		}
	}
}

case("Extra")
{
wait(10);
	loop(10)
	{
	if(GetLife<=1000)
	{
		break;
	}
		let angle=GetAngleToPlayer;
		ascent(let i in 0..7)
		{
		//	CreateShot01(GetX,GetY,2+0.5*i,angle,RED11,10);
		//	CreateShotFromScript( "shot1",GetX, GetY,2+0.5*i,angle, 10, RED11);
			CreateShot01ToItem(GetX,GetY,2+0.5*i,angle,RED11,10);
		}
		wait(30);
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in 0..36)
		{
		//	CreateShot01(GetX,GetY,3,i*20,BLUE01,10);
		//	CreateShotFromScript( "shot1",GetX, GetY,3,i*20, 10,BLUE01);
			CreateShot01ToItem(GetX,GetY,3,i*10,BLUE01,10);
		}
	}
}

}

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"
}
#include_script ".\..\txt/EnemyShotData.txt"