#東方弾幕風
#Title[紅符「スカーレットエイジス」]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

let Norma=5;//撮影枚数の設定
let SpellTimer=9000;//制限時間の設定（フレーム単位）
let StepUp=[1,2,3,4];//段階移行する枚数を設定（五つまで設定可能）。StepUp1〜5（boolean）まであり、入力枚数撮るとtrueになる

#include_function ".\..\txt/DoubleSpoilerData.txt"

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_remilia.png"; 

    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 112;


   @Initialize {
	SetShotAutoDeleteClip(16,16,16,16);
	SetBulletScorePoint(12,90);
	SetX(GetClipMinX);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,5,164,392,189);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	DoubleSpoilerYield;
    }

    @DrawLoop {
	DrawBoss( imgBoss );
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	FinalizeDoubleSpoiler;
    }
	@BackGround
	{

	}

    // メインタスク
task TMain 
{
	yield;
	BossShadowAnimation(imgBoss,0,255,0,0);
	standBy;
	//TMove;
	Step;
	Shot;
}

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 30);
	let wIni = 30;
	SetMovePosition03(xIni, yIni, 5,8);
	SetInvincibility(wIni);
	wait(wIni);
}

task TMove// 浮揚と移動
{
	loop
	{
	wait(120);
	DoubleSpoilermoveToPlayer(rand(40, 60), rand(-30, 30), 30,
                     GetClipMinX + 48, GetClipMinY +  64,
                     GetClipMaxX - 48, GetClipMinY + 144);
	MagicCircleEffectTask;
	}
}

let way=3;
let num=6;
let bulletwait=30;
let loopwait=120;
let bulletangle=45;
task Step
{
	while(!StepUp1){yield;}
	num=8;
	while(!StepUp2){yield;}
	num=10;
	while(!StepUp3){yield;}
	way=6;
	num=6;
	bulletangle=15;
	loopwait=150;
	DoubleSpoilerDeleteEnemyShotImmediatelyInCircle(ALL,GetCenterX,GetCenterY,300);
	while(!StepUp4){yield;}
	num=6;
	bulletwait=20;
	loopwait=180;
}

task Shot
{
wait(10);
let dir=rand_int(0,1)*2-1;
let stepupcount=0;
let waitjump=0;
	loop
	{
	let w=90;
		loop(num)
		{
		if(StepUp3==true && stepupcount==0)
		{
			stepupcount=1;
			waitjump=1;
			break;
		}
		if(StepUp4==true && stepupcount==1)
		{
			stepupcount=2;
			waitjump=1;
			break;
		}
		ascent(let i in 0..way)
		{
		BunCreateShot(GetX, GetY,4.5,w+360*i/way,dir,165,10);
		}
		wait(bulletwait);
		w-=bulletangle*dir;
		}
	if(waitjump==0)
	{
	MagicCircleEffectTask;
	loop(loopwait)
	{
		wait(1);
		if(StepUp3==true && stepupcount==0)
		{
			stepupcount=1;
			break;
		}
		if(StepUp4==true && stepupcount==1)
		{
			stepupcount=2;
			break;
		}
	}
	}
	else
	{
		waitjump=0;
	}
	dir=dir*-1;
	}
}


task BunCreateShot(let x,let y,let speed,let angle,let dir, let graphic,let delay)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	//ObjShot_SetBombResist(obj,true);

	//Obj_SetAutoDelete(obj,false);

	let count=-10;

	let X=Obj_GetX(obj);
	let Y=Obj_GetY(obj);

	while(!Obj_BeDeleted(obj))
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		if(speed>2)
		{
			speed-=0.025;
		}
		angle+=0.4*dir;
		if(count==3)
		{
		BunCreateShot01(Obj_GetX(obj),Obj_GetY(obj),0,0.005,Obj_GetAngle(obj)-90*dir,33,5);
		}
		if(count==6)
		{
		BunCreateShot01(Obj_GetX(obj),Obj_GetY(obj),0,0.0075,Obj_GetAngle(obj)-90*dir,33,5);
		}
		if(count==9)
		{
		BunCreateShot01(Obj_GetX(obj),Obj_GetY(obj),0,0.01,Obj_GetAngle(obj)-90*dir,33,5);
		}
		if(count==15)
		{
		count=0;
		}
		count+=1;
		wait(1);
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		BasePoint(310);
		BulletColor("RED");
			loop(8)
			{
			EffectSet(X,Y,"RED");
			}
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
			loop(8)
			{
			EffectSet(X,Y,"RED");
			}
	}
}


task BunCreateShot01(let x,let y,let speed,let aspeed,let angle, let graphic,let delay)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	//ObjShot_SetBombResist(obj,true);

	//Obj_SetAutoDelete(obj,false);

	let count=0;

	let X=Obj_GetX(obj);
	let Y=Obj_GetY(obj);

	while(!Obj_BeDeleted(obj))
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		Obj_SetSpeed(obj, speed);
		if(speed<1.5 && count>=10)
		{
		speed+=aspeed;
		}
		count+=1;
		wait(1);
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		BulletColor("RED");
			EffectSet(X,Y,"RED");
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		EffectSet(X,Y,"RED");
	}
}

#include_function ".\..\txt/Data.txt"
#include_function ".\..\lib/lib_anime_Patchouli.txt"
}
