#e
#Title[@ʏP]
#Text[̉]ؔn]
#ScriptVersion[2]

script_enemy_main {
	let name	= "";

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

	// ʒu
	let xIni	= GetCenterX;
	let yIni	= GetClipMinY + 100;

	let D_RATE = 100;
	let D_WAIT = 260;

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

		Ini_Graphic;
		LoadGraphic(imgBlankCircle);

		TMain;
	}

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

		yield;
	}

	@DrawLoop {
		Draw_Byakuren;
	}

	@Finalize {
		if (!IsTimeOut()) { makeTokutenItem(15); }
//		DeleteGraphic(imgBoss);
	}

	// C^XN
	task TMain {
		yield;

		TRate;
		standBy;

		//GtFNg
		effect_blank_circle();
		powerSave;

		//e
		TShot;
	}

	//eˏo^XN
	task TShot()
	{
		shot_uzumaki(270, -17.5, 760, 1, 3, US_BILL_PURPLE, 1, 30);
		shot_uzumaki(270, -17.5, 760, 1, 4, US_BILL_PURPLE, 1, 30);

		wait(30);
		loop
		{
			ascent (let n in 0 .. 3)
			{
				let a_tmp = [60,45,30][n];
				shot_sakuretu( a_tmp+90, 4, US_BALL_L_BLUE, 2, 3, 5, 10);
				shot_sakuretu(-a_tmp+90, 4, US_BALL_L_BLUE, 2, 3, 5, 10);
				PlaySE(SE_SHOT3);
				wait(20);
			}

			moveBoss(20, 60, 10, 35, 20, 2, 64, 40, 150);

			wait(180);
		}
	}

	//yVbg
	//speed > 0łȂƓ삪Ȃ
	task shot_sakuretu(angle, speed, graphic, t_speed, t1, t2, t3)
	{
		let RAND_CHILD = 60;
		CreateShot01(GetX, GetY, speed, angle, graphic, 15);

		let kyori = getKyoriToKabe(GetX, GetY, angle);	//ǂ܂ł̋
//		let ref_angle = getReflectAngle(GetX, GetY, angle);	//ˌ̊px
		let timer = ceil(kyori/speed);	//܂ł̎
		let tmpx = GetX+cos(angle)*kyori;
		let tmpy = GetY+sin(angle)*kyori;
		wait(timer+15);

		//y 摜Œ
		loop(t1)
		{
			CreateShot01(tmpx, tmpy,
				rand(t_speed/4, t_speed), angle+180+rand(RAND_CHILD,-RAND_CHILD), US_BALL_M_BLUE, 0);
		}
		loop(t2)
		{
			CreateShot01(tmpx, tmpy,
				rand(t_speed/5, t_speed/3*2), angle+180+rand(RAND_CHILD,-RAND_CHILD), US_BALL_S_BLUE, 0);
		}
		loop(t3)
		{
			CreateShot01(tmpx, tmpy,
				rand(t_speed/6, t_speed/2), angle+180+rand(RAND_CHILD,-RAND_CHILD), US_BALL_SS_BLUE, 0);
		}
	}

	//܂Vbg
	task shot_uzumaki(angle, a_gain, a_finish, min_speed, max_speed, graphic, wt, wt2)
	{
		let KYORI = 200;
		ATTACK_FLAG = 1;
		loop
		{
			let t = 0;
			while (absolute(t) < a_finish)
			{
				//(KYORI)ōōxɒB悤ɂׂ̉x
				let tmp = (max_speed^2-min_speed^2)/(2*KYORI);
				CreateShot02(GetX, GetY, min_speed, angle+t, tmp, max_speed, graphic, 5);
				t += a_gain;
				StopSE(SE_SHOT);
				PlaySE(SE_SHOT);
				wait(wt);
			}
			wait(wt2);
		}
		ATTACK_FLAG = 0;
	}
}
