#東方弾幕風
#Title[星＆ナズ通常]
#Text[test]
#ScriptVersion[2]

script_enemy_main {
	let name	= "";

	// shot_all.png
	#include_function ".\lib_usershot.txt"
	// 星さん初期設定
	#include_function ".\lib\setting_tora.txt"

	// 初期位置
	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 {
		//ナズ＆星の当たり判定を取得
		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);
	}

	// メインタスク
	task TMain {
		yield;
		//ナズーリン
		CreateEnemyFromScript("Nazu", 0, 0, 0, 90, 0);

		TRate;
		standBy;
		effect_toramaru;
		
		TShot;
	}

	//弾射出タスク
	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);
		}
	}
}

// ナズーリン
script_enemy Nazu {
	let shot_speed = GetArgument();

	// ナズ寅初期設定
	#include_function ".\lib\setting_nazutora.txt"

	//初期位置は画面外
	SetX(-500);
	SetY(-500);

	let D_RATE = 0;
	let D_WAIT = 999;


	@Initialize {
		SetLife(9999);
		SetScore(1000);
		SetDamageRate(0, 0);		//ダメージ無効化

		SetTexture(imgBoss);
		setGraphicStop;
		

		TMain;
	}

	@MainLoop {
		//位置を記録
		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);
			//ショット
			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);
			//ショット
			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;
	}

	
	//ネズーミンランド召喚（濃さは均一）
	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; }
		}
	}
}
