#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"

	let sub_id = -1;

	@Initialize
	{
		SetLife(500);
		SetScore(50000);

		SetTexture(img_fairy);

		LoadUserShotData(shot_00);

		InitializeAction();
		SetFairyType(3);

		T_Main();
		T_HitTest(32);
	}

	@Finalize
	{
		if( GetLife() <= 0 ){
			if( hypot(GetX() - GetPlayerX(), GetY() - GetPlayerY()) < 100 ){
				CreateItemCircle(GetX() - 16, GetY(), 5, 10);
				CreateItemCircle(GetX() + 16, GetY(), 5, 10);
			}
			else{
				CreateItemCircle(GetX(), GetY(), 5, 10);
			}
		}
		if( sub_id >= 0 ){
			ExitSubEnemy(sub_id);
		}
	}

	@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 / 100;
		loop(120){
			v += a;
			SetSpeed(v);
			yield;
		}
		Wait(150);
		a = -0.1;
		loop(60){
			v += a;
			SetSpeed(v);
			yield;
		}
	}

	task T_Shot()
	{
		Wait(10);
		sub_id = CreateSubEnemy(GetX(), GetY(), 0);

		let label = ToString(sub_id);
		loop{
			SetCommonData("sub_x" ~ label, GetX());
			SetCommonData("sub_y" ~ label, GetY());
			yield;
		}
	}

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