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

    @MainLoop {
	yield;
    }

        @DrawLoop {
	//	DrawFairy(imgEnemy );
	}

        @Finalize
        {
		if(!BeVanished)
		{

		}
        } 

task Tmain
{
yield;
attack;
eraze;
}

task attack
{
let rangle=rand(0,360);
let range=240;
let way=12;
let bullet=4;
alternative(SelectedDifficult)
case("Easy")
{
	way=10;
	bullet=4;
}
case("Normal")
{
	way=12;
	bullet=4;
}
case("Hard")
{
	way=16;
	bullet=4;
}
case("Lunatic")
{
	way=20;
	bullet=4;
}
ascent(let j in 0..bullet)
{
	ascent(let i in 0..way)
	{
		fllowerattack(GetClipMinX+64,GetClipMaxY-64,2-0.8*j,i*360/way+rangle);
		fllowerattack(GetClipMaxX-64,GetClipMaxY-64,2-0.8*j,i*360/way+rangle);
	}
}
wait(10);
let rangle=rand(0,360);
ascent(let j in 0..bullet)
{
	ascent(let i in 0..way)
	{
		fllowerattack(GetClipMinX+64,GetClipMaxY-196,2-0.8*j,i*360/way+rangle);
		fllowerattack(GetClipMaxX-64,GetClipMaxY-196,2-0.8*j,i*360/way+rangle);
	}
}
wait(10);
let rangle=rand(0,360);
ascent(let j in 0..bullet)
{
	ascent(let i in 0..way)
	{
		fllowerattack(GetClipMinX+64,GetClipMaxY-324,2-0.8*j,i*360/way+rangle);
		fllowerattack(GetClipMaxX-64,GetClipMaxY-324,2-0.8*j,i*360/way+rangle);
	}
}
wait(10);
let rangle=rand(0,360);
ascent(let j in 0..bullet)
{
	ascent(let i in 0..way)
	{
		fllowerattack(GetClipMinX+128,GetClipMaxY-388,2-0.8*j,i*360/way+rangle);
		fllowerattack(GetClipMaxX-128,GetClipMaxY-388,2-0.8*j,i*360/way+rangle);
	}
}
wait(90);
DeleteEnemyShotInCircle(SHOT,GetCenterX,GetCenterY,range);
wait(30);
DeleteEnemyShotInCircle(SHOT,GetCenterX,GetCenterY,range);
wait(30);
DeleteEnemyShotInCircle(SHOT,GetCenterX,GetCenterY,range);
wait(30);
DeleteEnemyShotInCircle(SHOT,GetCenterX,GetCenterY,range);
wait(30);
DeleteEnemyShotInCircle(SHOT,GetCenterX,GetCenterY,range);
//DeleteAllEnemyWithoutBoss;
SetCommonData("YUKAAPPEAR",true)
}

task fllowerattack(let x ,let y ,let speed,let angle)
{
	let itemx=x;
	let itemy=y;
        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj, YELLOW11);
        Obj_SetAngle(obj, angle);
        Obj_SetSpeed(obj, speed);
        ObjShot_SetDelay(obj, 30);
        Obj_SetPosition(obj,x, y);
//	ObjShot_SetBombResist(obj,true);
	speed=0;
	loop(60)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, speed);
	loop(60)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetSpeed(obj, speed);
		if(speed<2)
		{
			speed+=0.03;
		}
		else
		{
			ObjShot_SetBombResist(obj,false);
		}
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}


task eraze
{
let count=0;
while(!BeVanished)
{
        	if(GetX<GetClipMinX-64||GetX>GetClipMaxX+64||GetY<GetClipMinY-32||GetY>GetClipMaxY+32)
        	{
        		VanishEnemy();
        	}
		if(count>=1200)
        	{
        		VanishEnemy();
        	}
count++;
yield;
}
}

#include_function ".\..\txt/StageEnemydata.txt"
#include_function ".\..\lib\lib_anime_fairy.txt"
}

#include_script ".\..\txt/EnemyShotData.txt"