#TouhouDanmakufu
#Title[Genner Sitiens Attack 4 -Hard-]
#Text[Genneri arcanum.]
#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;
	let var = 0.3;
	let vm = -0.05;
	let r = 0;
	let md = 0;
	let present = true;
	@Initialize {
		SetLife(4000);
		SetInvincibility(120);
		SetDamageRate(100, 0);
		SetTimer(89);
//		SetScore(666666);
//		CutIn(KOUMA, ""\""Razor Wind"\", "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);
		MainTask;
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	function Returners {
		ascent(a in 0..15) {
			ascent(t in 0..2) {
				let turndir = t%2 * 2 - 1;
				CreateShotA(0, GetX, GetY, 0);
				SetShotDataA(0, 0, 2, GetAngleToPlayer + a * 24, 2 * turndir, 0, 2, GREEN03);
				SetShotDataA(0, 120, 1.5, NULL, 0, 0, 1.5, GREEN03);
				FireShot(0);
			}
		}
	}
	@MainLoop {
		if(present) {
			SetCollisionA(GetX, GetY, 32);
			SetCollisionB(GetX, GetY, 16);
		}
		md -= frame * 1.82;
		if(frame == -120) {
			Concentration01(120);
		}
		yield;
		frame++;
	}
	task MainTask {
		loop(121) { yield; }
		loop {
			present = false;
			let outAngle = 90;
			ascent(i in 0..12) {
				ascent(a in 0..20) {
					CreateShotA(0, GetX, GetY, 0);
					SetShotDataA(0, 0, 4, a * 18 + outAngle, 0, -0.075, 0, PURPLE02);
					SetShotDataA(0, 60, NULL, a * 18 + outAngle + 90, 0, 0.01, 3, PURPLE02);
					FireShot(0);
					CreateShotA(0, GetX, GetY, 0);
					SetShotDataA(0, 0, 2, a * 18 + outAngle - 9, 0, -0.075, 0, BLUE02);
					SetShotDataA(0, 60, NULL, a * 18 + outAngle - 99, 0, 0.01, 3, BLUE02);
					FireShot(0);
				}
				loop(10) { yield; }
				outAngle += 20;
			}
			loop(30) { yield; }
			present = true;
			loop(150) { yield; }
			SetMovePosition03(GetCenterX + cos(md) * 60, GetClipMinY + 100 + sin(md) * 50, 10, 2);
			present = false;
			ascent(i in 0..4) {
				ascent(a in 0..180) {
					CreateShot01(GetX, GetY, 1 + a%8 / 16, a * 2 + outAngle, GREEN12, 0);
				}
				CreateShot01(GetX, GetY, 2 - 8 / 18, GetAngleToPlayer, RED03, 45);
				CreateShot01(GetX, GetY, 2 - 4 / 18, GetAngleToPlayer, RED03, 45);
				CreateShot01(GetX, GetY, 2, GetAngleToPlayer, RED03, 45);
				outAngle -= 16;
				loop(90) { yield; }
			}
			loop(30) { yield; }
			present = true;
			loop(150) { yield; }
			SetMovePosition03(GetCenterX + cos(md) * 60, GetClipMinY + 100 + sin(md) * 50, 10, 2);
			present = false;
			ascent(i in 0..10) {
				ascent(a in 0..15) {
					CreateShot02(GetX, GetY, 0.1, GetAngleToPlayer + a * 24, 0.05, 6, YELLOW03, 10);
					CreateShot02(GetX, GetY, 0.1, GetAngleToPlayer + a * 24 + 12, 0.05, 6, YELLOW05, 10);
				}
				loop(15) { yield; }
			}
			loop(30) { yield; }
			present = true;
			loop(150) { yield; }
			SetMovePosition03(GetCenterX + cos(md) * 60, GetClipMinY + 100 + sin(md) * 50, 10, 2);
		}
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		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;
		}
	}
}