#TouhouDanmakufu
#Title[Procella Attack 2]
#Text[Procellae arcanum.]
#Image[]
#Player[player\ProcellaPlayers\EmilyA\EmilyA.dnh, player\ProcellaPlayers\EmilyB\EmilyB.dnh, player\ProcellaPlayers\FeliciaA\FeliciaA.dnh, player\ProcellaPlayers\FeliciaB\FeliciaB.dnh]
#PlayLevel[Extra]
#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(3000);
		SetInvincibility(121);
		SetDamageRate(100, 0);
		SetTimer(36);
//		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 SatelliteCircle1 {
		yield;
		loop {
			ascent(a in 0..7) {
				let bulletx = GetX + cos(trig + a * 360 / 7) * r;
				let bullety = GetY + sin(trig + a * 360 / 7) * r;
				if(frame%112 == 1 + a * 16) {
					ascent(d in 0..36) {
						CreateShot02(bulletx, bullety, 5, atan2(GetY - bullety, GetX - bulletx) + d * 360 / 36, -0.1, 1, RED12 + a%8, 10);
					}
				}
				CreateShotA(0, bulletx, bullety, 0);
				SetShotDataA(0, 0, 0, 0, 0, 0, 0, a + 25);
				SetShotKillTime(0, 1);
				FireShot(0);
			}
			yield;
		}
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgBoss);
	}
}