#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"

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

		SetTexture(img_fairy);

		LoadUserShotData(shot_00);

		InitializeAction();
		SetFairyType(4);

		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(40);
		let angle = 90;
		ascent( let i in 0..16 ){
			PlaySE(se_shot1);
			ascent( let j in 0..12 ){
				let angle_s = angle + j * 360 / 12;
				ascent( let k in 0..3 ){
					let v = [1.8, 2.0, 2.2][k];
					CreateShot02(GetX(), GetY(), v, angle_s, v / 100, 20.0, [41, 11, 1][k], 0);
				}
			}
			Wait(15);
			angle += 11.3;
		}
	}

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