#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(0);

		T_Main();
		T_HitTest(16);
	}

	@Finalize
	{
		if( GetLife() <= 0 && 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);
			}
		}
	}

	@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 = 2.6;
		let angle = GetAngleToPlayer();

		SetSpeed(v);

		loop(300){
			angle = GetHomingAngle(GetX(), GetY(), angle, 1.3);
			SetAngle(angle);
			yield;
		}
		f_item = 0;
		SetLife(0);
	}

	task T_Shot()
	{
		loop(5){
			Wait(30);
			PlaySE(se_shot1);
			CreateShot02(GetX(), GetY(), 3.0, GetAngleToPlayer(), 0.0, 10.0, 14, 0);
			Wait(30);
		}
	}

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