#Title[六師外道其の一]
#Text[アジタ・ケーサカンバリン]
#PlayLevel[EXTRA]
#Player[FREE]
#ScriptVersion[2]

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

	let name = "六師「悲しみを恐れて喜びから退くまじ」";

	xIni = cx;
	yIni = GetClipMinY + 96;

	let earth = ORANGE;
	let water = BLUE;
	let fire  = RED;
	let wind  = GREEN;

	sub onInitialize {
		CutIn(YOUMU, name, bossCut, 1, 1, 463, 655);

		SetScore(2000000);
		SetTimer(60);
		SetLife(2000);
		SetDamageRate(30, 30);
		back = CSD ~ ".\img\back0.png";

		TMain;
	}

	sub onMainLoop {
		SetCollisionA(GetX, GetY, 64);
		SetCollisionB(GetX, GetY, 32);
		yield;
	}

	sub onDrawLoop {
	}

	sub onFinalize {
		DeleteGraphic(bossImg);
		createItems(ITEM_BOMB, 1, 0);
		createItems(ITEM_SCORE, 24, 64);
	}

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

	task TMain {
		getReady(120);

		loop{
			SetAction(ACT_STAND, 0);
			Concentration01(60);
			wait(60);
			SetAction(ACT_SHOT_B, 220);
			shot;
			wait(240);
			SetAction(ACT_SHOT_A, 120);
			Explosion01(GetX, GetY, 1, 0.5, 120);
			wait(50);
		}
	}

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

	sub shot {
		let baseAngle = GetAngleToPlayer;
		let span = 30;
		let angle = baseAngle - (span * (3 / 2));

		TCreateShot(angle, earth);
		angle += span;
		TCreateShot(angle, water);
		angle += span;
		TCreateShot(angle, fire);
		angle += span;
		TCreateShot(angle, wind);

		task TCreateShot(_angle, type) {
			let x = GetX + cos(_angle) * 8;
			let y = GetY + sin(_angle) * 8;
			let speed = 6;
			let delay = 0;
			let obj = createObjShot_(x + cos(_angle) * 10, y + sin(_angle) * 10, speed / 3, _angle, MIDDLE, type, 0);

			while(isInScreen(x, y)) {
				TShot(x, y, delay, type, _angle);
				x += cos(_angle) * speed;
				y += sin(_angle) * speed;
				delay += 2;
				wait(2);
			}

			task TShot(_x, _y, _delay, _type, __angle) {
				let _obj = createObjShot_(_x, _y, 0, 0, MIDDLE, _type, 1);

				wait(260 - delay);

				Obj_SetSpeed(_obj, rand(0.5, 0.8));
				Obj_SetAngle(_obj, getRandAngle(__angle));
				Obj_SetCollisionToPlayer(_obj, false);

				wait(60);

				Obj_SetCollisionToPlayer(_obj, true);

				function getRandAngle(___angle) {
					return  __angle + rand(30, 150) * [1, -1][rand_int(0, 1) == 0];
				}
			}
		}
	}
	#include_function ".\lib\六師外道body.dnh"
}