#TouhouDanmakufu
#Title[Desdemona Valtiel Attack 4 -Easy-]
#Text[Desdemonae arcanum.]
#Player[player\ProcellaPlayers\EmilyA\EmilyA.dnh, player\ProcellaPlayers\EmilyB\EmilyB.dnh, 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 r = 0;
	let outAngle = 90;
	let sprayAngle = 0;
	let movecounter = 0;
	@Initialize {
		SetLife(4000);
		SetInvincibility(120);
		SetDamageRate(100, 0);
		SetTimer(51);
//		SetScore(555555);
//		CutIn(KOUMA, ""\""Personalized Indoctrination"\", "script\img\alexandaqua.png", 0, 0, 0, 0);

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

		SetMovePosition03(GetCenterX, GetClipMinY + 150, 9, 5);
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	function Flower(x, y, v1, accel, v2, num, sa, graphic) {
		loop(num) {
			CreateShot02(x, y, v1, sa, accel, v2, graphic, 0);
			if(num%2 == 0) {
				CreateShot02(x, y, v1, 180 - sa, accel, v2, graphic, 0);
			}
			else {
				CreateShot02(x, y, v1, 0 - sa, accel, v2, graphic, 0);
			}
			sa += (360 / num);
		}
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		if(frame%360 < 90 && frame > 0 && frame%15 == 1) {
			ascent(a in 0..5) {
				ascent(v in 0..3) {
					CreateShot01(GetX, GetY, 1 + v, GetAngleToPlayer + a * 72, PURPLE11, 0);
				}
			}
		}
		else if(frame%360 >= 91 && frame%360 <= 181 && frame%10 == 1) {
			TrailShot(GetX, GetY, 1, 4, sprayAngle, PURPLE03, PURPLE02, PURPLE01, 0);
			if(movecounter%2 == 0) {
				sprayAngle += 20;
			}
			else {
				sprayAngle -= 20;
			}
		}
		else if(frame%360 == 211) {
			movecounter++;
			loop(182) {
				let vm = rand(0.1, 3);
				let rd = rand_int(0, 1);	
				if(rd == 0) {
					CreateShot02(GetX, GetY, vm + 3, rand(0, 360), -0.1, vm, WHITE01, 60);
				}
				else {
					CreateShot02(GetX, GetY, vm + 3, rand(0, 360), -0.1, vm, RED54, 60);
				}
			}
			loop(182) {
				let vm = rand(0.1, 2);
					CreateShot02(GetX, GetY, vm + 3, rand(0, 360), -0.1, vm, WHITE05, 60);
			}
		}
		yield;
		frame++;
	}
	function TrailShot(x, y, v1, v2, angle, headshot, bodyshot, tailshot, delay) {
		CreateShot01(GetX, GetY, v2, angle, headshot, delay);
		loop(8) {
			CreateShot01(GetX, GetY, rand(v1 + 0.5, v2), angle + rand(-2.5, 2.5), bodyshot, delay);
			CreateShot01(GetX, GetY, rand(v1, v2 - 0.5), angle + rand(-2.5, 2.5), tailshot, delay);
		}
	}
	@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;
		}
	}
}