#Title[六師外道其の四]
#Text[マッカリ・ゴーサーラ]
#PlayLevel[EXTRA]
#Player[FREE]
#ScriptVersion[2]

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

	let name = "六師「宿命を前に人は非力なり」";

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

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

		TMain;
	}

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

	sub onDrawLoop {
	}

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

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

	task TMain {
		getReady(120);

		SetAction(ACT_SHOT_A, 999999);
		Concentration01(120);
		wait(150);
		SetDamageRate(15, 15);

		createShot;
		wait(740);
		createShot;
		wait(380);
		createShot;
		wait(180);

		SetDamageRate(50, 50);

		let count = 0;
		loop {
			createShot;
			count++;
			wait(180 - count * 10);
		}
	}

	sub createShot {
		ascent(let i in 0..4) {
			CreateEnemyFromScript("woolBall", GetX, GetY, 0, i * 90, 0);
		}
	}
	#include_function ".\lib\六師外道body.dnh"
}

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

script_enemy woolBall {
	#include_function ".\lib\六師外道Common_.dnh"

	let obj = createObjShot_(GetX, GetY, 0, GetAngle, RING, GREEN, -1);

	@Initialize {
		SetLife(500);
		SetDamageRateEx(30, 30, 110, 110);
		SetScore(30000);

		TMain;
	}

	@MainLoop {
		SetCollisionA(GetX, GetY, 64);
		yield;
	}

	@DrawLoop {
	}

	@Finalize {
		Obj_Delete(obj);
	}

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

	task TMain {
		ObjShot_SetBombResist(obj, true);

		TBall;
		TShot;

		loop {
			SetX(Obj_GetX(obj));
			SetY(Obj_GetY(obj));
			yield;
		}

		task TBall {
			let angle = Obj_GetAngle(obj);
			let speed = 2.5;
			let dAngle = 360 / 120;
			let dSpeed = 0;

			loop(120) {
				angle += dAngle;
				setObjData(angle, speed);
				yield;
			}

			angle += 45;
			dSpeed = -0.05;

			loop(60) {
				speed = max(speed + dSpeed, 1.5);
				setObjData(angle, speed);
				yield;
			}

			angle += 90;
			dAngle = 1.8;
			speed = 2;

			loop(200) {
				angle += dAngle;
				setObjData(angle, speed);
				yield;
			}

			angle += 180;
			dAngle = -1;
			dSpeed = 0.02;

			loop(360) {
				angle += dAngle;
				speed = max(speed + dSpeed, 2.5);
				setObjData(angle, speed);
				yield;
			}

			Obj_Delete(obj);

			function setObjData(_angle, _speed) {
				Obj_SetAngle(obj, _angle);
				Obj_SetSpeed(obj, _speed);
			}
		}

		task TShot {
			loop {
				createNmlShot01_(GetX, GetY, 0.8, Obj_GetAngle(obj) + 180, RICE, GREEN, 0);
				wait(7);
			}
		}
	}
}