東方弾幕風
#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(3000);
		StartSetting(45, 0, "");
		SetInvincibility(150);
		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, 240, -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() + 80);
		SetAction(ACT_MOVE, 60);
		Wait(120);
		SetHitState(1);

		T_Move();
	}

	task T_Move()
	{
		let v;
		let a = (196 + 160) * 4 / (120 ^ 2);
		let angle = [55, 125];
		let warp_d = (80 + 160) / sin(angle[0]);
		let k = 0;

		loop{
			PlaySE(se_concent);
			SetColor(255, 255, 255);
			Concentration01(90);
			SetColor(255, 255, 255);
			Wait(90);

			SetAction(ACT_MOVE, 120 + 90);
			SetAngle(angle[k]);

			v = 0;
			let angle_s = rand(0, 360);
			let ks = 1 - 2 * k;
			ascent( let n in 0..120 ){
				v += a;
				SetSpeed(v);
				if( n % 10 == 5 ){
					PlaySE(se_shot1);
					ascent( let j in 0..3 ){
						let v = 1.1 + j * 0.3;
						ascent( let i in 0..25 ){
							CreateStopShot(GetX(), GetY(), v, angle_s + i * 360 / 25 + j * 4, ks, [102, 101, 107][j]);
						}
					}
					angle_s -= ks * 4.7;
				}
				yield;
			}
			SetX(GetCenterX() - warp_d * cos(angle[k]));
			SetY(GetClipMinY() + 80 - warp_d * sin(angle[k]));
			SetMovePositionDC(GetCenterX(), GetClipMinY() + 80, 90);
			Wait(60);
			k = 1 - k;
		}
	}

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

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

		let a = v / 50;
		loop(50){
			v -= a;
			Obj_SetSpeed(obj, v);
			yield;
		}
		Wait(30);

		PlaySE(se_shot2);
		ObjShot_SetGraphic(obj, type);

		let v_angle = k * 1;
		let a_angle = -v_angle / 60;

		loop(60){
			v += a;
			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"
}
