script_enemy_main{
	#include_function ".\lib\lib_files.txt"
	#include_function ".\lib\lib_item.txt"
	let imgEmeny = emnNUE;
	let INVISIBLE = 1;
	
	let COUNT_USEBOMB = GetBombCount();
	let COUNT_MISS = GetMissCount();
	let MOVE_FLAG = 0;
	
	@Initialize(){
		SetDamageRate(100, 100);
		SetLife(30);
		SetScore(1000);

		SetTexture(imgEmeny);
		SetGraphicRect(0, 0, 128, 128);
		SetGraphicScale(0.85, 0.85);
		Tmain;
	}

	@MainLoop(){
		SetCollisionB(GetX(), GetY(),16);
		yield;
	}

	@DrawLoop(){
		DrawGraphic(GetX, GetY);
		SetGraphicAngle(0, 0, rand(0,360));
	}

	@Finalize()
	{
	}
	
	task Tmain(){
		yield;

		TMove;
	}

	task TShot {
		let muki = 1;
		let WAY	= [8, 16, 16, 16][DIFFICULTLY];
		let WT	= [10, 5,  5,  5][DIFFICULTLY];
		
		ascent (let j in 0 .. 4)
		{
			let wait_count = 0;
			ascent(let i in 0 .. WAY)
			{
				let angle = i*360/WAY*muki + 90-muki*90;
				CreateEnemyFromScript("NueFaily", GetX+cos(angle)*48, GetY+sin(angle)*48, 1.5, angle+90*muki, j);
				wait(WT);
				wait_count += WT;
			}
			MOVE_FLAG = 1;
			muki = -muki;
			wait(240-wait_count);
		}
	}
	
	task TMove
	{
		SetMovePositionHermite(GetCenterX, GetY, 500, -45, 500, 135, 180);
		wait(180);
		
		TShot;
		loop(4)
		{
			while(!MOVE_FLAG) { yield; }
			let angle = rand(0, 360);
			SetMovePositionHermite(GetX, GetY, 180, angle, 180, 180+angle, 120);
			MOVE_FLAG = 0;
			wait(120);
		}
		wait(60);
		SetMovePositionHermite(GetClipMaxX+64, GetY, 1300, 190, 500, 45, 180);
		nue_drop_item;

		//ʊOɏo܂őҋ@
		while (GetClipMinX-32 <= GetX && GetClipMaxX+32 >= GetX
			&& GetClipMinY-32 <= GetY && GetClipMaxY+32 >= GetY) { yield; }
		VanishEnemy();
	}
	
	task nue_drop_item
	{
		wait(10);
		while (GetX < GetCenterX) { yield; }
		
		//ACehbv
		if (COUNT_USEBOMB == GetBombCount() && COUNT_MISS == GetMissCount())
			{ MY_CreateItem(GetX, GetY, ITEMTYPE_1UP_MAX); }
		else
			{ MY_CreateItem(GetX, GetY, ITEMTYPE_BOMB_MAX); }
	}
}

script_enemy NueFaily {
	#include_function ".\lib\lib_files.txt"
	#include_function ".\lib\lib_item.txt"
	let imgEmeny = emnFAILY1;
	let INVISIBLE = 1;
	let FAILY_TYPE = GetArgument();
	
	if (FAILY_TYPE % 2 != 0) { imgEmeny = emnFAILY2; }

	@Initialize {
		SetDamageRate(100, 100);
		SetLife(100);
		SetScore(1000);

		SetTexture(imgEmeny);
		SetGraphicRect(  0,  0, 32, 32);
		TMain;
	}

	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 13);

		yield;
	}

	@DrawLoop {
		DrawGraphic(GetX, GetY);
	}

	@Finalize()
	{
		if (!BeVanished())
		{
			MY_CreateItemEx(GetX, GetY, 24, 6);
		}
	}

	task TMain {
		yield;
		
		let SPEED = [1.3, 1.5, 2, 2.5][FAILY_TYPE];
		let GRAPHIC = [BLUE11, RED11, BLUE11, RED11][FAILY_TYPE];
		let WAY = [4, 4, 5, 5][FAILY_TYPE];
		let C_ANGLE = [30, 25, 35, 45][FAILY_TYPE];
		
		SPEED *= [1, 1, 1.4, 1.6][DIFFICULTLY];
		WAY += trunc(FAILY_TYPE * [0, 0, 0.5, 0.5][DIFFICULTLY]);

		let BASE_SGAIN = -0.2/SPEED;
		ascent(let k in 0 .. 2)
		{
			ascent(let j in 0 .. 10)
			{
				ascent (let i in 0 .. WAY)
				{
					CreateShot02(GetX, GetY, 4, GetAngle() + i*360/WAY + (1-k)*C_ANGLE, BASE_SGAIN*(19-j)/10, SPEED, GRAPHIC, 10);
					StopSE(sndSHOT); PlaySE(sndSHOT);
				}
				wait(3);
			}
			wait(30);
		}

		//ʊOɏo܂őҋ@
		while (GetClipMinX-32 <= GetX && GetClipMaxX+32 >= GetX
			&& GetClipMinY-32 <= GetY && GetClipMaxY+32 >= GetY) { yield; }
		VanishEnemy;
	}
}

