#東方弾幕風
#Title[魔符「スターストリーム」]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

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

#include_function ".\..\txt/data.txt"

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

    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetCenterY-50;


    @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,4,83,334,108);
	DoubleSpoilerSetShotAutoDeleteClip(96,128,96,32);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

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

    @DrawLoop {
	DrawBoss( imgBoss );
    }

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


	}

    // メインタスク
task TMain 
{
	yield;
	standBy;
	Shot;
	step;
}


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

let watetime=120;

task step
{
	while(!StepUp1){yield;}
	watetime=90;
	while(!StepUp2){yield;}
	watetime=60;
}

task Shot
{
	loop
	{
		ascent(let i in 0..3)
		{
		BunCreateShot01(GetX,GetY,90+i*120,129);
		}
		wait(30);
		moveToPlayer(rand(40, 60), rand(-10, 10), 30,
                     GetClipMinX + 48, GetClipMinY +  64,
                     GetClipMaxX - 48, GetClipMinY + 144);
		MagicCircleEffectTask;
		wait(watetime-30);
	}
}

task StarLightShot(obj,Angle)
{
let t=0;
while(!Obj_BeDeleted(obj))
{
	DoubleSpoilerCreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,Angle,121+t%7,10,SetBulletColor[t%7],80,50,80);
	t+=1;
	wait(7);
}
}

task BunCreateShot01(let x,let y,let angle,let graphic)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, 0);
	//ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);

	let X;
	let Y;
	let VanishJudg=false;

	let r=0;
	let pangle=90+GetAngleToPlayer-90;
	let GPAngle=GetAngleToPlayer;
	let t=0;
	StarLightShot(obj,GPAngle);
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetX(obj,x+r/3*cos(pangle)*cos(angle)-r*sin(pangle)*sin(angle));
		Obj_SetY(obj,y+r/3*sin(pangle)*cos(angle)+r*cos(pangle)*sin(angle));
		ObjShot_SetGraphic(obj, graphic+floor(t%7));
		wait(1);
		angle+=6;
		x-=0.8*cos(GPAngle);
		y-=0.8*sin(GPAngle);
		r+=1.2;
		t+=1/8;
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_GetX(obj)<GetClipMinX-192)//左端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetX(obj)>GetClipMaxX+192)//右端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)<GetClipMinY-192)//上端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)>GetClipMaxY+192)//下端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
	}
	if(VanishJudg==false)
	{
		if(DistanceToPlayer(X,Y)<=50)
		{
			RiskShot(160);
		}
		if(DistanceToBoss(X,Y)<=50)
		{
			ClearShot;
		}

		BasePoint(250);

		BulletColor("RED");

		BulletColor("ORANGE");

		BulletColor("YELLOW");

		BulletColor("GREEN");

		BulletColor("CYAN");

		BulletColor("BLUE");

		BulletColor("PURPLE");
	}
}


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