e
#Title[u։̘Sv]
#Text[]
#BackGround[DEFAULT]
#Player[FREE]
#ScriptVersion[2]

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

	@Initialize
	{
		SetLife(650);
		StartSetting(50, 1000000, "u։̘Sv");
		SetInvincibility(240);
		SetExMode();
		SetHitState(0);

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

		LoadGraphic(img_range);

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

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

		T_Main();
		T_DamageRate(20, 20, 360, -1);
		T_HitTest(48);
	}

	@Finalize
	{
		CreateItemCircle(GetX(), GetY(), 20, 50);
		DeleteGraphic(img_range);
		DeleteSE(se_shot1);
		DeleteSE(se_shot2);
		ClearBG();
	}

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

	task T_Main()
	{
		yield;

		SetAction(ACT_SPELL, 60);

		Wait(120);
		SetHitState(1);

		T_Circle();
	}

	task T_Circle()
	{
		PlaySE(se_shot1);
		SetAction(ACT_SHOT_B, 60);
		ascent( let i in 0..18 ){
			CreateFrameShot(GetX(), GetY(), -90 + i * 20, 90, 0);
		}
		Wait(60);
		PlaySE(se_shot1);
		SetAction(ACT_SHOT_B, 30);
		ascent( let i in 0..18 ){
			CreateFrameShot(GetX(), GetY(), i * 20, 30, i == 0 || i == 9);
		}
		Wait(30);
		SetAction(ACT_MOVE, 30);
		SetMovePosition02(GetCenterX(), GetClipMinY() + 80, 30);
		let r = 220;
		let v = 1.0;
		let count = 0;
	}

	task CreateFrameShot(x, y, angle, wait, f_shot)
	{
		let obj = Obj_Create(OBJ_SHOT);

		let r = 210;
		let tx = GetCenterX() + r * cos(angle);
		let ty = GetCenterY() + r * sin(angle);
		let t_angle = atan2(ty - y, tx - x);
		let v = hypot(ty - y, tx - x) * 2 / 120;
		let a = -v / 120;
		v += a / 2;

		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, t_angle);
		ObjShot_SetGraphic(obj, [198, 196][f_shot]);
		ObjShot_SetBombResist(obj, true);
		Obj_SetAutoDelete(obj, false);

		loop(120){
			Obj_SetSpeed(obj, v);
			v += a;
			yield;
		}

		Obj_SetAngle(obj, angle);
		Wait(wait);
		if( f_shot ){
			FrameShot_ShotTask(obj);
		}
		let d_angle = 0;
		loop{
			Obj_SetPosition(obj, GetCenterX() + r * cos(angle), GetCenterY() + r * sin(angle));
			Obj_SetAngle(obj, angle);
			angle -= d_angle;
			if( d_angle < 0.4 ){
				d_angle += 0.02;
			}
			yield;
		}
	}

	task FrameShot_ShotTask(obj)
	{
		Wait(30);
		loop{
			let x = Obj_GetX(obj);
			let y = Obj_GetY(obj);
			PlaySE(se_shot1);
			CreateCircle(x, y);
			Wait(60);
		}
	}

	task CreateCircle(cx, cy)
	{
		let angle = rand(0, 360);

		ascent( let i in 0..48 ){
			CreateCircleShot(cx, cy, angle, [8, 66][i % 2]);
			angle += 360 / 48;
		}
	}

	task CreateCircleShot(x, y, angle, type)
	{
		let obj = Obj_Create(OBJ_SHOT);

		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, type);

		let v = 3.4;
		let a = -v / 60;
		loop(60){
			v += a;
			Obj_SetSpeed(obj, v);
			yield;
		}
		Wait(60);

		Obj_SetAngle(obj, GetSnipeAngle(Obj_GetX(obj), Obj_GetY(obj)));
		Obj_SetSpeed(obj, 2.0);
	}

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