#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"

	@Initialize
	{
		SetLife(9999);
		T_Main();
	}

	@Finalize
	{
	}

	@DrawLoop
	{
	}

	@MainLoop
	{
		yield;
	}

	task T_Main()
	{
		CreateChain(GetX(), GetY(), GetAngleToPlayer());
		Wait(360);
		VanishEnemy();
	}

	task CreateChain(x, y, angle)
	{
		PlaySE(se_shot1);

		let cr = 40;
		x += cr * cos(angle);
		y += cr * sin(angle);

		let r1 = 50;
		let r2 = 25;
		let n = 36;
		angle += 180;
		ascent( let i in 0..n ){
			ascent( let j in 0..2 ){
				let s_angle = (i + 0.5) * (j - 0.5) * 360 / n;
				let b_sx = r1 * cos(s_angle);
				let b_sy = r2 * sin(s_angle);
				let sx = x + GetRotateX(b_sx, b_sy, angle);
				let sy = y + GetRotateY(b_sx, b_sy, angle);
				CreateChainShot(sx, sy, angle + s_angle, i % 3 == 1);
			}
			Wait(1);
		}
		angle -= 180;
		let cx = x + cr * cos(angle);
		let cy = y + cr * sin(angle);
		let c_angle = angle;
		if( !IsOutOfClipRange(cx, cy, 24)){
			CreateChain(cx, cy, c_angle);
		}
	}

	task CreateChainShot(x, y, angle, f_exp)
	{
		CreateShotA(0, x, y, 0);
		SetShotDataA(0,  0, 0.0, angle, 0, 0, 0, 205);
		if( f_exp ){
			SetShotDataA(0, 60, 0.0, angle, 0, 3.0 / 60, 3.0, 206);
		}
		else{
			SetShotKillTime(0, 60);
		}
		FireShot(0);
	}

	#include_function ".\f_base.txt"
}
