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

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

		LoadGraphic(img_chen);
		LoadGraphic(img_magic);

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

		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(), 40, 40);
				CreateItemCircle(GetX() + 40, GetY(), 40, 40);
			}
			else{
				CreateItemCircle(GetX(), GetY(), 40, 40);
			}
		}
		DeleteGraphic(img_chen);
		DeleteGraphic(img_magic);
		DeleteSE(se_shot1);
		DeleteSE(se_shot2);
		ClearBG();
	}

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

		SetAction(ACT_MOVE, 60);
		Wait(60);
		StartSetting(80, 3000000, "翼符「かわいい悪魔降臨」");
		SetInvincibility(150);
		T_DamageRate(20, 0, 360, -1);

		SetAction(ACT_SPELL, 60);

		Wait(120);
		SetHitState(1);
		SetAction(ACT_SHOT_B, 9999);

		PlaySE(se_concent);
		Concentration01(120);
		SetColor(64, 64, 255);
		Concentration01(120);
		SetColor(255, 255, 255);
		Wait(120);

		T_SetSpeed();
		T_Wall();
		T_Particle();
	}

	task T_SetSpeed()
	{
		loop{
			if( GetTimer() <= 20 ){
				SetCommonData("spell_speedrate", 1.0);
			}
			else{
				SetCommonData("spell_speedrate", 1.0 - 0.5 * max(GetLife() - 300, 0) / 1200);
			}
			yield;
		}
	}

	task T_Wall()
	{
		let angle = 0;
		let inter = 13.5;
		let count = 0;
		let k = 1;
		loop{
			let v = 5.7 * GetCommonData("spell_speedrate");
			let wait = trunc(4.2 / GetCommonData("spell_speedrate"));

			PlaySE(se_shot1);
			ascent( let j in 0..2 ){
				ascent( let i in 0..8 ){
					CreateShot01(GetX(), GetY() - 24, v, angle + (i - 4) * (inter + 1.2) + j * 180, 8, 0);
				}
			}
			angle += k * inter;
			count ++;
			if( count % 67 == 0 ){
				k = -k;
			}
			Wait(wait);
		}
	}

	task T_Particle()
	{
		let k = 0;
		loop{
			let wait = trunc(60 / GetCommonData("spell_speedrate") - 22);
			PlaySE(se_shot2);
			CreateEnemyFromScript("magic", GetX(), GetY(), 2.0, [170, 10][k], [-1, 1][k]);
			k = 1 - k;
			Wait(wait);
		}
	}

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

script_enemy magic
{
	#include_function ".\init.txt"

	let arg;
	let rot = rand(0, 360);

	@Initialize
	{
		SetLife(9999);
		SetHitState(0);

		arg = GetArgument();

		T_Main();
	}

	@Finalize
	{
	}

	@DrawLoop
	{
		SetTexture(img_magic);
		SetGraphicRect(192, 64, 256, 128);
		SetAlpha(128);
		SetGraphicAngle(0, 0, rot);
		DrawGraphic(GetX(), GetY());
		SetGraphicAngle(0, 0, 0);
	}

	task T_Main()
	{
		yield;

		T_Act();
		loop{
			if( IsOutOfClipRange(GetX(), GetY(), 64) ){
				VanishEnemy();
			}
			rot -= 2;
			yield;
		}
	}

	task T_Act()
	{
		let arg = GetArgument();
		let angle = -90;
		loop{
			let v = 3.4 * GetCommonData("spell_speedrate");
			ascent( let i in 0..2 ){
				CreateShot01(GetX(), GetY(), v, angle + (i - 0.5) * 2.5, 208, 8);
			}
			angle += arg * 12.9;
			Wait(3);
		}
	}

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