
script_enemy_main
{
	#include_function ".\init.txt"

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

		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(), 5, 10);
				CreateItemCircle(GetX() + 16, GetY(), 5, 10);
			}
			else{
				CreateItemCircle(GetX(), GetY(), 5, 10);
			}
			if( GetArgument()[1] ){
				CreateItem(ITEM_1UP, GetX(), GetY());
			}
		}
	}

	@DrawLoop
	{
		DrawGraphic(GetX(), GetY());
	}

	task T_Main()
	{
		yield;

		T_Move();
		T_Shot();

		Wait(30);

		loop{
			if( IsOutOfClipRange(GetX(), GetY(), 32) ){
				VanishEnemy();
			}
			yield;
		}
	}

	task T_Move()
	{
		let arg = GetArgument();
		let x = GetX();
		let y = GetY();
		let vx = arg[0] * 0.6;
		let vy = 4.0;
		let ax = 0.0;
		let ay = -vy / 90;

		ascent( let i in 0..600 ){
			if( i == 80 ){
				ay = -0.01;
			}
			if( i == 150 ){
				ax = 0.05 * cos(GetAngle());
				ay = 0.05 * sin(GetAngle());
			}
			x += vx;
			y += vy;
			vx += ax;
			vy += ay;
			SetSpeed(hypot(vy, vx));
			SetAngle(atan2(vy, vx));
			yield;
		}
	}

	task T_Shot()
	{
		let arg = GetArgument();
		let angle = 90 - arg[0] * 10;

		Wait(5);
		loop(9){
			ascent( let j in 0..8 ){
				PlaySE(se_shot1);
				let v = 3.5 + j * 0.2;
				ascent( let i in 0..4 ){
					CreateShot01(GetX(), GetY(), v, angle + i * 90, [103, 107][arg[1]], 0);
				}
				angle -= arg[0] * 2.3;
				Wait(2);
			}
		}
	}

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