#TouhouDanmakufu
#Title[Alex Ryder Attack 1 -Easy-]
#Text[Alexis 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 tm = 2;
	let tmm = 0.05;
	let mc = 0;
	@Initialize {
		SetLife(4000);
		SetInvincibility(120);
//		SetDamageRate(20, 10);
		SetTimer(36);
//		SetScore(222222);
//		SetDurableSpellCard;
//		CutIn(KOUMA, ""\""Whirlpool"\", "script\img\alexandaqua.png", 0, 0, 0, 0);

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

		SetMovePosition03(GetCenterX, GetClipMinY + 120, 10, 3);
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		if(frame%240 == 1) {
			BubbleBurst("CW");
		}
		else if(frame%120 == 1) {
			BubbleBurst("CCW");
		}
		if(frame%120 == 61) {
			if(mc%2 == 0) {
				SetMovePosition03(GetCenterX, GetClipMinY + 120, 10, 3);
			}
			else if(mc%4 == 1) {
				SetMovePosition03(GetCenterX + 60, GetClipMinY + 150, 10, 3);
			}
			else if(mc%4 == 3) {
				SetMovePosition03(GetCenterX - 60, GetClipMinY + 150, 10, 3);
			}
			mc++;
		}
		trig++;
		if(tm >= 2 || tm <= 0.5) {
			tmm *= -1;
		}
		tm += tmm;
		yield;
		frame++;
	}
	@DrawLoop {
		SetTexture(ImgBoss);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgBoss);
	}
	task BubbleBurst(param) {
		if(param == "CW") {
			ascent(b in 0..3) {
				ascent(a in 0..15) {
					CreateShot02(GetX + cos(b * 120 - 90) * 45, GetY + sin(b * 120 - 90) * 45, 2.5, a * 24 + frame%7 * (24 / 7), -0.01, 1.5, BLUE04, 20);
					if(a%2 == frame%7%2) {
						CreateShot01(GetX + cos(b * 120 - 90) * 45, GetY + sin(b * 120 - 90) * 45, 1, a * 24 + frame%7 * (24 / 7), AQUA03, 20);
					}
				}
				loop(20) { yield; }
			}
		}
			else {
				descent(b in 0..3) {
					ascent(a in 0..15) {
						CreateShot02(GetX + cos(b * 120 - 90) * 45, GetY + sin(b * 120 - 90) * 45, 2.5, a * 24 + frame%7 * (24 / 7), -0.01, 1.5, BLUE04, 20);
						if(a%2 == frame%7%2) {
							CreateShot01(GetX + cos(b * 120 - 90) * 45, GetY + sin(b * 120 - 90) * 45, 1, a * 24 + frame%7 * (24 / 7), AQUA03, 20);
						}
					}
				loop(20) { 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;
		}
	}
}