e
#Title[\u֋v]
#Text[]
#BackGround[DEFAULT]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"
	#include_function ".\lib\lib_anime_Chen.txt"

	let draw_rot = 0;

	@Initialize
	{
		SetLife(450);
		SetExMode();
		SetHitState(0);

		InitPosition(GetCenterX(), GetClipMinY() + 100);

		LoadGraphic(img_chen);

		LoadUserShotData(shot_00);
		SetShotAutoDeleteClip(24, 24, 24, 24);

		InitializeAction();
		InitializeBG();
		LoadSE(se_shot1);
		LoadSE(se_shot2);

		T_Main();
		T_HitTest(48);
	}

	@Finalize
	{
		if( GotSpellCardBonus() ){
			if( hypot(GetX() - GetPlayerX(), GetY() - GetPlayerY()) < 100 ){
				CreateItemCircle(GetX() - 40, GetY(), 20, 40);
				CreateItemCircle(GetX() + 40, GetY(), 20, 40);
			}
			else{
				CreateItemCircle(GetX(), GetY(), 20, 40);
			}
		}
		DeleteGraphic(img_chen);
		DeleteSE(se_shot1);
		DeleteSE(se_shot2);
		ClearBG();
	}

	@DrawLoop
	{
		if( action == ACT_MOVE && absolute(GetSpeed()) >= 0.1 ){
			if( cos( GetAngle() ) <= 0 ){
				draw_rot -= 30;
			}
			else{
				draw_rot += 30;
			}
		}
		else{
			draw_rot = 0;
		}
		SetGraphicAngle(0, 0, draw_rot);
		SetAlpha([255, 128][IsExMode() && OnBomb()]);
		DrawBoss(img_chen);
		SetGraphicAngle(0, 0, 0);
	}

	task T_Main()
	{
		yield;

		SetAction(ACT_MOVE, 60);
		Wait(60);
		StartSetting(60, 2000000, "\u֋v");
		SetInvincibility(150);
		T_DamageRate(20, 0, 240, -1);

		SetAction(ACT_SPELL, 60);

		Wait(120);
		SetHitState(1);

		T_Move();
		T_Winder();
		T_Circle();
	}

	task T_Move()
	{
		Wait(80);
		loop{
			SetAction(ACT_MOVE, 60);
			SetMovePositionDC(GetClipMinX() + rand(120, 135), GetClipMinY() + rand(90, 110), 60);
			Wait(100);
			SetAction(ACT_MOVE, 60);
			SetMovePositionDC(GetClipMaxX() - rand(120, 135), GetClipMinY() + rand(90, 110), 60);
			Wait(100);
		}
	}

	task T_Winder()
	{
		let count = -40;
		let width = 300;
		let way = 13;

		loop{
			let v_angle = 6 * sin(count * 18.5);

			if( count < 0 ){
				width -= (300 - 40) / 40;
			}
			PlaySE(se_shot1);
			ascent( let i in 0..way ){
				let angle = 90 + width / 2 + v_angle + i * (360 - width) / (way - 1);
				CreateShot02(GetX() + 40 * cos(angle), GetY() + 40 * sin(angle), 5.6, angle, 0, 0, 87, 6);
			}
			Wait(2);
			count ++;
			if( OnPlayerMissed() || OnBomb() ){
				loop{
					if( !OnPlayerMissed() && !OnBomb() ){
						count = -40;
						width = 300;
						break;
					}
					yield;
				}
			}
		}
	}

	task T_Circle()
	{
		loop{
			let angle = rand(0, 360);
			PlaySE(se_shot2);
			ascent( let j in 0..17 ){
				ascent( let i in 0..7 ){
					CreateShot02(GetX(), GetY(), 1.5, angle + i * 2.0 + j * 360 / 17, 0.020, 2.2, 201, 0);
				}
			}
			Wait(70);
		}
	}

	#include_function ".\f_base.txt"
	#include_function ".\f_enemy.txt"
	#include_function ".\f_boss.txt"
	#include_function ".\f_bg_chen.txt"
}
