#東方弾幕風
#Title[錨符「フックアンカーショット」]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

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

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

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_murasa.png"; 
    let imgAnchor =GetCurrentScriptDirectory ~ "..\img/ikari.png"; 

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


    @Initialize {
	SetShotAutoDeleteClip(4,4,4,4);
	SetBulletScorePoint(12,120);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,4,473,422,499);
        LoadGraphic(imgBoss);
	LoadGraphic(GetCurrentScriptDirectory ~ "..\img/shot_all.png");
	LoadGraphic(imgAnchor);
        SetTexture(imgBoss);
	SetX(GetCenterX-0.1);
	InitializeAction();
        TMain;
    }

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

    @DrawLoop {
	DrawBoss( imgBoss );
    }

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


	}

    // メインタスク
task TMain 
{
	yield;
	BossShadowAnimation(imgBoss,0,127,127,255);
	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)
	{
		yield;
	}
}

let AnchorWay=4;
let AnchorFlag1=false;
let AnchorFlag2=false;
let AnchorFlag3=false;
let AnchorFlag4=false;

task step
{
	while(!StepUp1){yield;}
	AnchorFlag1=true;
	while(!StepUp2){yield;}
	AnchorWay=6;
	AnchorFlag2=true;
	while(!StepUp3){yield;}
	AnchorFlag3=true;
	while(!StepUp4){yield;}
	AnchorWay=8;
	AnchorFlag4=true;
}

task Shot
{
let dir=1;
	loop
	{
	let angle=GetAngleToPlayer;
		ascent(let i in 0..AnchorWay)
		{
			AnchorShot(GetX,GetY,angle+i*360/AnchorWay*dir);
			wait(10);
		}
		wait(60);
		DoubleSpoilermoveToPlayer03(rand(20,30),rand(-10,10), 15,0.5,
               		 GetClipMinX + 48, GetCenterY-80,
               		 GetClipMaxX - 48, GetCenterY-40);
		wait(60);

		loop(120)
		{
			if(AnchorFlag1==true){AnchorFlag1=false;break;}
			if(AnchorFlag2==true){AnchorFlag2=false;break;}
			if(AnchorFlag3==true){AnchorFlag3=false;break;}
			if(AnchorFlag4==true){AnchorFlag4=false;break;}
			yield;
		}
	dir=dir*-1;
	}
}

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

	let speed=0;
	Obj_SetSpeed(obj,speed);
	Obj_SetAngle(obj,angle);
	Obj_SetAlpha(obj,0);

	let angleplus=6;

	let r=0;
	let pangle=90+GetAngleToPlayer-90;
	let GPAngle=GetAngleToPlayer;
	let t=0;
	let WaterFlag=false;

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

	Anchor(obj);
	loop(15)
	{
	if(Obj_BeDeleted(obj)){break;}
	yield;
	}
	ascent(let i in 0..120)
	{
		if(Obj_BeDeleted(obj)){break;}
		Obj_SetSpeed(obj,speed);
		if(speed<10)
		{
			speed+=0.25;
		}
		if(Obj_GetX(obj)<=GetClipMinX+32 || Obj_GetX(obj)>=GetClipMaxX-32 || Obj_GetY(obj)<=GetClipMinY+32 || Obj_GetY(obj)>=GetClipMaxY-32)
		{
			speed=0;
			if(WaterFlag==false)
			{
			ascent(let i in 0..10)
			{
				DoubleSpoilerCreateShot01(Obj_GetX(obj),Obj_GetY(obj),0.75,Obj_GetAngle(obj)+i*360/10,14,10,"BLUE",0,1);
				DoubleSpoilerCreateShot01(Obj_GetX(obj),Obj_GetY(obj),1.75,Obj_GetAngle(obj)+i*360/10,14,10,"BLUE",0,1);

				DoubleSpoilerCreateShot01(Obj_GetX(obj),Obj_GetY(obj),1.25,Obj_GetAngle(obj)+i*360/10+18,14,10,"BLUE",0,1);
			}
			WaterFlag=true;
			}
		}
		yield;
	}

	speed=-0.1;
	Obj_SetSpeed(obj,speed);
	WaterHook(obj);
	loop(120)
	{
		if(Obj_BeDeleted(obj)){break;}
		Obj_SetAngle(obj,atan2(Obj_GetY(obj)-GetY,Obj_GetX(obj)-GetX));
		Obj_SetSpeed(obj,speed);
		if(speed<10)
		{
			speed-=0.1;
		}
		if(((Obj_GetX(obj)-GetX)^2+(Obj_GetY(obj)-GetY)^2)^0.5<=10)
		{
			speed=0;
		}
		yield;
	}
}

