#東方弾幕風
#Title[境符「先と後の境界」]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

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

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

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_yukari.png"; 
	let imgBG=GetCurrentScriptDirectory ~ "..\img/MenuBG.png";

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


    @Initialize {
	SetShotAutoDeleteClip(2,2,2,2);
	SetBulletScorePoint(12,150);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,5,377,276,402);
        LoadGraphic(imgBoss);
	LoadGraphic(imgBG);
        SetTexture(imgBoss);
	SetX(xIni);
	SetY(yIni-200);
	InitializeAction();
        TMain;
    }

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

let appearecount=0;

    @DrawLoop {
	DrawBoss( imgBoss );
    }

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


	}

    // メインタスク
task TMain 
{
	yield;
	BossShadowAnimation(imgBoss,0,160,32,240);
	AppearBlind;
	standBy;
	Shot;
}


sub standBy//初期位置へ
{
	SetX(xIni);
	SetY(yIni+60);
	SetMovePosition02(xIni,yIni,30);
	wait(40);
}

task AppearBlind
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBG);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -30, 50);
		ObjEffect_SetVertexXY(obj, 1, 30,  50);
		ObjEffect_SetVertexXY(obj, 2, 30, -30);
		ObjEffect_SetVertexXY(obj, 3,  -30,  -30);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  384, 0);
		ObjEffect_SetVertexUV(obj, 2, 384,  448);
		ObjEffect_SetVertexUV(obj, 3, 0, 448);
		ObjEffect_SetLayer(obj,2);
		ObjEffect_SetScale(obj, 1.1,1.0);

		Obj_SetPosition(obj,xIni,yIni+60);
		loop(60)
		{
			yield;
		}
		Obj_Delete(obj);
}


let watetime=120;
let waterframe=25;
let Obj_Array=[1,2,3];

task Shot
{
	OrbitShot(1,79);
	OrbitShot(2,78);
	OrbitShot(3,74);
}

task OrbitShot(num,graphic)
{
	let Rudius=50;
	let angle=90;
	let angleplus;
	if(num==1)
	{
		angleplus=1;
	}
	if(num==2)
	{
		angleplus=1.5;
	}
	if(num==3)
	{
		angleplus=2.0;
	}
	let shotangle=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_Array[num-1]=obj;
	Obj_SetPosition(obj,GetX+Rudius*cos(angle),GetY+Rudius*sin(angle));
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAlpha(obj,0);
    
	let X=Obj_GetX(obj);
	let Y=Obj_GetY(obj);

	waveshot(obj,num);
	string(obj,num);
	stringorbit(obj,num);
	loop
	{
		Obj_SetPosition(obj,GetX+Rudius*cos(angle),GetY+Rudius*sin(angle));
		angle+=angleplus;
		yield;
	}
}

task waveshot(Cobj,num)
{
let angle=0;
let angleplus;
if(num==1){angleplus=0};
if(num==2){angleplus=120};
if(num==3){angleplus=240};
let graphic;
if(num==1){graphic=79};
if(num==2){graphic=78};
if(num==3){graphic=74};
let color;
if(num==1){color="PURPLE"};
if(num==2){color="BLUE"};
if(num==3){color="ORANGE"};
loop
{
	ascent(let i in 0..5)
	{
	DoubleSpoilerCreateShot01(Obj_GetX(Cobj),Obj_GetY(Cobj),num*0.75+1.25,angle+72*i,graphic,0,color,0,1);
	}
	angle+=angleplus;
	angleplus+=0.5;
	wait(num+1);
}
}

task string(Cobj,num)
{
	let graphic;
	if(num==1){graphic=159};
	if(num==2){graphic=158};
	if(num==3){graphic=154};

	let angle=atan2(GetY-Obj_GetY(Cobj),GetX-Obj_GetX(Cobj));
	let length=50;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,GetX,GetY);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,5);
	ObjShot_SetGraphic(obj, graphic);
	ObjLaser_SetSource(obj,false);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAngle(obj,angle);
	//Obj_SetAlpha(obj,150);
	ObjShot_SetBombResist(obj,true);

	loop
	{
		if(OnPlayerMissed){break;}
		Obj_SetPosition(obj, Obj_GetX(Cobj), Obj_GetY(Cobj));
		angle=atan2(GetY-Obj_GetY(Cobj),GetX-Obj_GetX(Cobj));
		Obj_SetAngle(obj,angle);
		yield;
	}
	Obj_Delete(obj);
}

task stringorbit(Cobj,num)
{
	yield;
	if(num==3){num=0;}
	let angle=atan2(Obj_GetY(Obj_Array[num])-Obj_GetY(Cobj),Obj_GetX(Obj_Array[num])-Obj_GetX(Cobj));
	let length=((Obj_GetY(Obj_Array[num])-Obj_GetY(Cobj))^2+(Obj_GetX(Obj_Array[num])-Obj_GetX(Cobj))^2)^0.5;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,GetX,GetY);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,5);
	ObjShot_SetGraphic(obj, 161);
	ObjLaser_SetSource(obj,false);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAngle(obj,angle);
	Obj_SetAlpha(obj,150);
	ObjShot_SetBombResist(obj,true);

	loop
	{
		if(OnPlayerMissed){break;}
		Obj_SetPosition(obj, Obj_GetX(Cobj), Obj_GetY(Cobj));
		angle=atan2(Obj_GetY(Obj_Array[num])-Obj_GetY(Cobj),Obj_GetX(Obj_Array[num])-Obj_GetX(Cobj));
		Obj_SetAngle(obj,angle);
		length=((Obj_GetY(Obj_Array[num])-Obj_GetY(Cobj))^2+(Obj_GetX(Obj_Array[num])-Obj_GetX(Cobj))^2)^0.5;
		ObjLaser_SetLength(obj,length);
		yield;
	}
	Obj_Delete(obj);
}

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