#Title[六師外道其の五]
#Text[サンジャヤ・ベーラッティプッタ]
#PlayLevel[EXTRA]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\yuyuko.dnh"

	let name = "六師「ないことはない可能性は必ずしも否定されないと思う」";

	let xIni = cx;
	let yIni = cy - 96;

	sub onInitialize {
		CutIn(YOUMU, name, bossCut, 1, 1, 463, 655);
		SetScore(4000000);
		SetTimer(55);
		SetLife(2000);
		back = CSD ~ "img\back4.png";

		SetDurableSpellCard;

		TMain;
	}

	sub onMainLoop {
		yield;
	}

	sub onDrawLoop {
	}

	sub onFinalize {
		DeleteGraphic(bossImg);
		createItems(ITEM_SCORE, 26, 64);
	}

/////////////////////////////////////////////////////////////////////

	task TMain {
		getReady_;
		SetAction(ACT_SHOT_A, 999999);

		let count = 0;

		loop {
			createShot(GetClipMinY + 64 + count * 12, count);
			wait(120 - count);
			count++;
		}
	}

	sub getReady_ {
		let wIni = 120;
		let alpha = 255;
		SetAction(ACT_MOVE, wIni);
		SetMovePosition02(xIni, yIni, wIni);
		loop(wIni) {
			alpha -= 255 / wIni / 2;
			SetAlpha(alpha);
			yield;
		}
	}

	function createShot(maxY, count) {
		let way = 16 + count * 2;

		loop(way) {
			shot;
		}

		task shot {
			let obj = createObjShot_(rand(GetClipMinX, GetClipMaxX), rand(GetClipMinY, maxY), 0.3, rand(-100, -80),
									BUTTER, [BLUE, rand_int(0, 7)][rand_int(0, 20) == 0], 0);
			Obj_SetAlpha(obj, rand(96, 194));

			let G = [rand(-0.1, 0), rand(0.3, 0.5)][rand_int(0, 6) == 0];
			let dir = [1, -1][rand_int(0, 1) == 0];
			let dAng = rand(0.1, 0.3) * dir;

			while(isInScreen(Obj_GetX(obj), Obj_GetY(obj))) {
				let x = Obj_GetX(obj) + cos(Obj_GetAngle(obj)) * Obj_GetSpeed(obj);
				let y = Obj_GetY(obj) + sin(Obj_GetAngle(obj)) * Obj_GetSpeed(obj) - G;

				let angle = atan2(y - Obj_GetY(obj), x - Obj_GetX(obj)) + dAng;
				let speed = [((x - Obj_GetX(obj))^2 + (y - Obj_GetY(obj))^2)^(1/2), 1][((x - Obj_GetX(obj))^2 + (y - Obj_GetY(obj))^2)^(1/2) > 1];

				Obj_SetAngle(obj, angle);
				Obj_SetSpeed(obj, speed);
				yield;
			}
		}
	}
	#include_function ".\lib\六師外道body.dnh"
}