#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"

	let f_item = 1;

	@Initialize
	{
		SetLife(30);
		SetScore(5000);

		SetTexture(img_fairy);

		LoadUserShotData(shot_00);

		InitializeAction();
		SetFairyType(1);

		T_Main();
		T_HitTest(16);
	}

	@Finalize
	{
		if( GetLife() <= 0 ){
			if( f_item ){
				if( hypot(GetX() - GetPlayerX(), GetY() - GetPlayerY()) < 100 ){
					CreateItemCircle(GetX() - 8, GetY(), 1, 0);
					CreateItemCircle(GetX() + 8, GetY(), 1, 0);
				}
				else{
					CreateItemCircle(GetX(), GetY(), 1, 0);
				}
			}
			PlaySE(se_shot1);
			let angle = GetAngleToPlayer();
			ascent( let i in 0..6 ){
				CreateShot02(GetX(), GetY(), 0.0, angle + i * 360 / 6, 0.05, 10.0, 15, 0);
			}
		}
	}

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

	task T_Main()
	{
		yield;

		T_Move();
		//T_Shot();
		Wait(20);

		loop{
			if( IsOutOfClipRange(GetX(), GetY(), -4) ){
				f_item = 0;
				SetLife(0);
			}
			yield;
		}
	}

	task T_Move()
	{
		let v = 2.0;
		let angle = GetAngleToPlayer();

		loop(300){
			v += 0.08;
			angle = GetHomingAngle(GetX(), GetY(), angle, 3.0 / v);
			SetSpeed(v);
			SetAngle(angle);
			yield;
		}
		f_item = 0;
		SetLife(0);
	}

	task T_Shot()
	{
		loop(10){
			Wait(15);
			PlaySE(se_shot1);
			CreateShot02(GetX(), GetY(), 0.0, GetAngleToPlayer(), 0.05, 10.0, 42, 0);
			Wait(30);
		}
	}

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