#e
#Title[iYʏ]
#Text[test]
#ScriptVersion[2]

script_enemy_main {
	let name	= "";

	// shot_all.png
	#include_function ".\lib_usershot.txt"
	// 񏉊ݒ
	#include_function ".\lib\setting_tora.txt"

	// ʒu
	let xIni	= GetCenterX;
	let yIni	= GetClipMinY + 120;
	
	let D_RATE = 100;
	let D_WAIT = 180;

	@Initialize {
		SetLife(2700);
		SetTimer(40);
		SetDamageRate(5, 5);

		Ini_Graphic;
		LoadGraphic(imgHoutou);

		TMain;
	}

	@MainLoop {
		//iY̓蔻擾
		SetCollisionA(GetCommonDataDefault("NazuX", -100), GetCommonDataDefault("NazuY", -100), 32);
		SetCollisionB(GetCommonDataDefault("NazuX", -100), GetCommonDataDefault("NazuY", -100), 13);
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 13);

		yield;
	}

	@DrawLoop {
		Draw_Toramaru;
	}

	@Finalize {
		if (!IsTimeOut()) { makeTokutenItem(8); }

//		DeleteGraphic(imgBoss);
	}

	// C^XN
	task TMain {
		yield;
		//iY[
		CreateEnemyFromScript("Nazu", 0, 0, 0, 90, 0);

		TRate;
		standBy;
		effect_toramaru;
		
		TShot;
	}

	//eˏo^XN
	task TShot()
	{
		wait(60);
		loop
		{
			ATTACK_FLAG = 1;
			let base = rand(120,180);
			shot_kurukuru_lazer4(GetAngleToPlayer, base, 8, US_LIGHT_YELLOW, 1);
			PlaySE(SE_LASER2);
			wait(30);
			shot_kurukuru_lazer4(GetAngleToPlayer, base, 8, US_LIGHT_YELLOW,-1);
			PlaySE(SE_LASER2);
			wait(60);
			ATTACK_FLAG = 0;
			
			moveBoss(20, 40, 0, 30, 20, 2, 64, 40, 150);
			
			wait(60);
		}
	}

	function shot_kurukuru_lazer4(angle, a_move, way, graphic, muki)
	{
		let s_max = 5;
		ascent (let n in 0 .. way)
		{
			let s_base = s_max*(n+1)/way*0.8;
			let a_span = (a_move+n/way*120)/120 * muki;
			CreateLaserC(0, GetX, GetY, 6, 60, graphic, 0);
			SetLaserDataC(0,   0, s_base, angle+180, a_span, 0, 6);
			SetLaserDataC(0, 120,  s_max, NULL,     0, 0, 6);
			FireShot(0);
		}
	}
}

// iY[
script_enemy Nazu {
	let shot_speed = GetArgument();

	// iYЏݒ
	#include_function ".\lib\setting_nazutora.txt"

	//ʒu͉ʊO
	SetX(-500);
	SetY(-500);

	let D_RATE = 0;
	let D_WAIT = 999;


	@Initialize {
		SetLife(9999);
		SetScore(1000);
		SetDamageRate(0, 0);		//_[W

		SetTexture(imgBoss);
		setGraphicStop;
		

		TMain;
	}

	@MainLoop {
		//ʒuL^
		SetCommonData("NazuX", GetX);
		SetCommonData("NazuY", GetY);
		yield;
	}

	@DrawLoop {
		Draw_Nazu;
	}

	@Finalize {
		if (!IsTimeOut()) { makeTokutenItem(8); }
	}

	task TMain {
		yield;
		
		standBy;
		TShot;
	}

	task TShot {
		yield;

		loop
		{
			//ړ
			SetX(GetClipMinX-60); SetY(GetClipMinY+20);
			SetMovePosition03(GetClipMinX+80, GetClipMinY+150, 13, 4);
			wait(90);
			//Vbg
			TShot_sub();
			wait(60);
			//ʒ[Ɉړ
			SetMovePosition03(GetClipMinX-60, GetClipMinY+100, 0, 5);
			wait(60);
			//ړ
			SetX(GetClipMaxX+60); SetY(GetClipMinY+20);
			SetMovePosition03(GetClipMaxX-80, GetClipMinY+150, 13, 4);
			wait(90);
			//Vbg
			TShot_sub();
			wait(60);
			//ʒ[Ɉړ
			SetMovePosition03(GetClipMaxX+60, GetClipMinY+100, 0, 5);
			wait(60);
		}
	}
	
	task TShot_sub
	{
		ATTACK_FLAG = 1;
		loop(2)
		{
			shot_nezumi2(1.5, 4, 20, 90, US_SCALE_PURPLE);
			loop(30){yield;}
		}
		ATTACK_FLAG = 0;
	}

	
	//lY[~hiZ͋ψj
	task shot_nezumi2(speed_min, speed_max, noudo, timer, graphic)
	{
		let n = 0;
		let speed_gain = (speed_min-speed_max)/timer;
		let angle = GetAngleToPlayer;
		//
		n = 0;
		while (n < 200)
		{
			let length = rand(-noudo/2,noudo/2) + n;
			let sx = GetX + cos(90+angle)*length;
			let sy = GetY + sin(90+angle)*length + rand(-(n+100)/4, (n+100)/4);
			CreateShot02(sx, sy, speed_max, atan2(GetPlayerY-sy, GetPlayerX-sx), speed_gain, speed_min, graphic, 15);

			length = rand(-noudo/2,noudo/2) - n;
			sx = GetX + cos(90+angle)*length;
			sy = GetY + sin(90+angle)*length + rand(-(n+100)/4, (n+100)/4);
			CreateShot02(sx, sy, speed_max, atan2(GetPlayerY-sy, GetPlayerX-sx), speed_gain, speed_min, graphic, 15);

			n += noudo;
			StopSE(SE_SHOT2);
			PlaySE(SE_SHOT2);
			loop(3) { yield; }
		}
	}
}
