#e
#Title[AŁu_ہv]
#Text[test]
#ScriptVersion[2]

script_enemy_main {
	let name	   = "AŁu_ہv";
	let imgBoss	= "script\img\ExRumia.png";

	// ʒu
	let xIni	   = GetCenterX+100;
	let yIni	   = GetClipMinY-300;
	
	//shotall.png
	#include_function ".\lib_usershot.txt"
	//ւ̊{ݒ
	#include_function ".\lib\setting_itirin.txt"
//	CreateDebugWindow;

	let imgShotKobushi	= GetCurrentScriptDirectory() ~ "\img\genkotu.png";

	let D_RATE = 0;
	let D_WAIT = 999;

	@Initialize {
		CutIn(YOUMU, name, "", 0, 0, 0, 0);

		SetLife(1);
		SetTimer(20);
		SetScore(800000);
		SetDamageRate(0, 0);
		SetDurableSpellCard();	//ϋv

		LoadGraphic(imgShotKobushi);
		Ini_Graphic;

		TMain;
	}

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

		yield;
	}

	@DrawLoop {
		Draw_Itirin;
	}

	@Finalize {
//		DeleteGraphic(imgBoss);
	}

	// C^XN
	task TMain {
		yield;

		TRate;
		standBy;

		//e
		SetY(-900);
		TShot;
	}

	task TShot()
	{
		let kabe = [1, 3, 2, 4 ];
		let muki_x = [1, -1, -1, 1];
		let muki_y = [1, 1, -1, -1];
		let wt = 120;
		let t = 0;
		
		loop
		{
			shot_masingun(kabe[t%4], muki_x[t%4], muki_y[t%4], 5, 10);
			loop(wt) { yield; }
			t++;
			wt -= 10; if (wt < 40) { wt = 40; }
		}
	}
	
	// }VK
	//muki=1 ....  or E獶
	//muki=-1 ... ォ牺 or E
	task shot_masingun(kabe, muki_x, muki_y, way, wt)
	{
		ascent (let n in 0 .. way)
		{
			let x; let y;

			if (muki_y == 1) { y = GetClipMaxY - (GetClipMaxY-GetClipMinY)/way * (n+0.5); }
			else { y = GetClipMinY + (GetClipMaxY-GetClipMinY)/way * (n+0.5); }

			if (muki_x == 1) { x = GetClipMaxX - (GetClipMaxX-GetClipMinX)/way * (n+0.5); }
			else { x = GetClipMinX + (GetClipMaxX-GetClipMinX)/way * (n+0.5); }

			shot_kobushi(10, kabe, x, y);
			loop(wt) { yield; }
		}
	}
	
	//ʊO猝U@@_
	// kabe=1: 2=E 3= 4= ȊOƑłȂ
	// kabe_x, kabe_y _*ꎞ~*WBkabeŐݒ肵Ǖt߂Œ~
	function shot_kobushi(speed, kabe, kabe_x, kabe_y)
	{
		let x = 0; let y = 0;
		let angle = 0;
		let FLAG = 2;

		while (FLAG > 0)	//px}ɂȂ߂ꍇ͔ˈʒu𒲐Ȃ
		{
			alternative (kabe)
			case (1)
			{
				angle = (atan2(GetPlayerY-kabe_y ,GetPlayerX-2)+360)%360;
				x = GetClipMinX-60; y = kabe_y-tan(angle)*60;
			//	if (angle <= 90 && angle > 70) { kabe = 3; }
			//	else if (angle >= 270 && angle < 290) { kabe = 4; }
			//	else { FLAG = 0; }
			}
			case (2)
			{
				angle = (atan2(GetPlayerY-kabe_y ,GetPlayerX-(GetClipMaxX-2))+360)%360;
				x = GetClipMaxX+60; y = kabe_y+tan(angle)*60;
			//	if (angle < 110) { kabe = 3; }
			//	else if (angle > 250) { kabe = 4; }
			//	else { FLAG = 0; }
			}
			case (3)
			{
				angle = (atan2(GetPlayerY-2 ,GetPlayerX-kabe_x)+360)%360;
				x = kabe_x-60/tan(angle); y = GetClipMinY-60;
			//	if (angle > 160) { kabe = 2; }
			//	else if (angle < 20) { kabe = 1; }
			//	else { FLAG = 0; }
			}
			case (4)
			{
				angle = (atan2(GetPlayerY-(GetClipMaxY-2) ,GetPlayerX-kabe_x)+360)%360;
				x = kabe_x+60/tan(angle); y = GetClipMaxY+60;
			//	if (angle < 200) { kabe = 2; }
			//	else if (angle > 340) { kabe = 1; }
			//	else { FLAG = 0; }
			}
			others
			{
				return (false);
			}
			FLAG--;
		}
		
		CreateShotFromScript("Kobushi", x, y, speed, angle, 75, 2);
	}
}


