東方弾幕風
#Title[天上「大気圏ブルーオーシャン」]
#Text[]
#BackGround[DEFAULT]
#Player[FREE]
#ScriptVersion[2]

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

	@Initialize
	{
		StartPlural();

		SetLife(700);
		SetHitState(0);

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

		LoadGraphic(img_yukari);

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

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

		SetEffectForZeroLife(0, 0, 0);

		T_Main();
		T_HitTest(48);
	}

	@Finalize
	{
		PlaySE(se_destroy);
		if( GotSpellCardBonus() ){
			if( hypot(GetX() - GetPlayerX(), GetY() - GetPlayerY()) < 100 ){
				CreateItemCircle(GetX() - 40, GetY(), 40, 40);
				CreateItemCircle(GetX() + 40, GetY(), 40, 40);
			}
			else{
				CreateItemCircle(GetX(), GetY(), 40, 40);
			}
		}
		CreateItem(ITEM_1UP, GetX(), GetY());
		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(50, 2000000, "天上「大気圏ブルーオーシャン」");
		SetInvincibility(150);
		T_DamageRate(20, 20, 360, -1);

		SetAction(ACT_SPELL, 60);

		Wait(150);
		SetHitState(1);

		T_Cloud1();
		T_Cloud2();
		T_Star();
		T_Move();
	}

	function MoveActOwn(ymin, ymax)
	{
		let x;
		let y;
		let k;
		let min_x = 100;
		let xmin = GetClipMinX() + min_x;
		let xmax = GetClipMaxX() - min_x;

		if( GetX() < xmin + 60 ){
			k = 1;
		}
		else if( GetX() > xmax - 60 ){
			k = -1;
		}
		else if( GetX() < GetPlayerX() ){
			k = 1;
		}
		else{
			k = -1;
		}
		x = max(xmin, min(xmax, GetX() + k * rand(35, 60)));
		y = max(ymin, min(ymax, GetY() + rand(-30, 30)));
		SetMovePositionDC(x, y, 60);
	}

	task T_Move()
	{
		Wait(120);
		loop{
			SetAction(ACT_MOVE, 60);
			MoveActOwn(GetClipMinY() + 50, GetClipMinY() + 60);
			Wait(150);
		}
	}

	task T_Cloud1()
	{
		Wait(180);
		loop{
			PlaySE(se_shot1);
			CreateFallShot();
			Wait(30);
		}
	}

	task T_Cloud2()
	{
		loop{
			SetShotColor(128, 128, 128);
			CreateShot01(GetClipMinX() - 48, GetClipMaxY() - 10 + rand(-10, 10), 1.5,   0, 196, 0);
			CreateShot01(GetClipMaxX() + 48, GetClipMaxY() - 35 + rand(-10, 10), 1.5, 180, 196, 0);
			CreateShot01(GetClipMinX() - 48, GetClipMaxY() - 60 + rand(-10, 10), 1.5,   0, 198, 0);
			CreateShot01(GetClipMaxX() + 48, GetClipMaxY() - 85 + rand(-10, 10), 1.5, 180, 198, 0);
			SetShotColor(255, 255, 255);
			Wait(35);
		}
	}

	task T_Star()
	{
		let k = 0;
		loop{
			PlaySE(se_shot2);
			let n = 11;
			let dy = (GetClipMaxY() - 32 - GetClipMinY()) / (n - 1);
			let x = [GetClipMinX() - 24, GetClipMaxX() + 24][k];
			let y = GetClipMinY() - 96 + rand(0, dy);
			ascent( let i in 0..n ){
				CreateShot01(x, y, 1.8, [15, 165][k], [153, 154][k], 0);
				y += dy;
			}
			Wait(35);
			k = 1 - k;
		}
	}

	task CreateFallShot()
	{
		SetShotColor(192, 192, 192);
		let obj = Obj_Create(OBJ_SHOT);
		SetShotColor(255, 255, 255);

		Obj_SetPosition(obj, GetPlayerX(), GetClipMaxY() + 48);
		Obj_SetAngle(obj, -90);
		ObjShot_SetGraphic(obj, 195);

		let v = 5.2;
		let a = -v / 180;

		while( !Obj_BeDeleted(obj) ){
			v += a;
			Obj_SetSpeed(obj, v);
			yield;
		}
	}

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