#東方弾幕風
#Title[「レインボウリング」]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

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

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_daiyousei.png"; 
    let imgLine =GetCurrentScriptDirectory ~ "..\img/CircleLine.png"; 

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


    @Initialize {
	SetBulletScorePoint(12,120);
	SetShotAutoDeleteClip(96,96,96,96);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	LoadGraphic(GetCurrentScriptDirectory ~ "..\img/WhiteLine.png");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,9,49,271,75);
        LoadGraphic(imgBoss);
        LoadGraphic(imgLine);
        SetTexture(imgBoss);
	InitializeAction();
	SetX(GetCenterX);
	SetY(GetClipMinY-32);
        TMain;
    }

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

//let appearecount=0;

    @DrawLoop {	
/*	if(appearecount<30)
	{
		if(appearecount%2==0)
		{
			SetAlpha(100);
			SetColor(150,255,255);
			DrawGraphic(GetX+45-appearecount*1.5,GetY);
			DrawGraphic(GetX-45+appearecount*1.5,GetY);
		}
		else
		{
			SetAlpha(150);
			SetColor(150,255,255);
			DrawGraphic(GetX+22.5-appearecount*1.5/2,GetY);
			DrawGraphic(GetX-22.5+appearecount*1.5/2,GetY);
		}
	appearecount+=1;
	SetAlpha(0);
	DrawBoss( imgBoss );
	}
	else
*///	{
		SetAlpha(255);
		SetColor(255,255,255);
		DrawBoss( imgBoss );
//	}
    }

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


	}

    // メインタスク
task TMain 
{
	yield;
	BossShadowAnimation(imgBoss,0,0,255,255);
	standBy;
	TMagic;
	Shot;
	step;
}

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

task TMagic
{
	loop
	{
	let angle=0;
	let y =GetY;
	loop(90)
	{
//		SetY(y+4*sin(angle));
		yield;
//		angle+=4;
	}

	MagicCircleEffectTask;
	
	}
}

let num=24;

task step
{
	while(!StepUp1){yield;}
	num=27;
	while(!StepUp2){yield;}
	num=30;
	while(!StepUp3){yield;}
	num=33;
	while(!StepUp4){yield;}
	num=36;
	while(!StepUp5){yield;}
	num=39;
}

task Shot
{
let t=rand_int(0,7);
let dir=rand_int(0,1)*2-1;
	loop
	{
	let pangle=rand(0,360);
		ascent(let i in 0..num)
		{
		BunCreateShot01(GetX,GetY,i*360/num,pangle,dir,9+t%7);
		}
		Effect(GetX,GetY,0,pangle+90,9+t%7,num,dir);
		wait(45);
		t+=1;
		dir=dir*-1;
	}
}

