#東方弾幕風
#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/DoubleSpoilerData.txt"

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

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


    @Initialize {
	SetShotAutoDeleteClip(96,128,96,8);
	SetBulletScorePoint(12,100);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,4,83,334,108);
        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;
	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);
		DoubleSpoilermoveToPlayer(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],0);
	t+=1;
	wait(7);
}
}

task locus(Cobj,let x,let y,let angle,let graphic)
{
	let r=0;
	let dirangle=GetAngleToPlayer;
	let rudius=30;
	let obj = Obj_Create(OBJ_SINUATE_LASER);
	Obj_SetPosition(obj, GetX+rudius*cos(angle), GetY+rudius*sin(angle));
	ObjShot_SetGraphic(obj, graphic+112);
	ObjSinuateLaser_SetLength(obj,36);
	ObjSinuateLaser_SetWidth(obj,8);
	Obj_SetAutoDelete(obj,false);
	let angleplus=0;
	let VanishJudg=false;//画面外にいって消えたかを判定。
	let count=0;
	let angleplus=6;

	let r=0;
	let pangle=90+GetAngleToPlayer-90;
	let GPAngle=GetAngleToPlayer;
	let t=0;
	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));
		if(Obj_BeDeleted(Cobj)){VanishJudg=false;break;}
		wait(1);
		angle+=angleplus;
		angleplus-=0.012;
		x-=0.8*cos(GPAngle);
		y-=0.8*sin(GPAngle);
		r+=1.2;
		t+=1/8;
	}
	ascent(let i in 0..36)
	{
		ObjSinuateLaser_SetLength(obj,36-i);
		wait(1);
	}
	Obj_Delete(obj);
}

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 angleplus=6;

	let r=0;
	let pangle=90+GetAngleToPlayer-90;
	let GPAngle=GetAngleToPlayer;
	let t=0;
	StarLightShot(obj,GPAngle);
	locus(obj,x,y,angle,graphic);
	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+=angleplus;
		angleplus-=0.012;
		x-=0.8*cos(GPAngle);
		y-=0.8*sin(GPAngle);
		r+=1.2;
		t+=1/8;
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		BasePoint(300);

		BulletColor("RED");

		BulletColor("ORANGE");

		BulletColor("YELLOW");

		BulletColor("GREEN");

		BulletColor("CYAN");

		BulletColor("BLUE");

		BulletColor("PURPLE");
	}
}

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