#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"

	@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);
			}
		}
	}

	@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 / 30;
		loop(30){
			v += a;
			SetSpeed(v);
			yield;
		}
		Wait(300);
		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 wid = 0;
		let angle = 0;
		ascent( let i in 0..90 ){
			PlaySE(se_shot1);
			CreateShot02(GetX(), GetY(), 3.0, 90 + wid * sin(angle + rand(-15, 15)), 0.1, 10.0, 206, 0);
			Wait(4);
			angle = (angle + 40) % 360;
			wid += 0.6;
		}
	}

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