e
#Title[ʏR]
#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
	{
		StartPlural();

		SetLife(1400);
		StartSetting(30, 0, "");
		SetInvincibility(150);
		SetHitState(0);

		LoadGraphic(img_chen);

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

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

		T_Main();
		T_DamageRate(100, 100, 150, -1);
		T_HitTest(48);
	}

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

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

		Wait(60);
		InitPosition(GetCenterX(), GetClipMinY() + 120);
		SetAction(ACT_MOVE, 60);
		Wait(120);
		SetHitState(1);

		//T_Move();
		T_ShotA();
	}

	task T_Move()
	{
		Wait(80);
		loop{
			SetAction(ACT_MOVE, 60);
			MoveActOwn(100, 150);
			Wait(150);
		}
	}

	function MoveActOwn(ymin, ymax)
	{
		let x;
		let y;
		let k;
		let min_x = 100;
		let xmin = GetClipMinX() + min_x;
		let xmax = GetClipMaxX() - min_x;

		if( GetX() < xmin + 60 ){
			k = 1;
		}
		else if( GetX() > xmax - 60 ){
			k = -1;
		}
		else if( GetX() < GetPlayerX() ){
			k = 1;
		}
		else{
			k = -1;
		}
		x = max(xmin, min(xmax, GetX() + k * rand(70, 120)));
		y = max(ymin, min(ymax, GetY() + rand(-30, 30)));
		SetMovePositionDC(x, y, 60);
	}

	task T_ShotA()
	{
		loop{
			SetAction(ACT_MOVE, 60);
			SetMovePositionDC(GetClipMaxX() - rand(80, 100), GetClipMinY() + rand(80, 120), 60);
			ascent( let j in 0..12 ){
				PlaySE(se_shot1);
				ascent( let i in 0..25 ){
					CreatePutShotA(GetX(), GetY(), 7.0 - j * 6.0 / 12, i * 360 / 25);
				}
				Wait(4);
			}
			Wait(80);
			SetAction(ACT_MOVE, 60);
			SetMovePositionDC(GetClipMinX() + rand(80, 100), GetClipMinY() + rand(80, 120), 60);
			ascent( let j in 0..12 ){
				PlaySE(se_shot1);
				ascent( let i in 0..25 ){
					CreatePutShotA(GetX(), GetY(), 7.0 - j * 6.0 / 12, i * 360 / 25);
				}
				Wait(4);
			}
			Wait(80);
		}
	}

	task CreatePutShotA(x, y, tv, angle)
	{
		let obj = Obj_Create(OBJ_SHOT);

		Obj_SetPosition(obj, x, y);
		ObjShot_SetGraphic(obj, 47);
		//ObjShot_SetBombResist(obj, true);
		Wait(60);
		PlaySE(se_shot1);

		let s_angle = GetSnipeAngle(x, y) + angle;
		let v = 0.0;
		let a = tv / 60;

		Obj_SetAngle(obj, s_angle);

		loop(60){
			v += a;
			Obj_SetSpeed(obj, v);
			yield;
		}
	}

	task CreatePutShotB(x, y, tv, angle)
	{
		let obj = Obj_Create(OBJ_SHOT);

		Obj_SetPosition(obj, x, y);
		ObjShot_SetGraphic(obj, 43);
		Wait(60);
		PlaySE(se_shot1);

		let s_angle = angle;
		let v = 0.0;
		let a = tv / 60;

		Obj_SetAngle(obj, s_angle);

		loop(60){
			v += a;
			Obj_SetSpeed(obj, v);
			yield;
		}
	}

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