#東方弾幕風
#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-50;


    @Initialize {
	SetBulletScorePoint(12,120);
	SetShotAutoDeleteClip(80,80,80,80);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,9,49,271,75);
        LoadGraphic(imgBoss);
        LoadGraphic(imgLine);
        SetTexture(imgBoss);
	InitializeAction();
	SetX(xIni);
	SetY(yIni);
        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;
	standBy;
	TMagic;
	Shot;
	step;
}

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 30);
	let wIni = 30;
	//SetMovePosition02(xIni, yIni, wIni);
	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=30;

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

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,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 obj = Obj_Create(OBJ_SINUATE_LASER);
	ObjShot_SetGraphic(obj, 243);
	ObjSinuateLaser_SetLength(obj,36);
	ObjSinuateLaser_SetWidth(obj,8);
	Obj_SetCollisionToPlayer(obj,false);

	let r=0;
	let rplus=1.5;
	let angleplus=5*dir;

	loop
	{
		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));
		angle+=angleplus*2;
		if(angleplus>0.5 || angleplus<-0.5)
		{
			angleplus-=0.05*dir;
		}
		if(angleplus<=0.5 || angleplus>=0.5)
		{
			angleplus-=0.0005*dir;
		}
		r+=rplus;
		if(rplus>1)
		{
			rplus-=0.002;
		}
		yield;
	}
/////////////////////////////////////////////////////////////////////////
}
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.5;
	let angleplus=5*dir;
	
	while(!Obj_BeDeleted(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.05*dir;
		}
		if(angleplus<=0.5 || angleplus>=0.5)
		{
			angleplus-=0.0005*dir;
		}
		r+=rplus;
		if(rplus>1)
		{
			rplus-=0.002;
		}
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		alternative(graphic)
		case(9)
		{
			BulletColor("RED");
		}
		case(10)
		{
			BulletColor("ORANGE");
		}
		case(11)
		{
			BulletColor("YELLOW");
		}
		case(12)
		{
			BulletColor("GREEN");
		}
		case(13)
		{
			BulletColor("CYAN");
		}
		case(14)
		{
			BulletColor("BLUE");
		}
		case(15)
		{
			BulletColor("PURPLE");
		}

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

			BulletColor("ORANGE");

			BulletColor("YELLOW");

			BulletColor("GREEN");

			BulletColor("CYAN");

			BulletColor("BLUE");

			BulletColor("PURPLE");

			BulletColor("WHITE");
*/
	}

}

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