#TouhouDanmakufu[Single]
#Title[Koishi - Spell #4]
#BackGround[User(.\bgNon.png, 0, 0)]
#BGM[.\music0.mp3]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {

	#include_function ".\Include.~ath"

	task codeInit {
		SetLife(10000); SetTimer(62);
		SetMovePosition03(GetCenterX, GetCenterY/2, 10, 4);
		cutin("Concept "\""Hardcoded Destiny"\",imgBossCut,0,0,255,511); SetScore(1000000);
		SetInvincibility(120);
		wait(120);
		attack1;
		attack2;
	}
	task attack1 {
		task DNA(let nX, let nY, let nSpeed, let nAngle, let nBullets, let nRadius, let nTwirl, let nTime, let nNum, let nGraphic, let nDelay) {
			let nDisplace = nAngle;
			let nDisplace2 = nAngle+rand(-30,30);
			loop(nBullets) {
				PlaySE2("se_shot_kira");
				ascent(i in 0..2) {
					let t = TiltXY(nDisplace+i*360/2, nAngle+90, nRadius, 0);
					ascent(j in 0..nNum) { CreateShot02(nX+t[0], nY+t[1], 0, nAngle+90+i*360/2+nDisplace2, (3/2+j/3)/90, 3/2+j/3, nGraphic, nDelay); }
				}
				nX+=nSpeed*cos(nAngle);
				nY+=nSpeed*sin(nAngle);
				nDisplace+=nTwirl;
				nDisplace2-=nTwirl/2;
				wait(nTime);
			}
		}
		function TiltXY(a1,a2,r1,r2) {
			let a3 = atan2(sin(a1)*r2,cos(a1)*r1)+a2;
			let r3 = ((cos(a1)*r1)^2+(sin(a1)*r2)^2)^0.5;
			return [cos(a3)*r3, sin(a3)*r3];
		}
		loop {
			DNA(GetClipMinX, GetClipMinY, 6, 25, 90, 30, 15, 1, 1, BLUE22, 10);
			wait(180);
			DNA(GetClipMaxX, GetClipMinY, 7, 155, 90, 30, -15, 1, 2, BLUE14, 10);
			wait(180);
		}
	}
	task attack2 {
		let angle = 0;
		let angleF = 0;
		task CreateLaser(off) {
			let obj = Obj_Create(OBJ_LASER);
			Obj_SetPosition(obj, GetX, GetY); ObjShot_SetGraphic(obj, RED11);
			ObjLaser_SetWidth(obj, 30); ObjLaser_SetSource(obj, false);
			let le = 0;
			loop {
				if(le < 1) { le+=1/90; }
				ObjLaser_SetLength(obj, 480*le);
				ObjShot_SetDelay(obj, 2);
				Obj_SetAngle(obj, angle+off*360/11);
				wait(1);
			}
		}
		task CreateHookedShot(off) {
			let obj = Obj_Create(OBJ_SHOT);
			ObjShot_SetBombResist(obj, true);
			ObjShot_SetGraphic(obj, YELLOW34);
			let r = 0; let ra = 0;
			while(!Obj_BeDeleted(obj)) {
				Obj_SetPosition(obj, GetX+r*cos(Obj_GetAngle(obj)), GetY+r*sin(Obj_GetAngle(obj)));
				wait(1);
				Obj_SetAngle(obj, angle+off*360/11);
				r+=ra; if(ra<10/pi) { ra+=(10/pi)/90; }
			}
		}
		ascent(i in 0..11) { CreateLaser(i); }
		loop {
			loop(20) { angle=60*sin(angleF); angleF+=4/(pi^2); angleF%=360; wait(1); }
			PlaySE2("se_shot_tan");
			ascent(i in 0..11) { CreateHookedShot(i); }
		}
	}
}