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(180);
        SetDamageRate(100,100);
	LoadGraphic(imgEnemy);
	Initialize_Fairy(7);
	SetInvincibility(210);
	Tmain;
	}

    @MainLoop {
	SetCollisionA(GetX(),GetY(),32);
        SetCollisionB(GetX(),GetY(),16);
	yield;
    }

        @DrawLoop {
		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;
}

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

task move
{
	SetMovePosition03(GetX,GetCenterY-100,20,5);
	wait(4810);
	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);
}
}

task nife1(way)
{
let px=GetPlayerX;
let py=GetPlayerY;
let angle;
loop(10)
{
	angle=atan2(py-GetY-480*sin(150)/3.14,px-GetX-480*cos(150)/3.14)+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 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);
	loop(60)
	{
		Obj_SetAngle(obj, angle);
		angle+=3*dir;
		yield;
	}
		angle+=pangle;
		Obj_SetAngle(obj, angle);
}

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"
}

