#TouhouDanmakufu
#Title["Chaos Bolt" -Lunatic-]
#Text[Solemni arcanum.]
#Image[snapshot\chaosboltlunatic.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 cangle = 0;
	let turndir =1;
	@Initialize {
		SetLife(600);
		SetDamageRate(20, 10);
		SetInvincibility(120);
		SetTimer(46);
		SetScore(111111);
		CutIn(KOUMA, ""\""Chaos Bolt"\", "script\img\nyokoandsolemnus.png", 0, 0, 0, 0);

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

		SetMovePosition03(GetCenterX, GetClipMinY + 100, 10, 3);
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		trig += rand_int(0, 7);
		if(frame%150 == 1) {
			SetMovePosition03(GetCenterX + cos(trig) * 50, GetClipMinY + 120 + sin(trig / 2) * 20, 10, 3);
		}
		if(frame%2 == 1 || frame%3 == 1) {
			ascent(a in 0..3) {
				let randout = rand_int(0, 7);
				if(a == 0) {
					if(frame%7 == 1) {
						CreateShot01(GetX, GetY, rand(1.5, 2) + randout%6 / 5, rand(0, 360), RED03 + randout, 0);
					}
					CreateShot01(GetX, GetY, rand(1.5, 2) + randout%6 / 5, rand(0, 360), RED02 + randout, 0);
				}
				else {
					CreateShot01(GetX, GetY, rand(2, 2.5) + randout%6 / 5, rand(0, 360), RED04 + randout, 0);
				}
			}
		}
		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;
		}
	}
	task Tambourine(x, y, v, angle, freq, graphic, delay) {
     	let obj=Obj_Create(OBJ_SHOT);
	
     	Obj_SetPosition(obj, x, y);
     	Obj_SetAngle(obj, angle);
     	Obj_SetSpeed(obj, v);
	     ObjShot_SetGraphic(obj, graphic);
	     ObjShot_SetDelay  (obj, delay);
	     ObjShot_SetBombResist (obj, true);
	
	     while(Obj_BeDeleted(obj)==false) {

	             if(Obj_GetX(obj)<GetClipMinX) {
	                    Obj_SetAngle(obj, 180 - Obj_GetAngle(obj) );
	                    Obj_SetX(obj,  Obj_GetX(obj) + 0.1);
	             }
	             if(Obj_GetX(obj)>GetClipMaxX) {
	                    Obj_SetAngle(obj, 180 - Obj_GetAngle(obj) );
	                    Obj_SetX(obj,  Obj_GetX(obj) - 0.1);
	             }
	             if(Obj_GetY(obj)<GetClipMinY) {
	                    Obj_SetAngle(obj, 0 - Obj_GetAngle(obj) );
	                    Obj_SetY(obj,  Obj_GetY(obj) + 0.1);
	             }

	             if(Obj_GetY(obj)>GetClipMaxY) {
	                    Obj_SetAngle(obj, 0 - Obj_GetAngle(obj) );
	                    Obj_SetY(obj,  Obj_GetY(obj) - 0.1);
	             }
		if(frame%freq == 1) {
			let randout = rand_int(0, 7);
			if(randout == 0) {
				CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, rand(0, 360), 0.01, rand(1, 3), WHITE01, 30);
			}
			else if(randout == 1) {
				CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, rand(0, 360), 0.01, rand(1, 3), RED01, 30);
			}
			else if(randout == 2) {
				CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, rand(0, 360), 0.01, rand(1, 3), ORANGE01, 30);
			}
			else if(randout == 3) {
				CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, rand(0, 360), 0.01, rand(1, 3), YELLOW01, 30);
			}
			else if(randout == 4) {
				CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, rand(0, 360), 0.01, rand(1, 3), GREEN01, 30);
			}
			else if(randout == 5) {
				CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, rand(0, 360), 0.01, rand(1, 3), BLUE01, 30);
			}
			else if(randout == 6) {
				CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, rand(0, 360), 0.01, rand(1, 3), AQUA01, 30);
			}
			else {
				CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, rand(0, 360), 0.01, rand(1, 3), PURPLE01, 30);
			}
		}
	
	             yield;
	      }
	}
}
}