#TouhouDanmakufu
#Title[Moonbeam Attack 2]
#Text[Radiae arcanum.]
#Player[player\ProcellaPlayers\EmilyA\EmilyA.dnh, player\ProcellaPlayers\EmilyB\EmilyB.dnh, 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 cangle = 0;
	let turndir =1;
	@Initialize {
		SetLife(3000);
		SetInvincibility(120);
		SetTimer(34);
//		SetScore(111111);
//		CutIn(KOUMA, ""\""Chakram Compass"\", "script\img\moonbeamandconscius.png", 0, 0, 0, 0);

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

		SetMovePosition02(GetCenterX, GetClipMinY + 180, 120);
		MainTask;
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		yield;
		frame++;
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgBoss);
	}
	task MainTask {
		loop(121) { yield; }
		loop {
			ascent(a in -12..12) {
				a *= 10;
				ascent(v in 0..4) {
					CreateShot02(GetX + cos(GetAngleToPlayer + a) * 45, GetY + sin(GetAngleToPlayer + a) * 45, 4, GetAngleToPlayer + a, -0.1, 1 + v / 4, RED21 + absolute((a / 10)%2), 10);
				}
				loop(2) { yield; }
			}
			descent(a in -12..12) {
				a *= 10;
				ascent(v in 0..4) {
					CreateShot02(GetX + cos(GetAngleToPlayer + a) * 45, GetY + sin(GetAngleToPlayer + a) * 45, 4, GetAngleToPlayer + a + 5, -0.1, 1 + v / 4, RED21 + absolute((a / 10)%2), 10);
				}
				loop(2) { yield; }
			}
			loop(60) { yield; }
			SetMovePosition03(GetCenterX - 80, GetClipMinY + 120, 10, 3);
			loop(60) { yield; }
			ascent(a in -12..12) {
				a *= 10;
				ascent(v in 0..4) {
					CreateShot02(GetX + cos(GetAngleToPlayer + a) * 45, GetY + sin(GetAngleToPlayer + a) * 45, 4, GetAngleToPlayer + a, -0.1, 1 + v / 4, RED21 + absolute((a / 10)%2), 10);
				}
				loop(2) { yield; }
			}
			descent(a in -12..12) {
				a *= 10;
				ascent(v in 0..4) {
					CreateShot02(GetX + cos(GetAngleToPlayer + a) * 45, GetY + sin(GetAngleToPlayer + a) * 45, 4, GetAngleToPlayer + a + 5, -0.1, 1 + v / 4, RED21 + absolute((a / 10)%2), 10);
				}
				loop(2) { yield; }
			}
			loop(60) { yield; }
			SetMovePosition03(GetCenterX, GetClipMinY + 180, 10, 3);
			loop(60) { yield; }
			ascent(a in -12..12) {
				a *= 10;
				ascent(v in 0..4) {
					CreateShot02(GetX + cos(GetAngleToPlayer + a) * 45, GetY + sin(GetAngleToPlayer + a) * 45, 4, GetAngleToPlayer + a, -0.1, 1 + v / 4, RED21 + absolute((a / 10)%2), 10);
				}
				loop(2) { yield; }
			}
			descent(a in -12..12) {
				a *= 10;
				ascent(v in 0..4) {
					CreateShot02(GetX + cos(GetAngleToPlayer + a) * 45, GetY + sin(GetAngleToPlayer + a) * 45, 4, GetAngleToPlayer + a + 5, -0.1, 1 + v / 4, RED21 + absolute((a / 10)%2), 10);
				}
				loop(2) { yield; }
			}
			loop(60) { yield; }
			SetMovePosition03(GetCenterX + 80, GetClipMinY + 120, 10, 3);
			loop(60) { yield; }
			ascent(a in -12..12) {
				a *= 10;
				ascent(v in 0..4) {
					CreateShot02(GetX + cos(GetAngleToPlayer + a) * 45, GetY + sin(GetAngleToPlayer + a) * 45, 4, GetAngleToPlayer + a, -0.1, 1 + v / 4, RED21 + absolute((a / 10)%2), 10);
				}
				loop(2) { yield; }
			}
			descent(a in -12..12) {
				a *= 10;
				ascent(v in 0..4) {
					CreateShot02(GetX + cos(GetAngleToPlayer + a) * 45, GetY + sin(GetAngleToPlayer + a) * 45, 4, GetAngleToPlayer + a + 5, -0.1, 1 + v / 4, RED21 + absolute((a / 10)%2), 10);
				}
				loop(2) { yield; }
			}
			loop(60) { yield; }
			SetMovePosition03(GetCenterX, GetClipMinY + 180, 10, 3);
			loop(60) { yield; }
		}
	}
	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;
		}
	}
}