#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"

	@Initialize
	{
		SetLife(180);
		SetScore(30000);

		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(), 3, 10);
				CreateItemCircle(GetX() + 16, GetY(), 3, 10);
			}
			else{
				CreateItemCircle(GetX(), GetY(), 3, 10);
			}
		}
	}

	@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 angle = GetAngle();
		let v = GetSpeed();
		let a = -v / 60;
		let d_angle = 2.0;
		if( GetX() < GetCenterX() ){
			d_angle *= -1;
		}
		ascent( let i in 0..60 ){
			if( i >= 20 ){
				angle += d_angle;
			}
			v += a;
			SetAngle(angle);
			SetSpeed(v);
			yield;
		}
		Wait(180);
		if( GetX() < GetCenterX() ){
			SetAngle(-110);
		}
		else{
			SetAngle(-70);
		}
		a = 0.07;
		loop(60){
			v += a;
			SetSpeed(v);
			yield;
		}
	}

	task T_Shot()
	{
		Wait(60);

		loop(10){
			PlaySE(se_shot2);
			CreateShot02(GetX(), GetY(), 3.0, GetAngleToPlayer(), 0.07, 10.0, 178, 0);
			Wait(30);
		}
	}

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