東方弾幕風
#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
	{
		SetLife(900);
		SetExMode();
		SetHitState(0);

		InitPosition(GetCenterX(), GetCenterY() - 60);

		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
	{
		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);
			}
		}
		CreateItem(ITEM_1UP, GetX(), GetY());
		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( 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;

		SetAction(ACT_MOVE, 60);
		Wait(60);
		StartSetting(60, 2000000, "誘符「奈落曳手」");
		SetInvincibility(150);
		T_DamageRate(20, 0, 360, -1);

		SetAction(ACT_SPELL, 60);

		Wait(120);
		SetHitState(1);

		T_Move();
	}

	task T_Move()
	{
		let k = 1;

		loop{
			PlaySE(se_concent);
			SetColor(255, 255, 255);
			Concentration01(90);
			SetColor(255, 255, 255);
			SetAction(ACT_MOVE, 90);
			SetMovePositionDC(GetCenterX(), GetCenterY() - 230, 90);
			Wait(90);

			let roletime = 240;
			let rx = 183;
			let ry = 170;
			let drx = rx / (roletime - 60);
			let dry = ry / (roletime - 60);
			let angle = -90;

			SetAction([ACT_MOVE_L, ACT_MOVE_R][k < 0], roletime);
			ascent( let n in 0..roletime ){
				SetX(GetCenterX() + rx * cos(angle));
				SetY(GetCenterY() + ry * sin(angle) - 60);
				angle += k * 4.7;
				if( n >= 60 ){
					rx -= drx;
					ry -= dry;
				}
				if( n % 3 == 0 && n < roletime ){
					PlaySE(se_shot1);
					SetShotColor(255, 255 - 200 * n / roletime, 255 - 200 * n / roletime);
					CreatePutShot(GetX(), GetY(), (roletime - n) * 2);
					SetShotColor(255, 255, 255);
					CreateShot02(GetX(), GetY(), 0.0, 90, 0.02, 1.0, 61, 0);
				}
				yield;
			}
			PlaySE(se_shot2);
			Wait(240);
			k = -k;
		}
	}

	task CreatePutShot(x, y, wait)
	{
		let obj = Obj_Create(OBJ_SHOT);

		Obj_SetPosition(obj, x, y);
		ObjShot_SetGraphic(obj, 41);

		Wait(wait);

		if( Obj_BeDeleted(obj) ){
			return;
		}

		let angle = GetSnipeAngle(x, y);
		ascent( let i in 0..5 ){
			CreateShot02(x, y, 0.0, angle + (i - 2) * 21, 0.08, 12.0, 207, 0);
		}
		Obj_Delete(obj);
	}

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