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

	let KYORI = 0;
	let TIMER = 0;
	let position = 0;

	@Initialize(){
		if (GetArgument() == 0)
		{
			KYORI = 250;
			TIMER = 300;
		}
		else if (GetArgument() == 1)
		{
			KYORI = 250;
			TIMER = 300;
		}
		else if (GetArgument() == 2)
		{
			KYORI = 250;
			TIMER = 300;
		}
		else if (GetArgument() == 3)
		{
			KYORI = 250;
			TIMER = 600;
		}
		else if (GetArgument() == 4)
		{
			KYORI = 250;
			TIMER = 600;
		}
		else	//エラー
		{
			KYORI = 100;
			TIMER = 0;
		}

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

		Initialize_Fairy(SMALL);	//使用する妖精を設定
		SetLife(50);
		SetDamageRate(100, 100);
		SetScore(1000);

		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_type1;
			TShot1;
			SetInvincibility(10);
		}
		else if (GetArgument() == 1)
		{
			TMove_type1;
			TShot2;
			SetInvincibility(10);
		}
		else if (GetArgument() == 2)
		{
			TMove_type2;
			TShot3;
			SetInvincibility(40);
		}
		else if (GetArgument() == 3)
		{
			TMove_type2;
			TShot4(US_BILL_PURPLE);
			SetInvincibility(20);
		}
		else if (GetArgument() == 4)
		{
			TMove_type2;
			TShot4(US_BILL_BLUE);
			SetInvincibility(20);
		}
	}

	task TShot1(){
		wait(15);
		
		let t = 0;
		while (t < TIMER)
		{
			shot_nway(3.5, 5, 6, US_GUN_AQUA);
			t += 10;
			PlaySE(SE_SHOT);
			wait(10);
		}
	}

	task TShot2(){
		wait(15);
		let t = 0;
		while (t < TIMER)
		{
			shot_nway(3.75, 8, 4, US_GUN_RED);
			shot_nway(3.5, 5, 7, US_GUN_RED);
			shot_nway(3.25, 8, 6, US_GUN_RED);
			shot_nway(3, 15, 5, US_GUN_RED);
			t += 60;
			PlaySE(SE_SHOT);
			wait(60);
		}
	}

	task TShot3(){
		wait(60);
		let t = 0;
		while (t < TIMER)
		{
			CreateShot01(GetX, GetY, 5, GetAngleToPlayer+rand(-5,5), US_GUN_WHITE, 5);
			t += 8;
			PlaySE(SE_SHOT);
			wait(8);
		}
	}

	task TShot4(graphic){
		wait(60);
		let t = 0;
		while (t < TIMER)
		{
			let base_angle = GetAngleToPlayer;
			ascent(let n in 0 .. 7)
			{
				CreateShot01(GetX, GetY, 4, base_angle+(n-3)*3, graphic, 21-n*3);
				wait(3);
			}
			PlaySE(SE_SHOT);
			t += 75;
			wait(54);
		}
	}

	// nwayショット
	function shot_nway(speed, angle, way, graphic)
	{
		let pa = GetAngleToPlayer();
		ascent (let n in 0 .. way)
		{
			CreateShot01(GetX, GetY, speed, (n-(way-1)/2)*angle+pa, graphic, 5);
		}
	}

	task TMove_type1()
	{
		let x = GetX();
		let y = GetY();
		let ang_plus = 100;
		if (position < 0) { ang_plus = 80; }

		SetMovePositionHermite(x+KYORI*position, y+KYORI/2, 0, 0, KYORI, ang_plus, 180);
		x += KYORI*position; y += KYORI;
		loop(180) { yield; }
		SetMovePosition01(x+500*cos(ang_plus), y+500*sin(ang_plus), 1);
		
		//画面外に出るまで待機
		while (GetClipMinX-32 <= GetX && GetClipMaxX+32 >= GetX
			&& GetClipMinY-32 <= GetY && GetClipMaxY+32 >= GetY) { yield; }
		VanishEnemy();
	}

	task TMove_type2()
	{
		let x = GetX;
		let y = GetY;
		if (position < 0) {
			SetMovePositionHermite(x-300, y-50, 200, 270, 300, 270, 250);
			wait(240);
			SetMovePositionHermite(x-100, y+50, 200, 270, 300, 270, 200);
			wait(190);
			SetMovePositionHermite(x-600, y-50, 200, 270, 300, 270, 350);
		}
		else
		{
			SetMovePositionHermite(x+300, y-50, 200, 270, 300, 270, 250);
			wait(240);
			SetMovePositionHermite(x+100, y+50, 200, 270, 300, 270, 200);
			wait(190);
			SetMovePositionHermite(x+600, y-50, 200, 270, 300, 270, 350);
		}
		wait(120);
		
		//画面外に出るまで待機
		while (GetClipMinX-32 <= GetX && GetClipMaxX+32 >= GetX
			&& GetClipMinY-32 <= GetY && GetClipMaxY+32 >= GetY) { yield; }
		VanishEnemy();
	}
}