script_enemy_main{
	#include_function ".\lib\lib_files.txt"
	#include_function ".\lib\lib_item.txt"
	let imgEmeny = emnOTHER;
	let INVISIBLE = 1;
	let DROP_ITEM = GetArgument();

	let Animation = 0;

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

		SetTexture(imgEmeny);
		if (DROP_ITEM)
			{ SetGraphicRect( 32*6,  0, 32*7, 32); }
		else
			{ SetGraphicRect(  0,  0, 32, 32); }
		Tmain;
	}

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

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

	@Finalize()
	{
		if (!BeVanished())
		{
			if (DROP_ITEM != 0) { MY_CreateItem(GetX, GetY, DROP_ITEM); }
			MY_CreateItemEx(GetX, GetY, 24, 3);
		}
	}

	task Tmain(){
		yield;

		TShot;
		TMove;
	}

	task TShot {
		let WAY = 3;
		let way_angle = 1.5;
		let speed = 1.5;
		if (DIFFICULTLY == d_EASY) { WAY = 1; }
		else if (DIFFICULTLY == d_HARD) {
			WAY = 4;
			speed = 2.5;
		}
		else if (DIFFICULTLY == d_LUNA) {
			WAY = 4;
			speed = 3;
		}

		wait(30);
		loop(2)
		{
			let a_offset = -WAY/2*way_angle;
			
			if (cos(GetAngle()) > 0) { a_offset = -a_offset; way_angle=-way_angle; }
			
			loop(WAY)
			{
				CreateShot01(GetX, GetY, speed, 180+GetAngleToPlayer+a_offset, AQUA11, 10);
				CreateShot01(GetX, GetY, speed, GetAngleToPlayer+a_offset, AQUA11, 10);
				a_offset += way_angle;
				wait(2);
			}
			
			StopSE(sndSHOT); PlaySE(sndSHOT);
			wait(60);
		}
	}
	
	task TMove
	{
		let angle;
		let gain_angle;
		if (GetX < GetCenterX) { angle = 0; gain_angle = -0.35; }
		else { angle = 180; gain_angle = 0.35; }

		SetSpeed(3);
		SetAngle(angle);
		
		while (GetClipMinX > GetX || GetClipMaxX < GetX
			|| GetClipMinY > GetY || GetClipMaxY < GetY)
		{
			angle += gain_angle;
			SetAngle(angle);
			yield;
		}
		INVISIBLE = 0;

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