#TouhouDanmakufu
#Title["Hurricane" -Easy-]
#Text[Aquae arcanum.]
#Image[snapshot\hurricaneeasy.bmp]
#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 turndir = 1;
	let movecounter = 0;
	let counter = 0;
	let outAngle = 0;
	@Initialize {
		SetLife(800);
		SetInvincibility(120);
		SetDamageRate(20, 10);
		SetTimer(41);
		SetScore(333333);
		CutIn(KOUMA, ""\""Hurricane"\", "script\img\alexandaqua.png", 0, 0, 0, 0);

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

		SetMovePosition03(GetCenterX, GetClipMinY + 40, 10, 3);
		OutCircle;
	}
	task OutCircle {
		loop(121) {
			yield;
		}
		loop {
			if(counter%2 == 0) {
				outAngle += 4;
			}
			loop(24) {
				ascent(d in 0..3) {
					CreateShotA(2, GetX, GetY, d * 5);
					if(counter%2 == 0) {
						SetShotDataA(2, 0, 3, outAngle, 0.3, -0.1, 1.4, AQUA04);
					}
					else {
						SetShotDataA(2, 0, 3, outAngle, -0.3, -0.1, 1.4, BLUE04);
					}
					FireShot(2);
				}
				outAngle += 15 * (counter%2 * 2 - 1) * -1;
			}
			counter++;
			loop(30) {
				yield;
			}
		}
	}

	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		if(frame%240 == 1) {
			Whirlwind(GetX + (movecounter%3 - 1) * 90, GetY, 1.8, 90, 45, movecounter%2 * 2 - 1, WHITE03);
			movecounter++;
		}
		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 Whirlwind(x, y, v, angle, radius, turndir, graphic) {
		let obj = Obj_Create(OBJ_SHOT);
		let t = 0;
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, v);
		ObjShot_SetGraphic(obj, WHITE01);
		ObjShot_SetDelay(obj, 30);
		while(Obj_BeDeleted(obj) == false) {
			ascent(a in 0..8) {
				CreateShotA(0, Obj_GetX(obj) + cos(t + a * 45) * radius, Obj_GetY(obj) + sin(t + a * 45) * radius, 0);
				SetShotDataA(0, 0, 0, 0, 0, 0, 0, graphic);
				SetShotKillTime(0, 1);
				FireShot(0);
			}
			t += v;
			yield;
		}
	}
}