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

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

	@Initialize(){
		if (GetArgument() == 0)
		{
			KYORI = 250;
			TIMER = 300;
			SetLife(50);
		}
		else if (GetArgument() == 1)
		{
			KYORI = 200;
			TIMER = 300;
			SetLife(50);
		}
		else if (GetArgument() == 2)
		{
			KYORI = 180;
			TIMER = 500;
			SetLife(200);
		}
		else if (GetArgument() == 3)
		{
			KYORI = 50;
			TIMER = 300;
			SetLife(50);
		}
		else	//エラー
		{
			KYORI = 100;
		}

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

		Initialize_Fairy(SMALL);	//使用する妖精を設定
		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(1, 0);
			//打ち返し
			if (GetArgument() == 0)
				{ shot_nway(6, 360/24, 24, US_BALL_S_RED); }
			else if (GetArgument() == 1)
				{ utikaesi(20); }
		}
	}

	task Tmain(){
		yield;

		
		if (GetArgument() == 0)
		{
			TMove_type1;
			TShot;
		}
		else if (GetArgument() == 1)
		{
			TMove_type1;
			TShot2;
		}
		else if (GetArgument() == 2)
		{
			TMove_type2;
			TShot3;
		}
		else if (GetArgument() == 3)
		{
			TMove_type3;
			TShot4;
		}

	}

	task TShot {
		wait(10);
		
		let t = 0;
		while (t < TIMER)
		{
			shot_nway(4, 20, 3, US_RICE_S_YELLOW);
			t += 10;
			PlaySE(SE_SHOT);
			wait(10);
		}
	}
	task TShot2 {
		wait(10);
		
		let t = 0;
		while (t < TIMER)
		{
			shot_nway(2.5, 20, 1, US_GUN_AQUA);
			t += 20;
			PlaySE(SE_SHOT);
			wait(20);
		}
	}
	task TShot3(){
		wait(40);
		
		let t = 0;
		while (t < TIMER)
		{
			ascent (let n in 0 .. 5)
			{
				CreateShot01(GetX, GetY, (n+2)*0.5, 90,  [YELLOW21, YELLOW21, ORANGE21, ORANGE21, RED21][n], 5);
				CreateShot01(GetX, GetY, (n+2)*0.5, 270, [YELLOW21, YELLOW21, ORANGE21, ORANGE21, RED21][n], 5);
			}
			PlaySE(SE_SHOT);
			wait(30);
			t += 30;
		}
	}
	task TShot4(){
		wait(20);
		
		let t = 0;
		while (t < TIMER)
		{
			ascent (let n in 0 .. 5)
			{
				CreateShot01(GetX, GetY, (n+2)*0.5, 180,  [YELLOW21, YELLOW21, ORANGE21, ORANGE21, RED21][n], 5);
				CreateShot01(GetX, GetY, (n+2)*0.5, 0, [YELLOW21, YELLOW21, ORANGE21, ORANGE21, RED21][n], 5);
			}
			PlaySE(SE_SHOT);
			wait(30);
			t += 30;
		}
	}
	
	// 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);
		}
	}

	// 打ち返しショット
	function utikaesi(count)
	{
		loop (count)
			{ CreateShot01(GetX, GetY, rand(0.2,1), rand(0,360), US_BALL_SS_YELLOW, 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(GetClipMaxX+8, y+50, KYORI, 270, KYORI, 90, 180);
			wait(180);
			SetMovePositionHermite(GetClipMinX-8, y+100, KYORI, 270, KYORI, 90, 180);
			wait(180);
			SetMovePositionHermite(GetClipMaxX+30, y+150, KYORI, 270, KYORI, 90, 210);
		}
		else
		{
			SetMovePositionHermite(GetClipMinX-8, y+50, KYORI, 270, KYORI, 90, 180);
			wait(180);
			SetMovePositionHermite(GetClipMaxX+8, y+100, KYORI, 270, KYORI, 90, 180);
			wait(180);
			SetMovePositionHermite(GetClipMinX-30, y+150, KYORI, 270, KYORI, 90, 210);
		}
		
		//画面外に出るまで待機
		while (GetClipMinX-32 <= GetX && GetClipMaxX+32 >= GetX
			&& GetClipMinY-32 <= GetY && GetClipMaxY+32 >= GetY) { yield; }
		VanishEnemy();
	}


	task TMove_type3()
	{
		let x = GetX();
		let y = GetY();

		if (position > 0)
		{
			SetMovePosition02(x, y-300, 300);
			wait(300);
			SetMovePositionHermite(x+200, y-350, KYORI, 270, KYORI, 180, 180);
			wait(120);
			SetMovePosition01(GetClipMaxX+60, y-350, 1.5);
		}
		else
		{
			SetMovePosition02(x, y-300, 300);
			wait(300);
			SetMovePositionHermite(x-200, y-350, KYORI, 270, KYORI, 180, 180);
			wait(120);
			SetMovePosition01(GetClipMinX-60, y-350, 1.5);
		}
		
		//画面外に出るまで待機
		while (GetClipMinX-32 <= GetX && GetClipMaxX+32 >= GetX
			&& GetClipMinY-32 <= GetY && GetClipMaxY+32 >= GetY) { yield; }
		VanishEnemy();
	}
}