//e
//ʒ[GetArgumentsNZȏ㗣ꂽꎞ~AЕ̉ʒ[Œ~
//tF[hAEgA폜
script_shot Kobushi
{
	let SPEED = GetSpeed();		//Xs[h
	let SIZE = 50;			//e̔a

	let imgShot	= GetCurrentScriptDirectory() ~ "\img\genkotu.png";

	let ERACE_FLAG = 0;
	let g_alpha = 0;
	let FALED = 1;		//ˎs
	let SE_FLAG = 0;

	//TEhf[^̍ݏ
	#include_function ".\lib\lib_se.txt"

	@Initialize
	{	
//		LoadGraphic(imgShot);
		SetTexture(imgShot);
		SetGraphicRect(  0,   0, 128, 128);

		SetBombResist();	//{ŏȂ
		SetSpeed(6);		//speedl
	}
	@MainLoop
	{
		let angle = GetAngle%360;

		if(OnDelay()){
			//ʒuɓꎞ~
			if (angle < 90) { if (GetX >= GetClipMinX+GetArgument && GetY >= GetClipMinY+GetArgument) { SetSpeed(0); FALED=0; } }
			else if (angle < 180) { if (GetX <= GetClipMaxX-GetArgument && GetY >= GetClipMinY+GetArgument) { SetSpeed(0); FALED=0; } }
			else if (angle < 270) { if (GetX <= GetClipMaxX-GetArgument && GetY <= GetClipMaxY-GetArgument) { SetSpeed(0); FALED=0; } }
			else { if (GetX >= GetClipMinX+GetArgument && GetY <= GetClipMaxY-GetArgument) { SetSpeed(0); FALED=0; } }
			
			if (FALED == 0)
			{
				if (SE_FLAG <= 0) { StopSE(SE_WARP); PlaySE(SE_WARP); SE_FLAG = 1; }
			}

		//	SetCollisionB(GetX, GetY, 60);	//蔻聨ςtȂ
		}
		else if (ERACE_FLAG == 1)
		{
		//	if (SE_FLAG <= 1) { PlaySE(SE_KOBUSI); SE_FLAG = 2; }
			//XɔA폜
			g_alpha -= 10;
			if (g_alpha <= 0) { End(); }
			else if (g_alpha > 150) { SetCollisionB(GetX, GetY, 60); }	//蔻
		}
		else
		{
			//˂Ɏsꍇ͑Xɍ폜
			if (FALED == 1) { End(); }
			
			//ǂɂԂ~
			if (angle < 90)
			{
				if (GetX >= GetClipMaxX-SIZE || GetY >= GetClipMaxY-SIZE) { g_alpha = 255; ERACE_FLAG = 1; SetSpeed(0); }
				else { SetSpeed(SPEED); }
			}
			else if (angle < 180)
			{
				if (GetX <= GetClipMinX+SIZE || GetY >= GetClipMaxY-SIZE) { g_alpha = 255; ERACE_FLAG = 1; SetSpeed(0); }
				else { SetSpeed(SPEED); }
			}
			else if (angle < 270)
			{
				if (GetX <= GetClipMinX+SIZE || GetY <= GetClipMinY+SIZE) { g_alpha = 255; ERACE_FLAG = 1; SetSpeed(0); }
				else { SetSpeed(SPEED); }
			}
			else
			{
				if (GetX >= GetClipMaxX-SIZE || GetY <= GetClipMinY+SIZE) { g_alpha = 255; ERACE_FLAG = 1; SetSpeed(0); }
				else { SetSpeed(SPEED); }
			}

			SetCollisionB(GetX, GetY, 60);	//蔻
		}
	}
	@DrawLoop
	{
		if (g_alpha > 0) { SetAlpha(g_alpha); }
		SetGraphicAngle(0, 0, 180+GetAngle);
		DrawGraphic(GetX, GetY);
	}
	@Finalize
	{
	}
}