//////////////////////////////////////////////////////////////////
task Effect(let x,let y,angle,pangle,let graphic,let num,dir)
{
		let R;let G;let B;
		if(graphic==9){R=255;G=0;B=0;}
		if(graphic==10){R=255;G=165;B=0;}
		if(graphic==11){R=255;G=255;B=0;}
		if(graphic==12){R=0;G=255;B=0;}
		if(graphic==13){R=0;G=255;B=255;}
		if(graphic==14){R=0;G=0;B=255;}
		if(graphic==15){R=160;G=32;B=240;}

		let r1=-5;
		let r2=5;
		let r=0;
		let rplus=1.70;
		let angleplus=5*dir;

		let randvertex=0;
		let VertexNum=48;
		let Radius=[r1,r2];
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,GetCurrentScriptDirectory ~ "..\img/WhiteLine.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj,VertexNum);

		ascent(let i in 0..VertexNum)
		{
			ObjEffect_SetVertexXY(obj, i, Radius[i%2]*cos(360/(VertexNum-2)*i), Radius[i%2]*sin(360/(VertexNum-2)*i));
		}
		ascent(let i in 0+randvertex..VertexNum+randvertex)
		{	
			ObjEffect_SetVertexUV(obj, i-randvertex,  256/(VertexNum)*i,  16*(i%2));
		}

		ascent(let i in 0..VertexNum)
		{			
			ObjEffect_SetVertexColor(obj, i,100,R,G,B);
		}

		ObjEffect_SetAngle(obj,0,0,pangle);
		ObjEffect_SetLayer(obj,3);

		let Scale=1;

		ObjEffect_SetScale(obj,Scale,Scale/2);
		Obj_SetPosition(obj,GetX,GetY);
		let Alpha=100;

		loop(420)
		{
		angle+=angleplus;
		if(angleplus>0.5 || angleplus<-0.5)
		{
			angleplus-=0.05*dir;
		}
		if(angleplus<=0.5 || angleplus>=0.5)
		{
			angleplus-=0.0005*dir;
		}
		if(!OnPlayerMissed)
		{
		r1+=rplus;
		r2+=rplus;
		Radius=[r1,r2];
		}
		if(rplus>1.25)
		{
			rplus-=0.0015;
		}
		ascent(let i in 0..VertexNum)
		{
			ObjEffect_SetVertexXY(obj, i, Radius[i%2]*cos(360/(VertexNum-2)*i), Radius[i%2]*sin(360/(VertexNum-2)*i));
		}
		yield;
		}
		Obj_Delete(obj);
/////////////////////////////////////////////////////////////////////////
}

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

	let r=0;
	let rplus=1.70;
	let angleplus=5*dir;
	
	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/2*cos(pangle)*cos(angle)-r*sin(pangle)*sin(angle));
		Obj_SetY(obj,y+r/2*sin(pangle)*cos(angle)+r*cos(pangle)*sin(angle));
		wait(1);
		angle+=angleplus;
		if(angleplus>0.5 || angleplus<-0.5)
		{
			angleplus-=0.04*dir;
		}
		if(angleplus<=0.5 || angleplus>=0.5)
		{
			angleplus-=0.0004*dir;
		}
		r+=rplus;
		if(rplus>1.25)
		{
			rplus-=0.0015;
		}
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		alternative(graphic)
		case(9)
		{
			BulletColor("RED");
				EffectSet(X,Y,"RED");
				EffectSet(X,Y,"RED");
		}
		case(10)
		{
			BulletColor("ORANGE");
				EffectSet(X,Y,"ORANGE");
				EffectSet(X,Y,"ORANGE");
		}
		case(11)
		{
			BulletColor("YELLOW");
				EffectSet(X,Y,"YELLOW");
				EffectSet(X,Y,"YELLOW");
		}
		case(12)
		{
			BulletColor("GREEN");
				EffectSet(X,Y,"GREEN");
				EffectSet(X,Y,"GREEN");
		}
		case(13)
		{
			BulletColor("CYAN");
				EffectSet(X,Y,"CYAN");
				EffectSet(X,Y,"CYAN");
		}
		case(14)
		{
			BulletColor("BLUE");
				EffectSet(X,Y,"BLUE");
				EffectSet(X,Y,"BLUE");
		}
		case(15)
		{
			BulletColor("PURPLE");
				EffectSet(X,Y,"PURPLE");
				EffectSet(X,Y,"PURPLE");
		}
		}

/*		SetCommonData("OyajiBonus",1);
		SetCommonData("CatBonus",1);
			BulletColor("RED");

			BulletColor("ORANGE");

			BulletColor("YELLOW");

			BulletColor("GREEN");

			BulletColor("CYAN");

			BulletColor("BLUE");

			BulletColor("PURPLE");

			BulletColor("WHITE");
*/
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		alternative(graphic)
		case(9)
		{
				EffectSet(X,Y,"RED");
				EffectSet(X,Y,"RED");
		}
		case(10)
		{
				EffectSet(X,Y,"ORANGE");
				EffectSet(X,Y,"ORANGE");
		}
		case(11)
		{
				EffectSet(X,Y,"YELLOW");
				EffectSet(X,Y,"YELLOW");
		}
		case(12)
		{
				EffectSet(X,Y,"GREEN");
				EffectSet(X,Y,"GREEN");
		}
		case(13)
		{
				EffectSet(X,Y,"CYAN");
				EffectSet(X,Y,"CYAN");
		}
		case(14)
		{
				EffectSet(X,Y,"BLUE");
				EffectSet(X,Y,"BLUE");
		}
		case(15)
		{
				EffectSet(X,Y,"PURPLE");
				EffectSet(X,Y,"PURPLE");
		}
	}

}

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