e
#Title[uŏI` -|̂˂p`-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(1500);
		SetExMode();
		SetHitState(0);

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

		LoadGraphic(img_chen);

		LoadUserShotData(shot_00);
		SetShotAutoDeleteClip(64, 64, 64, 64);

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

		T_Main();
		T_HitTest(48);
	}

	@Finalize
	{
		DeleteGraphic(img_chen);
		DeleteSE(se_shot1);
		DeleteSE(se_shot2);
		ClearBG();
	}

	@DrawLoop
	{
		if( (action == ACT_MOVE && absolute(GetSpeed()) >= 0.1) || action == ACT_MOVE_L || action == ACT_MOVE_R ){
			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(150, 3000000, "uŏI` -|̂˂p`-v");
		SetInvincibility(150);
		T_DamageRate(20, 0, 720, -1);

		SetEffectForZeroLife(60, 210, 2);

		Wait(120);
		SetHitState(1);

		T_Shot();
		T_Claw();
		T_Snipe();
		T_ShotB();
		T_ClawB();
		T_SnipeB();

		loop{
			if( GetTimer() == 30 ){
				DeleteEnemyShotToItem(ALL);
			}
			if( GetEnemyLife() <= 0 || GetTimer() <= -1 ){
				SetPlayerInvincibility(65);
				ForbidBomb(true);
				break;
			}
			yield;
		}
		PlaySE(se_destroy2);
		Wait(20);
		PlaySE(se_destroy2);
		Wait(20);
		PlaySE(se_destroy2);
		Wait(19);
		PlaySE(se_destroy);
	}

	task T_Shot()
	{
		let wait = 50;

		loop{
			PlaySE(se_shot1);
			let angle = rand(0, 360);
			ascent( let i in 0..40 ){
				CreateShot02(GetX(), GetY(), 10.0, angle + i * 360 / 40, -0.5, 3.2, 11, 0);
			}

			if( GetLife() < 300 ){
				wait = 25;
			}
			else if( GetLife() < 600 ){
				wait = 27;
			}
			else if( GetLife() < 1000 ){
				wait = 33;
			}
			else if( GetLife() < 1300 ){
				wait = 40;
			}
			loop(wait){
				if( GetTimer() <= 31 ){
					return;
				}
				yield;
			}
		}
	}

	task T_Claw()
	{
		Wait(180);

		let wait = 180;

		loop{
			CreateClaw();
			Wait(120);

			if( GetLife() < 300 ){
				wait = 40;
			}
			else if( GetLife() < 600 ){
				wait = 60;
			}
			else if( GetLife() < 1000 ){
				wait = 80;
			}
			else if( GetLife() < 1300 ){
				wait = 120;
			}
			loop(wait){
				if( GetTimer() <= 31 ){
					return;
				}
				yield;
			}
		}
	}

	task T_Snipe()
	{
		let wait = 20;
		loop{
			if( GetLife() < 800 ){
				PlaySE(se_shot1);
				CreateShot01(GetX(), GetY(), 5.0, GetAngleToPlayer(), 47, 0);
			}
			if( GetLife() < 450 ){
				wait = 10;
			}
			loop(wait){
				if( GetTimer() <= 31 ){
					return;
				}
				yield;
			}
		}
	}

	task CreateClaw()
	{
		SetAction(ACT_SHOT_B, 120);
		PlaySE(se_concent);
		Concentration01(120);
		Concentration01(120);
		Wait(120);
		PlaySE(se_shot2);
		SetAction(ACT_MOVE_L, 30);

		let angle = GetAngleToPlayer();
		let w = 32;
		ascent( let i in 0..(w * 2 + 1) ){
			let v;
			if( i >= w - 5 && i <= w + 5 ){
				v = 5.5 - 1.0 * abs(i - w) / 5;
			}
			else if( i >= w - 9 && i <= w + 9 ){
				v = 4.5 + 0.9 * (abs(i - w) - 5) / 4;
			}
			else{
				v = 5.4 - 4.6 * (abs(i - w) - 9) / (w - 9);
			}
			CreateShot01(GetX(), GetY(), v, angle + (i - w) * 0.8, 104, 0);
		}
	}

	task T_ShotB()
	{
		loop{
			if( GetTimer() <= 29 ){
				SetAction(ACT_MOVE_L, 6000);
				break;
			}
			yield;
		}

		loop{
			PlaySE(se_shot1);
			let angle = rand(0, 360);
			ascent( let i in 0..40 ){
				CreateShot02(GetX(), GetY(), 10.0, angle + i * 360 / 40, -0.5, 3.5, 11, 0);
			}
			Wait(20);
		}
	}

	task T_ClawB()
	{
		loop{
			if( GetTimer() <= 29 ){
				break;
			}
			yield;
		}

		loop{
			CreateClaw();
			Wait(120);
		}
	}

	task T_SnipeB()
	{
		loop{
			if( GetTimer() <= 29 ){
				break;
			}
			yield;
		}

		loop{
			PlaySE(se_shot1);
			CreateShot01(GetX(), GetY(), 5.5, GetAngleToPlayer(), 47, 0);
			Wait(10);
		}
	}

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