#TouhouDanmakufu
#Title["Boiling Seas" -Hard-]
#Text[Onis arcanum.]
#Image[snapshot\boilingseashard.bmp]
#Player[player\ProcellaPlayers\EmilyA\EmilyA.dnh, player\ProcellaPlayers\EmilyB\EmilyB.dnh, player\ProcellaPlayers\FeliciaA\FeliciaA.dnh, player\ProcellaPlayers\FeliciaB\FeliciaB.dnh]
#PlayLevel[Hard]
#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;
	@Initialize {
		SetLife(1000);
		SetInvincibility(600);
		SetDamageRate(20, 0);
		SetTimer(61);
		SetScore(666666);
		CutIn(KOUMA, ""\""Boiling Seas"\", "script\img\gennerandonis.png", 0, 0, 0, 0);

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

		SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		if(frame%5 == 1) {
			CreateShot02(rand(GetClipMinX, GetClipMaxX), GetClipMaxY, 1, rand(260, 280), -0.01, rand(0.5, 1), AQUA04 + frame%2, 10);
		}
		if(frame%960 == 1) {
			AimingSpheres;
		}
		yield;
		frame++;
	}
	task AimingSpheres {
		AimingSphere(GetClipMinX + 100, GetClipMinY, 3, 90, BLUE03, BLUE02, 240);
		AimingSphere(GetClipMaxX - 100, GetClipMinY, 3, 90, BLUE03, BLUE02, 240);
		loop(480) { yield; }
		AimingSphere(GetClipMinX + 100, GetClipMaxY, 3, 270, BLUE03, WHITE02, 240);
		AimingSphere(GetClipMaxX - 100, GetClipMaxY, 3, 270, BLUE03, WHITE02, 240);
	}
	task AimingSphere(x, y, v, angle, graphic, sg, delay) {
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		while(Obj_BeDeleted(obj) == false) {
			AimAmulet(Obj_GetX(obj), Obj_GetY(obj), 1, rand(0, 360), AQUA02, sg, delay);
			delay -= 5;
			loop(3) { yield; }
		}
	}
	task AimAmulet(x, y, v, angle, graphic1, graphic2, delay) {
		let obj = Obj_Create(OBJ_SHOT);
		let aim = false;
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, v);
		ObjShot_SetGraphic(obj, graphic1);
		loop(delay) {
			if(Obj_GetSpeed(obj) > 0.5) {
				Obj_SetSpeed(obj, Obj_GetSpeed(obj) - 0.05);
			}
			else if(Obj_GetSpeed(obj) < 0.5) {
				Obj_SetSpeed(obj, 0.5);
			}
			yield;
		}
		Obj_SetAngle(obj, atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj)));
		ObjShot_SetGraphic(obj, graphic2);
		while(Obj_BeDeleted(obj) == false) {
			if(Obj_GetSpeed(obj) < v) {
				Obj_SetSpeed(obj, Obj_GetSpeed(obj) + 0.05);
			}
			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);
	}
	task CreateShot03(x, y, v, angle, graphic, delay) {
		let obj = Obj_Create(OBJ_SHOT);
		let lifecounter = 10;
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, angle);
		Obj_SetAutoDelete(obj, false);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetBombResist(obj, true);
		ObjShot_SetDelay(obj, delay);
		while(Obj_BeDeleted(obj) == false) {
			lifecounter--;
			if(lifecounter <= 0) {
				Obj_SetAutoDelete(obj, true);
			}
			yield;
		}
	}
}