#TouhouDanmakufu
#Title["Water Claw" -Lunatic-]
#Text[Aquae arcanum.]
#Image[snapshot\waterclawlunatic.bmp]
#Player[player\ProcellaPlayers\EmilyA\EmilyA.dnh, player\ProcellaPlayers\EmilyB\EmilyB.dnh, player\ProcellaPlayers\FeliciaA\FeliciaA.dnh, player\ProcellaPlayers\FeliciaB\FeliciaB.dnh]
#PlayLevel[Lunatic]
#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 harbinger = 0;
	@Initialize {
		SetLife(500);
		SetInvincibility(120);
		SetDamageRate(0, 0);
		SetTimer(31);
		SetScore(222222);
		SetDurableSpellCard;
		CutIn(KOUMA, ""\""Water Claw"\", "script\img\alexandaqua.png", 0, 0, 0, 0);

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

		SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	@MainLoop {
		SetCollisionB(GetX, GetY, 16);
		if(frame%240 == 1) {
			harbinger = GetAngleToPlayer;
			ascent(a in 0..10) {
				CreateShot01(GetX, GetY, 6, harbinger, AQUA32, a * 6);
			}
		}
		else if(frame%240 == 61) {
			SetAngle(harbinger);
			SetSpeed(6);
		}
		if(IsOffScreen == true && frame%240 > 69) {
			SetSpeed(0);
			CreateShotA(0, GetX, GetY, 0);	
			SetShotDataA(0, 0, rand(0.5, 2.5), harbinger + rand(90, 270), rand(-0.2, 0.2), 0, 4, BLUE57);
			FireShot(0);
			if(frame%2 == 1) {
				CreateShotA(0, GetX, GetY, 0);	
				SetShotDataA(0, 0, rand(0.5, 2.5), harbinger + rand(90, 270), rand(-0.2, 0.2), 0, 4, BLUE57);
				FireShot(0);
			}
		}
		yield;
		frame++;
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		loop(6) {
			CreateItem(ITEM_SCORE, GetX + rand(-50, 50), GetY - rand(20, 100));
		}
		DeleteGraphic(ImgBoss);
	}
	task BurstLaser(x, y, v1, v2, angle, l, w, graphic1, graphic2, delay) {
		let obj = Obj_Create(OBJ_SINUATE_LASER);
		let boom = false;
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v1);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic1);
		ObjShot_SetDelay(obj, delay);
		ObjSinuateLaser_SetLength(obj, l);
		ObjSinuateLaser_SetWidth(obj, w);
		while(Obj_BeDeleted(obj) == false) {
			if(Obj_GetSpeed(obj) < v2) {
				Obj_SetSpeed(obj, Obj_GetSpeed(obj) + 0.05);
			}
			if((Obj_GetX(obj) < GetClipMinX || Obj_GetX(obj) > GetClipMaxX || Obj_GetY(obj) < GetClipMinY || Obj_GetY(obj) > GetClipMaxY) && boom == false) {
				ascent(m in 0..24) {
					CreateShot01(Obj_GetX(obj), Obj_GetY(obj), v1, m * 15, graphic2, 0);
				}
				boom = true;
			}
			yield;
		}
		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;
		}
	}
}