#TouhouDanmakufu
#Title["A Bird!"]
#Text[Solemni arcanum.]
#Image[snapshot\abird!.bmp]
#Player[player\ProcellaPlayers\EmilyA\EmilyA.dnh, player\ProcellaPlayers\EmilyB\EmilyB.dnh, player\ProcellaPlayers\FeliciaA\FeliciaA.dnh, player\ProcellaPlayers\FeliciaB\FeliciaB.dnh]
#PlayLevel[Hard]
#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(666);
		SetDamageRate(20, 10);
		SetInvincibility(120);
		SetTimer(34);
		SetScore(333333);
		CutIn(KOUMA, ""\""A Bird!"\", "script\img\nyokoandsolemnus.png", 0, 0, 0, 0);

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

		SetMovePosition02(GetCenterX, GetClipMinY + 100, 120);
	}
	function PointIsOnScreen(x, y) {
		return x < GetClipMaxX + 64 && x > GetClipMinX - 64 && y < GetClipMaxY + 64 && y > GetClipMinY - 64;
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		yield;
		frame++;
	}
	task Birds {
		let graphics = [RED12, RED21, RED22, RED31, RED32, RED03];
		loop(121) { yield; }
		loop {
			let delay = 150;
			while(delay > 0) {
				let ad = rand_int(-18, 18) * 10;
				let gd = rand_int(0, 7);
				let gd2 = rand_int(0, 5);
				ReAimShot(GetX, GetY, 3, ad + 90, false, graphics[gd2] + gd, delay);
				loop(3) { delay--; yield; }
			}
			delay = 150;
			while(delay > 0) {
				let ad = rand_int(-18, 18) * 10;
				let gd = rand_int(0, 7);
				let gd2 = rand_int(0, 5);
				ReAimShot(GetX, GetY, 3, ad + 90, true, graphics[gd2] + gd, delay);
				loop(3) { delay--; yield; }
			}
		}
	}
	task ReAimShot(x, y, v, angle, param, 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);
		loop(delay) {
			if(Obj_GetSpeed(obj) > 0) {
				Obj_SetSpeed(obj, Obj_GetSpeed(obj) - 0.05);
			}
			else {
				Obj_SetSpeed(obj, 0);
			}
			yield;
		}
		if(!Obj_BeDeleted(obj)) {
			let angle = Obj_GetAngle(obj);
			if(param) {
				angle = atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj));
			}
			ascent(a in -1..2) {
				ascent(v in 0..6) {
					CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 1, angle + a * 5, 0.05, 1 + v / 2, graphic, 0);
				}
			}
			Obj_Delete(obj);
		}
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		loop(9) {
			CreateItem(ITEM_SCORE, GetX + rand(-50, 50), GetY - rand(20, 100));
		}
		CreateItem(ITEM_1UP, GetX + rand(-50, 50), GetY - rand(20, 100));
		DeleteGraphic(ImgBoss);
	}
}