#TouhouDanmakufu
#Title[Emily Urmetus Attack 3]
#Text[Emiliae arcanum.]
#Image[]
#Player[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 frame = -120;
	let trig = 0;
	let movecounter = 1;
	let oa = 0;
	let r = 40;
	let rm = 0.5;
	let dest = 1;
	let tm = 1;
	@Initialize {
		SetLife(4000);
		SetInvincibility(121);
		SetDamageRate(100, 100);
		SetTimer(41);
//		SetScore(333333);
//		CutIn(KOUMA, ""\""Tri Edge"\", "script\img\jeaneandarcadia.png", 0, 0, 0, 0);

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

		SetMovePosition02(GetCenterX, GetClipMinY + 180, 120);
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		if(r > 80 || r < 40) {
			rm = rm * -1;
		}
		if(frame%240 == 1) {
			dest = dest * -1;
			if(movecounter%4 == 0) {
				SetMovePosition03(GetCenterX - 50, GetClipMinY + 100, 9, 3);
			}
			else if(movecounter%4 == 2) {
				SetMovePosition03(GetCenterX + 50, GetClipMinY + 100, 9, 3);
			}
			else {
				SetMovePosition03(GetCenterX, GetClipMinY + 180, 9, 3);
			}
			movecounter++;
		}
		if(tm > dest) {
			tm -= 0.05;
		}
		else if(tm < dest) {
			tm += 0.05;
		}
		r += rm;
		trig += tm;
		yield;
		frame++;
	}
	task SatelliteCircle2 {
		yield;
		loop {
			ascent(a in 0..6) {
				let bulletx = GetX + cos(trig * -1 + a * 60) * r * 1.5;
				let bullety = GetY + sin(trig * -1 + a * 60) * r * 1.5;
				if(frame%6 == 1) {
					CreateShot01(bulletx, bullety, 2, atan2(GetY - bullety, GetX - bulletx) + 180, BLUE12, 10);
				}
				CreateShotA(0, bulletx, bullety, 0);
				SetShotDataA(0, 0, 0, 0, 0, 0, 0,  BLUE02);
				SetShotKillTime(0, 1);
				FireShot(0);
			}
			yield;
		}
	}
	task SatelliteCircle1 {
		yield;
		loop {
			ascent(a in 0..4) {
				let bulletx = GetX + cos(trig + a * 90) * r;
				let bullety = GetY + sin(trig + a * 90) * r;
				let bullet1 = BLUE12;
				let bullet2 = BLUE02;
				if(frame%16 == 1) {
					ascent(a in 0..8) {
						CreateShot01(bulletx, bullety, 2, atan2(GetY - bullety, GetX - bulletx) + a * 45, bullet1, 10);
					}
				}
				CreateShotA(0, bulletx, bullety, 0);
				SetShotDataA(0, 0, 0, 0, 0, 0, 0, bullet2);
				SetShotKillTime(0, 1);
				FireShot(0);
			}
			yield;
		}
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgBoss);
	}
}