東方弾幕風
#Title[輪符「星環結界」]
#Text[]
#BackGround[DEFAULT]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"
	#include_function ".\lib\lib_anime_Yukari.txt"

	@Initialize
	{
		SetLife(900);
		SetHitState(0);

		InitPosition(GetCenterX(), GetClipMinY() + 150);

		LoadGraphic(img_yukari);

		LoadUserShotData(shot_00);
		SetShotAutoDeleteClip(128, 64, 128, 64);

		InitializeAction();
		InitializeBG();
		DeleteEnemyShot(ALL);
		LoadSE(se_shot1);
		LoadSE(se_shot2);

		T_Main();
		T_HitTest(48);
	}

	@Finalize
	{
		if( GotSpellCardBonus() ){
			if( hypot(GetX() - GetPlayerX(), GetY() - GetPlayerY()) < 100 ){
				CreateItemCircle(GetX() - 40, GetY(), 20, 40);
				CreateItemCircle(GetX() + 40, GetY(), 20, 40);
			}
			else{
				CreateItemCircle(GetX(), GetY(), 20, 40);
			}
		}
		DeleteGraphic(img_yukari);
		DeleteSE(se_shot1);
		DeleteSE(se_shot2);
		ClearBG();
	}

	@DrawLoop
	{
		SetAlpha([255, 128][IsExMode() && OnBomb()]);
		DrawBoss(img_yukari);
	}

	task T_Main()
	{
		yield;

		SetAction(ACT_MOVE, 60);
		Wait(60);
		StartSetting(45, 2000000, "輪符「星環結界」");
		SetInvincibility(150);
		T_DamageRate(20, 20, 300, -1);

		SetAction(ACT_SPELL, 60);

		Wait(150);
		SetHitState(1);

		T_Circle();
	}

	task T_Circle()
	{
		SetAction(ACT_SHOT_B, 90);
		CreateCircle(GetX(), GetY(), 1.00,  1, 17, 1.5, 194);
		Wait(180);
		SetAction(ACT_SHOT_B, 90);
		CreateCircle(GetX(), GetY(), 1.00, -1, 17, 1.5, 197);
		Wait(150);
		loop{
			SetAction(ACT_SHOT_B, 90);
			CreateCircle(GetX(), GetY(), 0.90,  1, 40, 2.4, 5);
			CreateCircle(GetX(), GetY(), 1.10,  1, 17, 1.5, 194);
			Wait(120);
			SetAction(ACT_SHOT_B, 90);
			CreateCircle(GetX(), GetY(), 0.90, -1, 40, 2.4, 1);
			CreateCircle(GetX(), GetY(), 1.10, -1, 17, 1.5, 197);
			Wait(120);
		}
	}

	task CreateCircle(cx, cy, db, k, n, dr, type)
	{
		PlaySE(se_shot2);

		let obj = [];
		let wh_rate = 0.8;

		ascent( let i in 0..n ){
			obj = obj ~ [Obj_Create(OBJ_SHOT)];
			ObjShot_SetGraphic(obj[i], type);
		}

		let r = 0;
		//let dr = 2.0;
		let b_angle = rand(0, 360);
		let c_angle = -30;
		let i_angle = 360 / n;
		let db_angle = db * k;
		let dc_angle = 0;

		loop{
			c_angle += dc_angle;
			b_angle += db_angle;
			r += dr;

			let rw = r;
			let rh = r * wh_rate;
			let x;
			let y;
			let f_exit = 1;

			ascent( let i in 0..n ){
				if( !Obj_BeDeleted(obj[i]) ){
					f_exit = 0;
					x = rw * cos(b_angle + i * i_angle);
					y = rh * sin(b_angle + i * i_angle);
					Obj_SetPosition(obj[i], cx + GetRotateX(x, y, c_angle), cy + GetRotateY(x, y, c_angle));
				}
			}
			if( f_exit ){
				break;
			}
			yield;
		}
	}

	#include_function ".\f_base.txt"
	#include_function ".\f_enemy.txt"
	#include_function ".\f_boss.txt"
	#include_function ".\f_bg_yukari.txt"
}
