東方弾幕風
#Title[橙通常７狂]
#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(2600);
		StartSetting(35, 0, "");
		SetInvincibility(210);
		SetHitState(0);

		LoadGraphic(img_chen);

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

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

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

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

	@DrawLoop
	{
		if( (action == ACT_MOVE && absolute(GetSpeed()) >= 0.1) || action == ACT_MOVE_L || action == ACT_MOVE_R ){
			if( action == ACT_MOVE_R || 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() + 100);
		SetAction(ACT_MOVE, 60);
		Wait(180);
		SetHitState(1);

		T_Move();
		T_Shot();
	}

	task T_Move()
	{
		SetAction(ACT_MOVE_L, 12000);
		loop{
			MoveActOwn(90, 110);
			Wait(50);
		}
	}

	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(30, 50)));
		y = max(ymin, min(ymax, GetY() + rand(-30, 30)));
		SetMovePositionDC(x, y, 45);
	}

	task T_Shot()
	{
		let k = 1;
		loop{
			PlaySE(se_shot1);
			let angle = rand(0, 360);
			ascent( let i in 0..32 ){
				CreateStopShot(GetX(), GetY(), 2.6, angle + i * 360 / 32, k, 103);
				CreateStopShot(GetX(), GetY(), 1.6, angle + (i + 0.5) * 360 / 32, k, 104);
			}
			Wait(18);
			k = -k;
		}
	}

	task CreateStopShot(x, y, tv, angle, k, type)
	{
		let obj = Obj_Create(OBJ_SHOT);

		Obj_SetPosition(obj, x, y);
		ObjShot_SetGraphic(obj, type);
		Obj_SetAngle(obj, angle);

		let v = 6.0;
		let a1 = -v / 30;
		loop(30){
			v += a1;
			Obj_SetSpeed(obj, v);
			yield;
		}

		let v_angle = k * 1.5;
		let a_angle = -v_angle / 120;
		let a2 = tv / 120;

		loop(120){
			v += a2;
			angle += v_angle;
			v_angle += a_angle;
			Obj_SetSpeed(obj, v);
			Obj_SetAngle(obj, angle);
			yield;
		}
	}

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