#TouhouDanmakufu
#Title[Emily Urmetus Attack 1 -Miniboss Lunatic-]
#Text[Emiliae arcanum.]
#Image[]
#Player[player\ProcellaPlayers\FeliciaA\FeliciaA.dnh, player\ProcellaPlayers\FeliciaB\FeliciaB.dnh]
#PlayLevel[Lunatic]
#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 frame = -120;
	let trig = 0;
	let movecounter = 0;
	let oa = 0;
	let oa2 = 4;
	let oa3 = 270;
	let ImgFamiliar = "script\img\circle6_s.png";
	@Initialize {
		SetLife(4000);
		SetInvincibility(121);
		SetDamageRate(100, 50);
		SetTimer(41);
//		SetScore(333333);
//		CutIn(KOUMA, ""\""Tri Edge"\", "script\img\jeaneandarcadia.png", 0, 0, 0, 0);

		LoadGraphic(ImgBoss);
		SetTexture(ImgBoss);
		LoadGraphic(ImgFamiliar);
		SetGraphicRect(6,195,70,285);
		psrand(747030);
		shotinit;
		OutCircle;
		SetMovePosition03(GetCenterX, GetClipMinY + 180, 10, 3);
	}
	task OutCircle {
		loop(121) {
			yield;
		}
		loop {
			oa2 = oa;
			loop(4) {
				ascent(a in 0..12) {
					CreateShot01(GetX, GetY, 1, oa + a * 30, BLUEI12, 0);
					CreateShot01(GetX, GetY, 1.5, oa2 + a * 30 + 15, REDI12, 0);
				}
				oa+=2;
				oa2-=2;
				loop(2) { yield; }
			}
			oa += 15;
			loop(30) {
				yield;
			}
		}
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		yield;
		if(frame%20 == 1) {
			ReHomer(GetX, GetY, 3, oa3, 0.05, WHITE03, 0);
			oa3 -= 60;
		}
		frame++;
	}
	function LemmingDelay(x, y) {
		CreateShotA(0, x, y, 30);
		SetShotDataA(0, 0, 0, 0, 0, 0, 0, WHITE57);
		SetShotKillTime(0, 0);	
		FireShot(0);
	}
	task ReHomer(x, y, v, angle, accel, graphic, delay) {
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDelay(obj, delay);
		while(Obj_GetSpeed(obj) > 0) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			Obj_SetSpeed(obj, Obj_GetSpeed(obj) - accel);
			yield;
		}
		while(delay > 0) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			Obj_SetSpeed(obj, 0);
			delay--;
			yield;
		}
		Obj_SetAngle(obj, atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj)));
		while(Obj_GetSpeed(obj) < v * 2) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			Obj_SetSpeed(obj, Obj_GetSpeed(obj) + accel * 2);
			yield;
		}
		while(Obj_BeDeleted(obj) == false) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			yield;
		}
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgBoss);
		DeleteGraphic(ImgFamiliar);
	}
}