script_enemy_main{
	let imgEmeny	= GetCurrentScriptDirectory() ~ "\img\faily_green.png";
	#include_function ".\lib\setting_emeny.txt"

	let position = 0;
	let ATTACK_FLAG = 0;
	let WT = 240;

	@Initialize(){

		if (GetX < GetCenterX)
			{ position = 1 }
		else
			{ position = -1 }

		Initialize_Fairy(LARGE);	//使用する妖精を設定

		if (GetArgument() == 0)
		{
			SetLife(250);
			SetDamageRate(100, 100);
			SetScore(1000);
			SetInvincibility(30);
		}
		else if (GetArgument() == 1)
		{
			SetLife(1200);
			SetDamageRate(100, 100);
			SetScore(50000);
			SetInvincibility(150);
			WT = 600;
		}
		else if (GetArgument() == 2)
		{
			SetLife(600);
			SetDamageRate(100, 100);
			SetScore(10000);
			SetInvincibility(100);
			WT = 450;
		}

		LoadUserShotData(userShot);
		Tmain;
	}

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

	@DrawLoop(){
		DrawFairy(imgEmeny);	//妖精を描画
	}

	@Finalize()
	{
		if (!BeVanished())
		{
			if (GetArgument() == 1) {  makeTokutenItem(16, 32); CreateItem(ITEM_BOMB, GetX, GetY); }
			else { makeTokutenItem(8, 32); }
		}
	}

	task Tmain(){
		yield;
		
		if (GetArgument() == 0)
		{
			TMove_type2;
			TShot1;
		}
		else if (GetArgument() == 1)
		{
			TMove_type2;
			TShot2;
		}
		else if (GetArgument() == 2)
		{
			TMove_type2;
			TShot3;
		}
	}

	task TShot1(){
		wait(80);
		
		loop
		{
			CreateShotFromScript("Haretu", GetX, GetY, 3, GetAngleToPlayer-30, 10, US_GUN_WHITE);
			CreateShotFromScript("Haretu", GetX, GetY, 3, GetAngleToPlayer+30, 10, US_GUN_WHITE);
			PlaySE(SE_SHOT);
			wait(150);
		}
	}

	task TShot2(){
		wait(150);
		
		let t = 0;
		loop
		{
			loop(3)
			{
				CreateShot01(GetX, GetY, 5, rand(0,360), US_KUNAI_RED, 0);
			}
			if (t%3 == 0) { PlaySE(SE_SHOT); }
			t++;
			yield;
		}
	}

	task TShot3(){
		wait(150);
		let way = 20;
		
		loop
		{
			ascent (let n in 0 .. 4)
			{
				shot_circle(2, n*2, way, US_BILL_AQUA);
				wait(5);
				PlaySE(SE_SHOT);
			}
			let tmp = rand(0,360/way);
			ascent (let n in 0 .. 4)
			{
				shot_circle(2, tmp-n*2, way, US_BILL_AQUA);
				wait(5);
				PlaySE(SE_SHOT);
			}
			wait(40);
		}
	}
	
	function shot_circle(speed, angle, way, graphic)
	{
		ascent (let n in 0 .. way)
			{ CreateShot01(GetX, GetY, speed, angle+n*360/way, graphic, 5); }
	}

	task TMove_type2()
	{
		SetMovePosition03(GetX, GetY+200, 20, 3);
		wait(10);
		while (GetSpeed() != 0) { yield; }	//停止するまで待機
		ATTACK_FLAG = 1;
		wait(WT);
		SetMovePosition01(GetX, GetClipMinY-60, 2);
		
		//画面外に出るまで待機
		while (GetClipMinX-32 <= GetX && GetClipMaxX+32 >= GetX
			&& GetClipMinY-32 <= GetY && GetClipMaxY+32 >= GetY) { yield; }
		VanishEnemy();
	}
}

//破裂ショット
script_shot Haretu
{
	let SPEED	= GetSpeed();
	let GRAPHIC	= GetArgument();
	let userShot = GetCurrentScriptDirectory() ~ ".\lib\data_usershot.txt";
	let TIMER	= 40;	//弾が破裂するまでの時間

	#include_function ".\lib\lib_se.txt"

	@Initialize
	{
		LoadUserShotData(userShot);
		SetDefault(GRAPHIC);
	}
	@MainLoop
	{
		if(OnDelay()){
			SetSpeed(0);
		}
		else if (TIMER <= 0)
		{
			shot_haretu(2, 0, 20, 8, 2, YELLOW21);
			PlaySE(SE_BELL);
			End();
		}
		else
		{
			TIMER--;
			SetSpeed(SPEED);
			SetCollisionBDefault();
		}
	}
	@DrawLoop
	{
		DrawGraphicDefault();
	}
	@Finalize
	{
	}
	
	// 破裂ショット
	function shot_haretu(speed, a_base, c_span, t_way, t_span, graphic)
	{
		let i = 1;
		let a = -180;
		while(a + c_span*int(i/t_way) <= 180)
		{
			CreateShot01(GetX, GetY, speed, a_base+a+c_span*int(i/t_way), graphic, 0);
			a += t_span;
			i++;
		}
	}

}