#TouhouDanmakufu
#Title[Moonbeam Attack 1]
#Text[Radiae arcanum.]
//#Image[snapshot\chakramcompasses.bmp]
#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(3333);
		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);
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		if(frame%480 >= 1 && frame%480 <= 181) {
			CreateShot02(GetX + cos(cangle) * 45, GetY + sin(cangle) * 45, 0.5, cangle, 0.01, rand(1, 3), ORANGE05, 30);
			CreateShot02(GetX + cos(cangle + 180) * 45, GetY + sin(cangle + 180) * 45, 0.5, cangle + 180, 0.01, rand(1, 3), YELLOW05, 30);
			cangle += frame%480 / 5 * turndir;
		}
		if(frame%480 == 181) {
			SetMovePosition03(GetCenterX + prand_int(-80, 80), GetClipMinY + 120, 10, 4);
			Concentration01(60);
		}
		if(frame%480 >= 241 && frame%480 <= 361 && frame%3 == 0) {
			CreateShot01(GetX, GetY, 5, GetAngleToPlayer + 7.5, WHITE02, 0);
			CreateShot01(GetX, GetY, 5, GetAngleToPlayer - 7.5, WHITE02, 0);
		}
		if(frame%480 == 361) {
			SetMovePosition03(GetCenterX, GetClipMinY + 180, 10, 4);
			Concentration01(120);
			turndir = turndir * -1;
		}
		yield;
		frame++;
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgBoss);
	}
	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;
		}
	}
}