script_enemy_main{
	#include_function ".\lib\lib_files.txt"
	#include_function ".\lib\lib_item.txt"
	let imgEmeny = emnFAILY1;

	let INVISIBLE = 1;
	let UTIKAESHI = 1;
	let DROP_ITEM = GetArgument() % 10000;
	let ONE_SHOT = 0;
	if (GetArgument() >= 10000) { ONE_SHOT = 1; }
	
	if (DROP_ITEM) { imgEmeny = emnFAILY2; }

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

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

	@MainLoop(){
		if (!INVISIBLE)
		{
			SetCollisionA(GetX(), GetY(),24);
			SetCollisionB(GetX(), GetY(),6);
		}
		yield;
	}

	@DrawLoop(){
		DrawGraphic(GetX, GetY);
	}

	@Finalize()
	{
		if (!BeVanished())
		{
			if (DROP_ITEM != 0) { MY_CreateItem(GetX, GetY, DROP_ITEM); }
			MY_CreateItemEx(GetX, GetY, 24, 5);
			if (UTIKAESHI)
			{
				let WAY = [12, 28, 42, 42][DIFFICULTLY];
				ascent(let i in 0 .. WAY)
				{
					StopSE(sndSHOT); PlaySE(sndSHOT);
					CreateShot01(GetX, GetY, 4, GetAngleToPlayer+i*360/WAY, WHITE02, 0);
				}
			}
		}
	}

	task Tmain(){
		yield;

		TShot;
		TMove;
		
		wait(20);
		INVISIBLE = 0;
	}

	task TShot {
		let WAY = 4;
		let WT = 3;
		let loop_count = 2;
		if (ONE_SHOT) { loop_count = 1; }
		
		wait(60);
		UTIKAESHI = 0;
		loop(loop_count) {
			ZakoShotA(5, 2, -0.1, 4, 10/WAY, WAY, WT, PURPLE11, 0);
			if (DIFFICULTLY >= d_NORM)
				{ ZakoShotA(5, 2, -0.1, 4, 20/WAY, WAY, WT, PURPLE11, 0); }
			if (DIFFICULTLY == d_LUNA)
				{ ZakoShotA(5, 2, -0.1, 4, 30/WAY, WAY, WT, PURPLE11, 1); }
			else if (DIFFICULTLY == d_HARD)
				{ ZakoShotA(5, 2, -0.1, 4, 30/WAY, WAY, WT, PURPLE11, 0); }
			wait(120);
		}
	}
	
	task ZakoShotA(max_speed, min_speed, kasoku, start_angle, step_angle, way, wt, graphic, reverce) {
		let angle = start_angle;
		loop(way)
		{
			ZakoShotA_sub(max_speed, min_speed, kasoku, angle, graphic);
			StopSE(sndSHOT); PlaySE(sndSHOT);
			angle += step_angle;
			loop(wt) { yield; }
		}

		angle += step_angle;
		loop(way)
		{
			ZakoShotA_sub(max_speed, min_speed, kasoku, angle, graphic);
			StopSE(sndSHOT); PlaySE(sndSHOT);
			angle += step_angle*2;
			loop(wt) { yield; }
		}
		
		if (reverce)
		{
			angle = start_angle+90;
			while(angle < 180)
			{
				ZakoShotA_sub(max_speed, min_speed, kasoku, angle, graphic);
				StopSE(sndSHOT); PlaySE(sndSHOT);
				angle += step_angle*2;
				loop(wt) { yield; }
			}
		}
	}
	
	function ZakoShotA_sub(max_speed, min_speed, kasoku, angle, graphic)
	{
		CreateShot02(GetX, GetY, max_speed, 90+angle, kasoku, min_speed, graphic, 0);
		CreateShot02(GetX, GetY, max_speed, 90-angle, kasoku, min_speed, graphic, 0);
		CreateShot02(GetX, GetY, max_speed, 270+angle, kasoku, min_speed, graphic, 0);
		CreateShot02(GetX, GetY, max_speed, 270-angle, kasoku, min_speed, graphic, 0);
	}
	
	task TMove
	{
		SetMovePosition03(GetX, GetY+180, 15, 2);
		wait(150);
		SetSpeed(1.5);
		SetAngle(rand(60,120));

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