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

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

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

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

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


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

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

task move
{
let dir;
if(angle==0)
{
dir=1;
}
if(angle==180)
{
dir=-1;
}
	SetSpeed(speed);
	SetAngle(angle);
	loop
	{
		SetSpeed(speed);
		SetAngle(angle);
		speed+=0.02;
		angle-=0.2*dir;
		yield;
	}
}

task shot
{
wait(10);
alternative(SelectedDifficult)
case("Easy")
{
	loop
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer,RED02,0);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2.0,GetAngleToPlayer, 0, RED02);
		CreateShot01ToItem(GetX,GetY,2,GetAngleToPlayer,RED02,0);
		wait(25);
	}
}
case("Normal")
{
	loop
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,3,GetAngleToPlayer,RED02,0);
	//	CreateShotFromScript( "shot1",GetX, GetY, 3.0,GetAngleToPlayer, 0, RED02);
		CreateShot01ToItem(GetX,GetY,3,GetAngleToPlayer,RED02,0);
		CreateShot01ToItem(GetX,GetY,3,GetAngleToPlayer+30,RED02,0);
		CreateShot01ToItem(GetX,GetY,3,GetAngleToPlayer-30,RED02,0);
		wait(20);
	}
}
case("Hard")
{
	loop
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,4,GetAngleToPlayer,RED02,0);
	//	CreateShotFromScript( "shot1",GetX, GetY, 4.0,GetAngleToPlayer, 0, RED02);
		CreateShot01ToItem(GetX,GetY,4,GetAngleToPlayer,RED02,0);
		CreateShot01ToItem(GetX,GetY,4,GetAngleToPlayer+20,RED02,0);
		CreateShot01ToItem(GetX,GetY,4,GetAngleToPlayer-20,RED02,0);
		wait(15);
	}
}
case("Lunatic")
{
	loop
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,5,GetAngleToPlayer,RED02,0);
	//	CreateShotFromScript( "shot1",GetX, GetY, 5.0,GetAngleToPlayer, 0, RED02);
		CreateShot01ToItem(GetX,GetY,5,GetAngleToPlayer,RED02,0);
		CreateShot01ToItem(GetX,GetY,5,GetAngleToPlayer+20,RED02,0);
		CreateShot01ToItem(GetX,GetY,5,GetAngleToPlayer-20,RED02,0);
		wait(10);
	}
}

case("Extra")
{
	loop
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,5,GetAngleToPlayer,RED02,0);
	//	CreateShotFromScript( "shot1",GetX, GetY, 5.0,GetAngleToPlayer, 0, RED02);
		CreateShot01ToItem(GetX,GetY,5.5,GetAngleToPlayer,RED03,0);
		CreateShot01ToItem(GetX,GetY,5.5,GetAngleToPlayer+20,RED03,0);
		CreateShot01ToItem(GetX,GetY,5.5,GetAngleToPlayer-20,RED03,0);
		wait(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"