#東方弾幕風
#Title[白蓮さん通常１]
#Text[夢の回転木馬準備]
#ScriptVersion[2]

script_enemy_main {
	let name	= "";

	// shot_all.png
	#include_function ".\lib_usershot.txt"
	// 白蓮さん初期設定
	#include_function ".\lib\setting_byakuren.txt"

	// 初期位置
	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);
	}

	// メインタスク
	task TMain {
		yield;

		TRate;
		standBy;

		//エフェクト
		effect_blank_circle();
		powerSave;

		//弾
		TShot;
	}

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

	//炸裂ショット
	//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);	//反射後の角度
		let timer = ceil(kyori/speed);	//当たるまでの時間
		let tmpx = GetX+cos(angle)*kyori;
		let tmpy = GetY+sin(angle)*kyori;
		wait(timer+15);

		//炸裂 画像固定
		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);
		}
	}

	//うずまきショット
	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)で最高速度に達するようにする為の加速度
				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;
	}
}
