script_enemy_main
{
        let csd     = GetCurrentScriptDirectory;
	let speed = GetSpeed;
	let angle = GetAngle;
	let num = GetArgument;
	let dir;
	if(num==1)
	{
		dir=1;
	}
	if(num==2)
	{
		dir=-1;
	}
	let imgEnemy;
	if(num==1)
	{
		imgEnemy=csd~"..\lib\fairy_red.png";
	}
	if(num==2)
	{
		imgEnemy=csd~"..\lib\fairy_blue.png";
	}
	let SelectedDifficult=GetCommonDataDefault("SELECTEDDIFFICULT","Normal");

    @Initialize {
        SetLife(1050);
        SetDamageRate(100,100);
	SetTexture(imgEnemy);
	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(-30,30),GetY+rand(-30,30),num);
			}
		}
        } 

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

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

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
{
	wait(72);
	SetSpeed(speed);
loop(60)
{
	angle+=1.5*dir;
	SetAngle(angle);
	yield;
}
wait(30);
loop(60)
{
	angle-=1.5*dir;
	SetAngle(angle);
	yield;
}
}

task shot
{
alternative(SelectedDifficult)
case("Easy")
{
	wait(90);
	loop(2)
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer,YELLOW01,10);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer, 10, YELLOW01);
		CreateShot01ToItem(GetX,GetY,2,GetAngleToPlayer,YELLOW01,10);
		wait(90);
	}
}
case("Normal")
{
	wait(90);
	loop(2)
	{
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in -1..2)
		{
	//	CreateShot01(GetX,GetY,3,GetAngleToPlayer+i*8,YELLOW01,10);
	//	CreateShotFromScript( "shot1",GetX, GetY, 3, GetAngleToPlayer+i*8, 10, YELLOW01);
		CreateShot01ToItem(GetX,GetY,3,GetAngleToPlayer+i*8,YELLOW01,10);
		}
		wait(90);
	}
}
case("Hard")
{
	wait(90);
	loop(2)
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer,YELLOW01,10);
	//	CreateShot01(GetX,GetY,2.5,GetAngleToPlayer,YELLOW01,10);
	//	CreateShot01(GetX,GetY,3,GetAngleToPlayer,YELLOW01,10);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer, 10, YELLOW01);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2.5, GetAngleToPlayer, 10, YELLOW01);
	//	CreateShotFromScript( "shot1",GetX, GetY, 3, GetAngleToPlayer, 10, YELLOW01);
		CreateShot01ToItem(GetX,GetY,2,GetAngleToPlayer,YELLOW01,10);
		CreateShot01ToItem(GetX,GetY,2.5,GetAngleToPlayer,YELLOW01,10);
		CreateShot01ToItem(GetX,GetY,3,GetAngleToPlayer,YELLOW01,10);
		wait(90);
	}
	if(GetLife<=1000)
	{
		break;
	}
	ascent(let i in 0..18)
	{
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer+i*20,GREEN01,10);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer+i*20, 10, GREEN01);
		CreateShot01ToItem(GetX,GetY,2,GetAngleToPlayer+i*20,GREEN01,10);
	}
}
case("Lunatic")
{
	wait(90);
	loop(2)
	{
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in -1..2)
		{
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer+i*8,YELLOW01,10);
	//	CreateShot01(GetX,GetY,2.5,GetAngleToPlayer+i*8,YELLOW01,10);
	//	CreateShot01(GetX,GetY,3,GetAngleToPlayer+i*8,YELLOW01,10);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer+i*8, 10, YELLOW01);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2.5, GetAngleToPlayer+i*8, 10, YELLOW01);
	//	CreateShotFromScript( "shot1",GetX, GetY, 3, GetAngleToPlayer+i*8, 10, YELLOW01);
		CreateShot01ToItem(GetX,GetY,2,GetAngleToPlayer+i*8,YELLOW01,10);
		CreateShot01ToItem(GetX,GetY,2.5,GetAngleToPlayer+i*8,YELLOW01,10);
		CreateShot01ToItem(GetX,GetY,3,GetAngleToPlayer+i*8,YELLOW01,10);
		}
		wait(90);
	}
	if(GetLife<=1000)
	{
		break;
	}
	ascent(let i in 0..24)
	{
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer+i*15,GREEN01,10);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer+i*15, 10, GREEN01);
		CreateShot01ToItem(GetX,GetY,2,GetAngleToPlayer+i*15,GREEN01,10);
	}
}

case("Extra")
{
	wait(30);
	loop(2)
	{
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in -3..4)
		{
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer+i*8,YELLOW01,10);
	//	CreateShot01(GetX,GetY,2.5,GetAngleToPlayer+i*8,YELLOW01,10);
	//	CreateShot01(GetX,GetY,3,GetAngleToPlayer+i*8,YELLOW01,10);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer+i*8, 10, YELLOW01);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2.5, GetAngleToPlayer+i*8, 10, YELLOW01);
	//	CreateShotFromScript( "shot1",GetX, GetY, 3, GetAngleToPlayer+i*8, 10, YELLOW01);
		CreateShot01ToItem(GetX,GetY,1.5,GetAngleToPlayer+i*5,YELLOW01,10);
		CreateShot01ToItem(GetX,GetY,2,GetAngleToPlayer+i*5,YELLOW01,10);
		CreateShot01ToItem(GetX,GetY,2.5,GetAngleToPlayer+i*5,YELLOW01,10);
		CreateShot01ToItem(GetX,GetY,3,GetAngleToPlayer+i*5,YELLOW01,10);
		CreateShot01ToItem(GetX,GetY,3.5,GetAngleToPlayer+i*5,YELLOW01,10);
		}
		wait(90);
	}
	if(GetLife<=1000)
	{
		break;
	}
	ascent(let i in 0..60)
	{
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer+i*15,GREEN01,10);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer+i*15, 10, GREEN01);
		CreateShot01ToItem(GetX,GetY,4,GetAngleToPlayer+i*6,GREEN01,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"