task WaterHook(obj)
{
while(Obj_GetSpeed(obj)!=0)
{
	ascent(let i in 0..10)
	{
		DoubleSpoilerCreateShot01(Obj_GetX(obj),Obj_GetY(obj),1,Obj_GetAngle(obj)+i*360/10+18,13,10,"CYAN",0,1);
	}
	wait(15);
}

}

task Anchor(Cobj)
{
	let ScaleX=0;
	let ScaleY=1;
  	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgAnchor);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//ObjEffect_SetRenderState(obj, ADD);
	ObjEffect_SetScale(obj, ScaleX,ScaleY);
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetVertexXY(obj, 0, -64, -64);
	ObjEffect_SetVertexXY(obj, 1,  64, -64);
	ObjEffect_SetVertexXY(obj, 2,  64,  64);
	ObjEffect_SetVertexXY(obj, 3, -64,  64);
		
	ObjEffect_SetVertexUV(obj, 0,  0,  0);
	ObjEffect_SetVertexUV(obj, 1,  128, 0);
	ObjEffect_SetVertexUV(obj, 2, 128,  128);
	ObjEffect_SetVertexUV(obj, 3, 0, 128);

/*	ObjEffect_SetVertexColor(obj,0,100,255,250,250);
	ObjEffect_SetVertexColor(obj,1,100,255,250,250);
	ObjEffect_SetVertexColor(obj,2,100,255,250,250);
	ObjEffect_SetVertexColor(obj,3,100,255,250,250);
*/

	ObjEffect_SetLayer(obj,3);

	let X=Obj_GetX(obj);
	let Y=Obj_GetY(obj);
	Obj_SetPosition(obj,Obj_GetX(Cobj),Obj_GetY(Cobj));
	ObjEffect_SetAngle(obj,0,0,Obj_GetAngle(Cobj)+90);

	loop(15)
	{
		AnchorShadow(Cobj,Obj_GetX(obj),Obj_GetY(obj),ScaleX);
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(Cobj)){break;}
		ObjEffect_SetScale(obj, ScaleX,ScaleY);
		ScaleX+=1/15;
		yield;
	}
	ObjEffect_SetScale(obj, ScaleX,ScaleY);
	let count=0;
	while(!Obj_BeDeleted(Cobj))
	{
		AnchorShadow(Cobj,Obj_GetX(obj),Obj_GetY(obj),ScaleX);
		Obj_SetPosition(obj,Obj_GetX(Cobj),Obj_GetY(Cobj));
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(((Obj_GetX(obj)-GetX)^2+(Obj_GetY(obj)-GetY)^2)^0.5<=10 && count>30)
		{
			break;
		}
		count+=1;
		wait(1);
	}

	loop(15)
	{
		AnchorShadow(Cobj,Obj_GetX(obj),Obj_GetY(obj),ScaleX);
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(Cobj)){break;}
		ObjEffect_SetScale(obj, ScaleX,ScaleY);
		ScaleX-=1/15;
		yield;
	}
	Obj_Delete(obj);
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		BasePoint(200);
		loop(5)
		{
		EffectSet(X,Y,"CYAN");
		}

		BulletColor("CYAN");
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		loop(5)
		{
		EffectSet(X,Y,"CYAN");
		}
	}
}

task AnchorShadow(Cobj,X,Y,ScaleX)
{
	let randlect=rand(-1,1);

  	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgAnchor);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetRenderState(obj, ADD);
//	ObjEffect_SetScale(obj, ScaleX,ScaleY);
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetVertexXY(obj, 0, -64+randlect, -64+randlect);
	ObjEffect_SetVertexXY(obj, 1,  64+randlect, -64+randlect);
	ObjEffect_SetVertexXY(obj, 2,  64+randlect,  64+randlect);
	ObjEffect_SetVertexXY(obj, 3, -64+randlect,  64+randlect);
		
	ObjEffect_SetVertexUV(obj, 0,  0,  0);
	ObjEffect_SetVertexUV(obj, 1,  128, 0);
	ObjEffect_SetVertexUV(obj, 2, 128,  128);
	ObjEffect_SetVertexUV(obj, 3, 0, 128);

	ObjEffect_SetLayer(obj,2);

	ObjEffect_SetAngle(obj,0,0,Obj_GetAngle(Cobj)+90);
	let Alpha=100;
	ascent(let i in 0..4)
	{
	ObjEffect_SetVertexColor(obj,i,Alpha,255,250,250);
	}

	let ScalePlus=0;
		ObjEffect_SetScale(obj, ScaleX+ScalePlus,1+ScalePlus);
	Obj_SetPosition(obj,X,Y);

	loop(8)
	{
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
		}
		ScalePlus+=0.01;
		ObjEffect_SetScale(obj, ScaleX+ScalePlus,1+ScalePlus);
		Alpha-=100/8;
		yield;
	}
	Obj_Delete(obj);
}
#include_function ".\..\txt/Data.txt"
#include_function ".\..\lib/lib_anime_Patchouli.txt"
}
