script_enemy_main{
	let imgEmeny	= GetCurrentScriptDirectory() ~ "\img\faily_red.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(MIDDLE_RIBBON);	//使用する妖精を設定

		if (GetArgument() == 0)
		{
			SetLife(125);
			SetDamageRate(100, 100);
			SetScore(1000);
		}
		else if (GetArgument() == 1)
		{
			SetLife(1000);
			SetDamageRate(100, 100);
			SetScore(30000);
		}

		LoadUserShotData(userShot);
		Tmain;
	}

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

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

	@Finalize()
	{
		if (!BeVanished())
		{
			makeTokutenItem(3, 16);
		}
	}

	task Tmain(){
		yield;
		
		if (GetArgument() == 0)
		{
			TMove_type2;
			TShot;
		}
		else if (GetArgument() == 1)
		{
			TMove_type2;
			TShot;
		}
	}

	task TShot(){
		wait(120);
		
		let b_angle = 0;
		loop
		{
			CreateShotFromScript("Bakuhatu", GetX, GetY, 8, GetAngleToPlayer, 10, US_GUN_WHITE);
			PlaySE(SE_SHOT);
			wait(120);
		}
		let t = 0;
	}
	
	task TMove_type2()
	{
//		SetMovePosition03(GetX, GetY+200, 20, 3);
		if (position == 1)
		{
			SetMovePositionHermite(GetX+120*position, GetY+180, 180, 180, 180, 0, 100);
		}
		else
		{
			SetMovePositionHermite(GetX+120*position, GetY+180, 180, 0, 180, 180, 100);
		}
		wait(10);
		while (GetSpeed() != 0) { yield; }	//停止するまで待機
		ATTACK_FLAG = 1;
		wait(WT);
		SetMovePosition01(GetX, GetClipMinY-60, 1);
		
		//画面外に出るまで待機
		while (GetClipMinX-32 <= GetX && GetClipMaxX+32 >= GetX
			&& GetClipMinY-32 <= GetY && GetClipMaxY+32 >= GetY) { yield; }
		VanishEnemy();
	}
}

//自機のあった位置で爆発するショット
script_shot Bakuhatu
{
	let SPEED	= GetSpeed();
	let GRAPHIC	= GetArgument();
	let userShot = GetCurrentScriptDirectory() ~ ".\lib\data_usershot.txt";
	
	let KYORI	= ((GetY-GetPlayerY)^2+(GetX-GetPlayerX)^2)^0.5;	//プレイヤーとの距離
	let S_SPAN	= SPEED^2 / KYORI;	// 減速度　speed^2/(2*kyori*(1-a))   a=0~1
	let TIMER_1	= 0.5*KYORI/SPEED;		//減速移動に移行する期間  a*kyori/speed
	let TIMER_2	= 1.5*KYORI/SPEED;		//停止する時間  (2-a)*kyori/speed
	let t = 0;

	#include_function ".\lib\lib_se.txt"
	#include_function ".\lib_usershot.txt"		//shot_all.png

	@Initialize
	{
		LoadUserShotData(userShot);
		SetDefault(GRAPHIC);
		SetAngle(atan2(GetPlayerY-GetY, GetPlayerX-GetX));	//自機狙い
	}
	@MainLoop
	{
		if(OnDelay()){
			SetSpeed(0);
		}
		else if (t > TIMER_2)
		{
			shot_haretu(2, 0, 20, 8, 2, YELLOW21);
			PlaySE(SE_DON19);
			End();
		}
		else
		{
			t++;
			if (t > TIMER_1) {
				SPEED -= S_SPAN;
			}
			SetSpeed(SPEED);
			SetCollisionBDefault();
		}
	}
	@DrawLoop
	{
		DrawGraphicDefault();
	}
	@Finalize
	{
	}
	
	// 破裂ショット
	function shot_haretu(speed, a_base, c_span, t_way, t_span, graphic)
	{
		let i = 1;
		let a = 0;
		while(a < 360)
		{
			CreateShotA(0, GetX, GetY, 10);
			SetShotDataA(0,  0, 3, a, 5, 0, 0, US_BALL_F_RED);
			SetShotDataA(0, 72, 3, NULL, 10, 0, 0, US_BALL_F_RED);
			SetShotKillTime(0, 108);
			FireShot(0);

			CreateShotA(0, GetX, GetY, 10);
			SetShotDataA(0,  0, 3, a+10, 10, 0, 0, US_BALL_S_RED);
			SetShotDataA(0, 36, 3, NULL, 5, 0, 0, US_BALL_S_RED);
			SetShotKillTime(0, 108);
			FireShot(0);

			a += 20;
			i++;
		}
	}

}