#東方弾幕風
#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,0);
	SetBulletScorePoint(12,120);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,4,83,334,108);
        LoadGraphic(imgBoss);
	  LoadGraphic(GetCurrentScriptDirectory ~ "..\img/shot_all.png");
        SetTexture(imgBoss);
	SetX(GetCenterX-0.1);
	InitializeAction();
        TMain;
    }

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

    @DrawLoop {
	DrawBossAndShadow( imgBoss,0,191,255);
	DrawBoss( imgBoss );
    }

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


	}

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


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

task AppearEffect
{
	loop(30)
	{
		StarEffect;
		StarEffect;
		yield;
	}
}

task StarEffect
{
let num=rand_int(0,6);
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,GetCurrentScriptDirectory ~ "..\img/shot_all.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ALPHA); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -10, -10);
		ObjEffect_SetVertexXY(obj, 1, 10,  -10);
		ObjEffect_SetVertexXY(obj, 2, 10, 10);
		ObjEffect_SetVertexXY(obj, 3,  -10,  10);
		
		ObjEffect_SetVertexUV(obj, 0,  20*num,  318);
		ObjEffect_SetVertexUV(obj, 1,  20+20*num, 318);
		ObjEffect_SetVertexUV(obj, 2, 20+20*num,  338);
		ObjEffect_SetVertexUV(obj, 3, 20*num, 338);

		ObjEffect_SetLayer(obj,2);

		let Scale=1;
		let Zangle=0;
		ObjEffect_SetScale(obj,Scale,Scale);
		Obj_SetPosition(obj,GetX,GetY);
		Obj_SetSpeed(obj,2);
		Obj_SetAngle(obj,rand(0,360));
		loop(30)
		{
			Zangle+=3;
			Scale-=1/30;
			ObjEffect_SetScale(obj,Scale,Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			yield;
		}
		Obj_Delete(obj);
}

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,2);
	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);

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

	while(!Obj_BeDeleted(obj))
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(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))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		BasePoint(200);
		loop(5)
		{
		EffectSet(X,Y,"RED");
		EffectSet(X,Y,"ORANGE");
		EffectSet(X,Y,"YELLOW");
		EffectSet(X,Y,"GREEN");
		EffectSet(X,Y,"CYAN");
		EffectSet(X,Y,"BLUE");
		EffectSet(X,Y,"PURPLE");
		}
		BulletColor("RED");

		BulletColor("ORANGE");

		BulletColor("YELLOW");

		BulletColor("GREEN");

		BulletColor("CYAN");

		BulletColor("BLUE");

		BulletColor("PURPLE");
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		loop(5)
		{
		EffectSet(X,Y,"RED");
		EffectSet(X,Y,"ORANGE");
		EffectSet(X,Y,"YELLOW");
		EffectSet(X,Y,"GREEN");
		EffectSet(X,Y,"CYAN");
		EffectSet(X,Y,"BLUE");
		EffectSet(X,Y,"PURPLE");
		}
	}
}

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