#TouhouDanmakufu
#Title["Five of a Kind -Queens-"]
#Text[Casu arcanum scelesta.]
#Image[snapshot\fiveofakindqueens.bmp]
#Player[player\ProcellaPlayers\EmilyA\EmilyA.dnh, player\ProcellaPlayers\EmilyB\EmilyB.dnh]
#PlayLevel[Normal]
#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 circle1 = 0;
	let circle2 = 0;
	let circle3 = 0;
	let turnmarker = 1;
	let trig = 0;
	@Initialize {
		SetLife(1000);
		SetInvincibility(121);
		SetDamageRate(20, 5);
		SetTimer(44);
		SetScore(444444);
		CutIn(KOUMA, ""\""Five of a Kind -Queens-"\", "script\img\feliciaandcasus.png", 0, 0, 0, 0);

		LoadGraphic(ImgBoss);
		SetTexture(ImgBoss);
		LoadGraphic("script\img\joker.png");
		LoadGraphic("script\img\queenofhearts.png");
		SetGraphicRect(6,195,70,285);
		psrand(747030);
		shotinit;
		CardSwirl(GetCenterX, GetClipMinY + 120, 13);
		CardSwirl(GetCenterX, GetClipMinY + 120, -13);

		SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		if(frame%75 == 1) {
			CardEffect("script\img\joker.png", GetCenterX + cos(circle3) * 150, GetClipMinY, 3, 90, 2, -0.0075);
		}
		else if(frame%30 == 1) {
			CardEffect("script\img\queenofhearts.png", GetCenterX + cos(circle1) * 150, GetClipMinY, 3, 90, 2, -0.0075);
		}
		else if(frame%30 == 16) {
			CardEffect("script\img\queenofhearts.png", GetCenterX + cos(circle2) * 150, GetClipMinY, 3, 90, 2, -0.0075);
		}
		circle1 += 2.5;
		circle2 += 5.5;
		circle3 += 17.5;
		yield;
		frame++;
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		loop(12) {
			CreateItem(ITEM_SCORE, GetX + rand(-50, 50), GetY - rand(20, 100));
		}
		DeleteGraphic("script\img\joker.png");
		DeleteGraphic("script\img\queenofhearts.png");
		DeleteGraphic(ImgBoss);
	}
	task CardSwirl(x, y, v) {
		loop(121) {
			yield;
		}
		let a = 0;
		loop {
			if(a%3 == 0) {
				CardAccelerator(x, y, 6, -0.25, 0.02, 2, 90 + a * v, 10, RED56);
			}
			else if(a%3 == 1) {
				CardAccelerator(x, y, 6, -0.25, 0.02, 2, 90 + a * v, -10, BLUE56);
			}
			else {
				CardAccelerator(x, y, 6, -0.25, 0.02, 2, 90 + a * v, 0, WHITE56);
			}
			a++;
			yield;
		}
	}
	task CardAccelerator(x, y, v1, a1, a2, v2, angle, am, graphic) {
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, v1);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDelay(obj, 0);
		while(Obj_BeDeleted(obj) == false) {
			if(v1 > 0) {
				v1 += a1;
			}
			else {
				CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, angle + am, a2, v2, graphic, 0);
				Obj_Delete(obj);
			}
			yield;
		}
	}
	task CardEffect(path, x, y, v, angle, scale, growth) {
		let obj = Obj_Create(OBJ_EFFECT);
		let hg = false;
		Obj_SetPosition(obj, x, y);
		ObjEffect_SetTexture(obj, path);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexUV(obj, 0, 0, 0);
		ObjEffect_SetVertexUV(obj, 1, 60, 0);
		ObjEffect_SetVertexUV(obj, 2, 60, 100);
		ObjEffect_SetVertexUV(obj, 3, 0, 100);
		ObjEffect_SetVertexXY(obj, 0, x - 30, y - 50);
		ObjEffect_SetVertexXY(obj, 1, x + 30, y - 50);
		ObjEffect_SetVertexXY(obj, 2, x + 30, y + 50);
		ObjEffect_SetVertexXY(obj, 3, x - 30, y + 50);
		while(Obj_BeDeleted(obj) == false) {
			Obj_SetPosition(obj, x, y);
			ObjEffect_SetVertexXY(obj, 0, -30 * scale, -50 * scale);
			ObjEffect_SetVertexXY(obj, 1, 30 * scale, -50 * scale);
			ObjEffect_SetVertexXY(obj, 2, 30 * scale, 50 * scale);
			ObjEffect_SetVertexXY(obj, 3, -30 * scale, 50 * scale);
			scale += growth;
			x += cos(angle) * v;
			y += sin(angle) * v;
			if(GetPlayerX < x + 20 * scale && GetPlayerX > x - 20 * scale && GetPlayerY < y + 40 * scale && GetPlayerY > y - 40 * scale && GetTimeOfPlayerInvincibility <= 0) {
				ShootDownPlayer;
			}
			else if(GetPlayerX < x + 30 * scale && GetPlayerX > x - 30 * scale && GetPlayerY < y + 40 * scale && GetPlayerY > y - 40 * scale && GetTimeOfPlayerInvincibility <= 0 && hg == false) {
				AddGraze(1);
				hg = true;
			}
			yield;
		}
	}
	task CreateShot03(x, y, v, angle, graphic, delay) {
		let obj = Obj_Create(OBJ_SHOT);
		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);
		yield;
	}
}