e
#Title[WʏP]
#Text[]
#BackGround[DEFAULT]
#Player[FREE]
#ScriptVersion[2]

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

	@Initialize
	{
		StartPlural();

		SetLife(1800);
		StartSetting(30, 0, "");
		SetInvincibility(120);

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

		LoadGraphic(img_range);

		LoadUserShotData(shot_00);
		SetShotAutoDeleteClip(16, 16, 16, 16);

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

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

	@Finalize
	{
		DeleteGraphic(img_range);
		DeleteSE(se_shot2);
		ClearBG();
	}

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

	task T_Main()
	{
		yield;

		Wait(120);
		SetColor(255, 128, 0);
		Concentration01(30);
		SetColor(255, 255, 255);
		Wait(30);

		T_Circle();
	}

	task T_Circle()
	{
		loop{
			SetAction(ACT_SHOT_B, 60);
			let angle = rand(0, 360);
			PlaySE(se_shot2);
			ascent( let i in 0..16 ){
				CreateCircle(GetX(), GetY(), angle, [12, 13][i % 2]);
				angle += 360 / 16;
			}
			Wait(200);
		}
	}

	task CreateCircle(x, y, angle, type)
	{
		let obj_s = [];
		let n = 15;

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

		let v = 3.4;
		let vx = v * cos(angle);
		let vy = v * sin(angle);
		let ax = -vx / 60 * 2.4 / 3.4;
		let ay = -vy / 60 * 2.4 / 3.4;
		let r = 0;
		let dr = 2.3;
		let ddr = -2.3 / 60;
		let angle_s = rand(0, 360);
		let count = 0;

		loop{
			x += vx;
			y += vy;
			r += dr;
			if( count < 60 ){
				vx += ax;
				vy += ay;
				dr += ddr;
			}

			if( IsOutOfClipRange(x, y, r + 16) ){
				ascent( let i in 0..n ){
					Obj_Delete(obj_s[i]);
				}
				break;
			}

			ascent( let i in 0..n ){
				let angle_st = angle_s + i * 360 / n;
				Obj_SetPosition(obj_s[i], x + r * cos(angle_st), y + r * sin(angle_st));
			}
			angle_s -= 0.8;

			count ++;
			yield;
		}
	}

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