script_enemy_main
{
        let csd     = GetCurrentScriptDirectory;
	let speed = GetSpeed;
	let angle = GetAngle;
	let num = GetArgument;
	let imgEnemy;
	imgEnemy=csd~"..\lib\fairy_green.png";
	let SelectedDifficult=GetCommonDataDefault("SELECTEDDIFFICULT","Normal");

    @Initialize {
        SetLife(1180);
        SetDamageRate(100,100);
	SetTexture(imgEnemy);
	Initialize_Fairy(7);
	SetInvincibility(300);
	Tmain;
	}

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

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

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

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

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

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

task move
{
	SetMovePosition03(GetX,GetCenterY-100,20,5);
	wait(480);
	SetSpeed(3);
	SetAngle(270);
}

task shot
{
wait(60);
alternative(SelectedDifficult)
case("Easy")
{
nife1(12);
nife2(12);
}
case("Normal")
{
nife1(18);
nife2(18);
}
case("Hard")
{
nife1(24);
nife2(24);
}

case("Lunatic")
{
nife1(36);
nife2(36);
}

case("Extra")
{
nife1(60);
nife2(60);
}
}

task nife1(way)
{
let px=GetPlayerX;
let py=GetPlayerY;
let angle;
loop(10)
{
	angle=atan2(py-GetY-480*sin(150)/3.1415,px-GetX-480*cos(150)/3.1415)+300;
	ascent(let i in 0..way)
	{
	HHshot(GetX,GetY,4,i*360/way,YELLOW01,5,angle,-1);
	}
wait(10);	
}
}

task nife2(way)
{
let px=GetPlayerX;
let py=GetPlayerY;
let angle;
loop(10)
{
	angle=atan2(py-GetY-480*sin(30)/3.14,px-GetX-480*cos(30)/3.14)-120;
	ascent(let i in 0..way)
	{
	HHshot(GetX,GetY,4,i*360/way,GREEN01,5,angle,1);
	}
wait(10);	
}
}

task HHshot(let x, let y, let speed,let angle, let graphic, let delay,let pangle,let dir)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	ObjShot_ToItem(obj,false);
	loop(60)
	{
		Obj_SetAngle(obj, angle);
		angle+=3*dir;
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);	
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
		angle+=pangle;
		Obj_SetAngle(obj, angle);
	while(!Obj_BeDeleted(obj))
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);	
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}

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"