#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"

	@Initialize
	{
		SetLife(140);
		SetScore(15000);

		SetTexture(img_fairy);

		LoadUserShotData(shot_00);

		InitializeAction();
		SetFairyType(5);

		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 v = GetSpeed();
		let a = -v / 40;
		loop(40){
			v += a;
			SetSpeed(v);
			yield;
		}
		Wait(240);
		let v = GetSpeed();
		let angle = GetAngle();
		let vx = v * cos(angle);
		let vy = v * sin(angle);
		let ax = 0.04;
		let ay = -0.1;

		if( GetX() < GetCenterX() ){
			ax = -ax;
		}

		loop{
			vx += ax;
			vy += ay;
			SetSpeed(hypot(vy, vx));
			SetAngle(atan2(vy, vx));
			yield;
		}
	}

	task T_Shot()
	{
		Wait(5);
		let angle = 0;
		ascent( let i in 0..24 ){
			PlaySE(se_shot1);
			CreateShot02(GetX(), GetY(), 3.0, GetAngleToPlayer(), 0.1, 10.0, 97, 0);
			Wait(10);
		}
	}

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