#TouhouDanmakufu
#Title["All-Eclipsing Thunderstorm"]
#Text[Onis arcanum.]
#Image[snapshot\alleclipsingthunderstorm.bmp]
#Player[player\ProcellaPlayers\EmilyA\EmilyA.dnh, player\ProcellaPlayers\EmilyB\EmilyB.dnh, player\ProcellaPlayers\FeliciaA\FeliciaA.dnh, player\ProcellaPlayers\FeliciaB\FeliciaB.dnh]
#PlayLevel[Normal]
#BGM[bgm\Night Falls ~ Evening Star.mp3]
#ScriptVersion[2]

script_enemy_main {
	#include_function "lib\SHOT_REPLACE\shot_replace.dnh"
	let ImgBoss = "script\img\stg8enm.png";
	let ImgFamiliar = "script\img\circle6_s.png";
	let frame = -120;
	let mc = 0;
	let trig = 0;
	@Initialize {
		SetLife(9001);
		SetInvincibility(360);
		SetDamageRate(100, 0);
		SetTimer(151);
		SetScore(666666);
		CutIn(KOUMA, ""\""All-Eclipsing Thunderstorm"\", "script\img\gennerandonis.png", 0, 0, 0, 0);

		LoadGraphic(ImgBoss);
		SetTexture(ImgBoss);
		SetGraphicRect(6,195,70,285);
		psrand(747030);
		shotinit;

		SetMovePosition03(GetCenterX, GetClipMinY + 120, 10, 3);
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	@MainLoop {
		if(!OnBomb) {
			SetCollisionA(GetX, GetY, 32);
		}
		SetCollisionB(GetX, GetY, 16);
		if(frame == 0) {
			ThunderWire;
			CreateEnemyFromScript("Knifer", GetX, GetY, 0, 0, 0);
			CreateEnemyFromScript("Knifer", GetX, GetY, 0, 0, 4);
			CreateEnemyFromScript("Bolter", GetX, GetY, 0, 0, 0);
			CreateEnemyFromScript("Bolter", GetX, GetY, 0, 0, 4);
			CreateEnemyFromScript("RainMachine", GetX, GetY, 0, 0, 0);
			CreateEnemyFromScript("RainMachine", GetX, GetY, 0, 0, 4);
		}
		if(frame > 0) {
			trig -= 2.3;
		}
		if(frame%420 == 1) {
		}
		yield;
		frame++;
	}
	task ThunderWire {
		let r = 0;
		let t = 90;
		while(r < 400) {
			ascent(a in 0..4) {
				CreateShot01(GetX + cos(t + a * 90) * r, GetY + sin(t + a * 90) * r, 1, t + a * 90, BLUEI23, 120);
				CreateShot01(GetX + cos(180 - (t + a * 90)) * r, GetY + sin(180 - (t + a * 90)) * r, 1, 180 - (t + a * 90), BLUEI23, 120);
			}
			r += 8;
			t += 4;
			yield;
		}
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		loop(18) { CreateItem(ITEM_SCORE, GetX + rand(-50, 50), GetY - rand(20, 100)); }
		DeleteGraphic(ImgBoss);
		DeleteGraphic(ImgFamiliar);
	}
}
script_enemy Bolter {
	#include_function "lib\SHOT_REPLACE\shot_replace.dnh"
	let ImgFamiliar = "script\img\circle6_s.png";
	let frame = -120;
	let ga = 0;
	@Initialize {
		LoadGraphic(ImgFamiliar);
		SetTexture(ImgFamiliar);
		SetGraphicRect(0, 0, 64, 64);
		SetLife(6666);
		SetDamageRate(0, 0);

		if(GetArgument == 0) {
			SetMovePositionHermite(GetCenterX - 75, GetClipMinY + 100, 600, 270, 450, 90, 100);
		}
		else {
			SetMovePositionHermite(GetCenterX + 75, GetClipMinY + 100, 600, 270, 450, 90, 100);
		}
		MainTask;
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	task MainTask {
		loop(120) { yield; }
		loop {
			if(GetArgument == 0) {
				Thunderbolt(GetX, GetY, GetAngleToPlayer, 2, 120, 5, 300);
				loop(240) { yield; }
			}
			else {
				loop(120) { yield; }
				Thunderbolt(GetX, GetY, GetAngleToPlayer, 2, 120, 5, 300);
				loop(120) { yield; }
			}
		}
	}
	task Thunderbolt(x, y, angle, count, delay, dint, to) {
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		ObjLaser_SetLength(obj, 150);
		ObjLaser_SetWidth(obj, 20);
		ObjShot_SetGraphic(obj, YELLOW50);
		ObjShot_SetDelay(obj, delay);
		loop(5) { yield; }
		if(count > 0) {
			count--;
			delay -= dint;
			to -= dint;
			loop(2) {
				Thunderbolt(ObjLaser_GetEndX(obj), ObjLaser_GetEndY(obj), angle + rand(-60, 60), count, delay, dint, to);
			}
		}
		loop(to) { yield; }
		Obj_Delete(obj);
	}
	task KnifeLine(angle, graphic) {
		loop(6) {
			CreateShot01(GetX, GetY, 2.5, angle, graphic, 10);
			loop(10) { yield; }
		}
	}
	@MainLoop {
		yield;
		frame++;
	}
	@DrawLoop {
		ga += 2 - GetArgument;
		SetGraphicAngle(0, 0, ga);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgFamiliar);
	}
}
script_enemy Knifer {
	#include_function "lib\SHOT_REPLACE\shot_replace.dnh"
	let ImgFamiliar = "script\img\circle6_s.png";
	let frame = -120;
	let ga = 0;
	@Initialize {
		LoadGraphic(ImgFamiliar);
		SetTexture(ImgFamiliar);
		SetGraphicRect(192, 0, 256, 64);
		SetLife(6666);
		SetDamageRate(0, 0);

		if(GetArgument == 0) {
			SetMovePositionHermite(GetCenterX - 150, GetCenterY + 64, 900, 270, 900, 60, 80);
		}
		else {
			SetMovePositionHermite(GetCenterX + 150, GetCenterY + 64, 900, 270, 900, 120, 80);
		}
		MainTask;
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	task MainTask {
		loop(120) { yield; }
		loop {
			if(GetArgument == 0) {
				KnifeLine(GetAngleToPlayer, BLUE32);
				loop(180) { yield; }
			}
			else {
				loop(90) { yield; }
				KnifeLine(GetAngleToPlayer, AQUA32);
				loop(90) { yield; }
			}
		}
	}
	task KnifeLine(angle, graphic) {
		loop(6) {
			CreateShot01(GetX, GetY, 2.5, angle, graphic, 10);
			loop(10) { yield; }
		}
	}
	@MainLoop {
		yield;
		frame++;
	}
	@DrawLoop {
		ga += 2 - GetArgument;
		SetGraphicAngle(0, 0, ga);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgFamiliar);
	}
}
script_enemy RainMachine {
	#include_function "lib\SHOT_REPLACE\shot_replace.dnh"
	let ImgFamiliar = "script\img\circle6_s.png";
	let frame = -120;
	let ga = 0;
	let fa = 0;
	@Initialize {
		LoadGraphic(ImgFamiliar);
		SetTexture(ImgFamiliar);
		SetGraphicRect(192, 64, 256, 128);
		SetLife(6666);
		SetDamageRate(0, 0);

		if(GetArgument == 0) {
			SetMovePositionHermite(GetCenterX - 115, GetCenterY - 64, 900, 270, 900, 0, 120);
		}
		else {
			fa = 180;
			SetMovePositionHermite(GetCenterX + 115, GetCenterY - 64, 900, 270, 900, 180, 120);
		}
		MainTask;
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	task MainTask {
		loop(120) { yield; }
		loop {
			if(GetArgument == 0) {
				ascent(a in 0..36) {
					CreateShot01(GetX, GetY, 2.25, a * 10, AQUA04, 30);
					CreateShot01(GetX, GetY, 2, a * 10, BLUE04, 30);
					CreateShot01(GetX, GetY, 1.25, a * 10, BLUE04, 30);
					CreateShot01(GetX, GetY, 1, a * 10, AQUA04, 30);
				}
				loop(180) { yield; }
			}
			else {
				loop(90) { yield; }
				ascent(a in 0..36) {
					CreateShot01(GetX, GetY, 2.25, a * 10, AQUA04, 30);
					CreateShot01(GetX, GetY, 2, a * 10, BLUE04, 30);
					CreateShot01(GetX, GetY, 1.25, a * 10, BLUE04, 30);
					CreateShot01(GetX, GetY, 1, a * 10, AQUA04, 30);
				}
				loop(90) { yield; }
			}
		}
	}
	@MainLoop {
		yield;
		frame++;
	}
	@DrawLoop {
		ga -= 2 - GetArgument;
		SetGraphicAngle(0, 0, ga);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgFamiliar);
	}
}