#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"

	@Initialize
	{
		SetLife(360);

		SetTexture(img_fairy);

		LoadUserShotData(shot_00);

		InitializeAction();
		SetFairyType(3);

		T_Main();
		T_HitTest(32);
	}

	@Finalize
	{
		if( GetLife() <= 0 ){
			CreateItemCircle(GetX(), GetY(), 5, 8);
		}
	}

	@DrawLoop
	{
		DrawGraphic(GetX(), GetY());
	}

	task T_Main()
	{
		yield;

		T_Move();
		T_Shot();
		Wait(10);

		loop{
			if( IsOutOfClipRange(GetX(), GetY(), 16) ){
				VanishEnemy();
			}
			yield;
		}
	}

	task T_Move()
	{
		let v = GetSpeed();
		let a = -v / 40;
		loop(40){
			v += a;
			SetSpeed(v);
			yield;
		}
		Wait(160);
		if( GetX() < GetCenterX() ){
			SetAngle(-110);
		}
		else{
			SetAngle(-70);
		}
		a = 0.07;
		loop(60){
			v += a;
			SetSpeed(v);
			yield;
		}
	}

	task T_Shot()
	{
		Wait(40);
		loop(8){
			PlaySE(se_shot1);
			let angle = rand(0, 360);
			ascent( let i in 0..72 ){
				CreateShotA(0, GetX(), GetY(), 0);
				SetShotDataA(0, 0, 9.0, angle, 0, -0.3, 0, 85);
				SetShotDataA(0, 30, rand(2.4, 2.7), angle + rand(-3, 3), 0, 0, 0, 8);
				FireShot(0);
				T_Shot_Wave();
				angle += 360 / 72;
			}
			Wait(20);
		}
	}

	task T_Shot_Wave()
	{
		Wait(30);
		PlaySE(se_shot2);
	}

	#include_function ".\f_base.txt"
	#include_function ".\f_enemy.txt"
	#include_function ".\f_anime_fairy.txt"
}
