#TouhouDanmakufu
#Title["Sacred Antibody" -Easy-]
#Text[Nihili arcanum.]
#Image[snapshot\sacredantibodyeasy.bmp]
#Player[player\ProcellaPlayers\FeliciaA\FeliciaA.dnh, player\ProcellaPlayers\FeliciaB\FeliciaB.dnh]
#PlayLevel[Easy]
#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 turndir = 1;
	let movecounter = 0;
	let oa = 0;
	@Initialize {
		SetLife(700);
		SetInvincibility(361);
		SetDamageRate(20, 5);
		SetTimer(45);
		SetScore(444444);
		CutIn(KOUMA, ""\""Sacred Antibody"\", "script\img\emilycutin.png", 0, 0, 0, 0);

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

		SetMovePosition02(GetCenterX, GetClipMinY + 180, 120);
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		SetShotAutoDeleteClip(0, 0, 0, 0);
		if(frame%480 == 1) {
			ReShooterSpiral;
			turndir = turndir * -1;
		}
		else if(frame%480 == 241) {
			ReHomerSpiral;
		}
		if(frame%240 == 181) {
			if(movecounter%4 == 0) {
				SetMovePosition03(GetCenterX - 60, GetClipMinY + 100, 9, 3);
			}
			else if(movecounter%4 == 2) {
				SetMovePosition03(GetCenterX + 60, GetClipMinY + 100, 9, 3);
			}
			else {
				SetMovePosition03(GetCenterX, GetClipMinY + 180, 9, 3);
			}
			movecounter++;
		}
		yield;
		frame++;
	}
	function LemmingDelay(x, y) {
		CreateShotA(0, x, y, 30);
		SetShotDataA(0, 0, 0, 0, 0, 0, 0, WHITE57);
		SetShotKillTime(0, 0);	
		FireShot(0);
	}
	function ReshotRing(x, y) {
		ascent(a in 0..8) {
			CreateShot01(x, y, 0.5, a * 45, BLUE12, 0);
		}
	}
	task ReShooterSpiral {
		ascent(a in 0..8) {
			ReShooter(GetX, GetY, 3, a * 45, 0.05, WHITE03, WHITE01, 0);
			loop(10) {
//				yield;
			}
		}
	}
	task ReHomerSpiral {
		ascent(a in 0..9) {
			ReHomer(GetX, GetY, 3, a * 45 * turndir, 0.05, WHITE03, 0);
			loop(10) {
				yield;
			}
		}
	}
	task ReShooter(x, y, v, angle, accel, graphic1, graphic2, delay) {
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic1);
		ObjShot_SetDelay(obj, delay);
		while(Obj_GetSpeed(obj) > 0) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			Obj_SetSpeed(obj, Obj_GetSpeed(obj) - accel);
			yield;
		}
		while(delay > 0) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			Obj_SetSpeed(obj, 0);
			delay--;
			yield;
		}
		while(Obj_GetSpeed(obj) < v) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			if(frame%17 == 1) {
				ReshotRing(Obj_GetX(obj), Obj_GetY(obj));
			}
			Obj_SetSpeed(obj, Obj_GetSpeed(obj) + accel);
			Obj_SetAngle(obj, Obj_GetAngle(obj) + turndir);
			yield;
		}
		while(Obj_BeDeleted(obj) == false) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			if(frame%15 == 1) {
				ReshotRing(Obj_GetX(obj), Obj_GetY(obj));
			}
			yield;
		}
	}
	task ReHomer(x, y, v, angle, accel, 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);
		ObjShot_SetDelay(obj, delay);
		while(Obj_GetSpeed(obj) > 0) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			Obj_SetSpeed(obj, Obj_GetSpeed(obj) - accel);
			yield;
		}
		while(delay > 0) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			Obj_SetSpeed(obj, 0);
			delay--;
			yield;
		}
		Obj_SetAngle(obj, atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj)));
		while(Obj_GetSpeed(obj) < v * 2) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			Obj_SetSpeed(obj, Obj_GetSpeed(obj) + accel * 2);
			yield;
		}
		while(Obj_BeDeleted(obj) == false) {
			LemmingDelay(Obj_GetX(obj), Obj_GetY(obj));
			yield;
		}
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgBoss);
	}
}