#東方弾幕風
#Title[儀符「ファントムポラリス」]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

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

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

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_mima.png"; 

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


   @Initialize {
	SetShotAutoDeleteClip(0,0,0,0);
	SetBulletScorePoint(12,80);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,4,200,348,225);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
	SetX(xIni);
	SetY(yIni);
        TMain;
    }

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

let appearecount=0;

    @DrawLoop {
	SetAlpha(255/30*appearecount);
	SetColor(255/30*appearecount,255/30*appearecount,255);
	SetGraphicScale(1.5-0.5/30*appearecount,1.5-0.5/30*appearecount);
	if(appearecount<30)
	{
	appearecount+=1;
	}
	else
	{
	DrawBossAndShadow( imgBoss,0,0,255);
	}
	DrawBoss( imgBoss );

    }


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

	}

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

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


let TimeWait=90;

task step
{
	while(!StepUp1){yield;}
	TimeWait=75;
	while(!StepUp2){yield;}
	TimeWait=60;
	while(!StepUp3){yield;}
	TimeWait=45;
	while(!StepUp4){yield;}
	TimeWait=30;
}

task Shot
{
let w=90;
let dir=rand_int(0,1)*2-1;
	loop
	{
		let angle=rand(0,360);
		ascent(let i in 0..6)
		{
			BunCreateShot01(GetX, GetY,8,i*60+angle,129,10,dir);
		}
		wait(TimeWait);
		dir=dir*-1;
		if(StepUp1)
		{
		let angle=rand(0,360);
			ascent(let i in 0..6)
			{
				BunCreateShot01(GetX, GetY,7,i*60+angle,130,10,dir);
			}
			wait(TimeWait);
			dir=dir*-1;			
		}
		if(StepUp3)
		{
		let angle=rand(0,360);
			ascent(let i in 0..6)
			{
				BunCreateShot01(GetX, GetY,6,i*60+angle,131,10,dir);
			}
			wait(TimeWait);
			dir=dir*-1;			
		}
		let angle=rand(0,360);
		ascent(let i in 0..6)
		{
			BunCreateShot01(GetX, GetY,5,i*60+angle,132,10,dir);
		}
		wait(TimeWait);
		dir=dir*-1;
		if(StepUp4)
		{
		let angle=rand(0,360);
			ascent(let i in 0..6)
			{
				BunCreateShot01(GetX, GetY,4,i*60+angle,133,10,dir);
			}
			wait(TimeWait);
			dir=dir*-1;			
		}
		if(StepUp2)
		{
		let angle=rand(0,360);
			ascent(let i in 0..6)
			{
				BunCreateShot01(GetX, GetY,3,i*60+angle,134,10,dir);
			}
			wait(TimeWait);
			dir=dir*-1;			
		}
		let angle=rand(0,360);
		ascent(let i in 0..6)
		{
			BunCreateShot01(GetX, GetY,2,i*60+angle,135,10,dir);
		}
		wait(TimeWait);
		dir=dir*-1;
	}
}

task locus(Cobj,let x,let y,let speed,let angle, let graphic,let delay,let dir)
{
	let dirangle=GetAngleToPlayer;
	let obj = Obj_Create(OBJ_SINUATE_LASER);
	Obj_SetPosition(obj, Obj_GetX(Cobj), Obj_GetY(Cobj));
	ObjShot_SetGraphic(obj, graphic+112);
	ObjSinuateLaser_SetLength(obj,36);
	ObjSinuateLaser_SetWidth(obj,8);
	Obj_SetAutoDelete(obj,false);
	let angleplus=0;

	let count=0;

	loop(delay)
	{
		if(Obj_BeDeleted(Cobj)){break;}
	yield;
	}
	loop(60)
	{
		Obj_SetPosition(obj, Obj_GetX(Cobj), Obj_GetY(Cobj));
		Obj_SetAngle(obj, angle+75*(count>30)*dir);
		angle+=angleplus*dir;
		angleplus+=1/30;
		if(Obj_BeDeleted(Cobj)){break;}
		count+=1;
		yield;
	}
	let time=30;
	loop(60)
	{
		angle+=2.0*dir;
		Obj_SetPosition(obj, Obj_GetX(Cobj), Obj_GetY(Cobj));
		Obj_SetAngle(obj, angle+90*dir);
		if(Obj_BeDeleted(Cobj)){break;}
		yield;
	}
	ascent(let i in 0..36)
	{
		ObjSinuateLaser_SetLength(obj,36-i);
		yield;
	}
	Obj_Delete(obj);
}

task BunCreateShot01(let x,let y,let speed,let angle, let graphic,let delay,let dir)
{
	let StandardSpeed=speed;
	let r=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, 0);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	//ObjShot_SetBombResist(obj,true);

	Obj_SetAutoDelete(obj,false);

	let angleplus=0;

	locus(obj,GetX, GetY,speed,angle,graphic,delay,dir);

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

	loop(delay)
	{
		if(Obj_BeDeleted(obj)){break;}
	yield;
	}
	loop(60)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		Obj_SetPosition(obj, GetX+r*cos(angle), GetY+r*sin(angle));
		r+=speed;
		angle+=angleplus*dir;
		angleplus+=1/30;
		speed-=StandardSpeed/60;
		if(Obj_BeDeleted(obj)){break;}
		yield;
	}
	let time=30;
	let count=0;
	loop(60)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		angle+=2.0*dir;
		Obj_SetPosition(obj, GetX+r*cos(angle), GetY+r*sin(angle));
		if(Obj_BeDeleted(obj)){break;}
		if(count%3==0)
		{
		StarShot(Obj_GetX(obj),Obj_GetY(obj),angle,graphic-8,10,time);
		}
		count+=1;
		yield;
	}
	Obj_Delete(obj);
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		BasePoint(220);
		alternative(graphic)
		case(129)
		{
			BulletColor("RED");
				EffectSet(X,Y,"RED");
				EffectSet(X,Y,"RED");
				EffectSet(X,Y,"RED");
		}
		case(130)
		{
			BulletColor("ORANGE");
				EffectSet(X,Y,"ORANGE");
				EffectSet(X,Y,"ORANGE");
				EffectSet(X,Y,"ORANGE");
		}
		case(131)
		{
			BulletColor("YELLOW");
				EffectSet(X,Y,"YELLOW");
				EffectSet(X,Y,"YELLOW");
				EffectSet(X,Y,"YELLOW");
		}
		case(132)
		{
			BulletColor("GREEN");
				EffectSet(X,Y,"GREEN");
				EffectSet(X,Y,"GREEN");
				EffectSet(X,Y,"GREEN");
		}
		case(133)
		{
			BulletColor("CYAN");
				EffectSet(X,Y,"CYAN");
				EffectSet(X,Y,"CYAN");
				EffectSet(X,Y,"CYAN");
		}
		case(134)
		{
			BulletColor("BLUE");
				EffectSet(X,Y,"BLUE");
				EffectSet(X,Y,"BLUE");
				EffectSet(X,Y,"BLUE");
		}
		case(135)
		{
			BulletColor("PURPLE");
				EffectSet(X,Y,"PURPLE");
				EffectSet(X,Y,"PURPLE");
				EffectSet(X,Y,"PURPLE");
		}
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		alternative(graphic)
		case(129)
		{
				EffectSet(X,Y,"RED");
				EffectSet(X,Y,"RED");
				EffectSet(X,Y,"RED");
		}
		case(130)
		{
				EffectSet(X,Y,"ORANGE");
				EffectSet(X,Y,"ORANGE");
				EffectSet(X,Y,"ORANGE");
		}
		case(131)
		{
				EffectSet(X,Y,"YELLOW");
				EffectSet(X,Y,"YELLOW");
				EffectSet(X,Y,"YELLOW");
		}
		case(132)
		{
				EffectSet(X,Y,"GREEN");
				EffectSet(X,Y,"GREEN");
				EffectSet(X,Y,"GREEN");
		}
		case(133)
		{
				EffectSet(X,Y,"CYAN");
				EffectSet(X,Y,"CYAN");
				EffectSet(X,Y,"CYAN");
		}
		case(134)
		{
				EffectSet(X,Y,"BLUE");
				EffectSet(X,Y,"BLUE");
				EffectSet(X,Y,"BLUE");
		}
		case(135)
		{
				EffectSet(X,Y,"PURPLE");
				EffectSet(X,Y,"PURPLE");
				EffectSet(X,Y,"PURPLE");
		}
	}
}

task StarShot(let x,let y,let angle,let graphic,let delay,let time)
{
	let speed=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj,angle-180);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	//ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);

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

	wait(time);
	loop(60)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		Obj_SetSpeed(obj,speed);
		speed+=0.06;
		if(Obj_BeDeleted(obj)){break;}
		yield;
	}
	Obj_SetAutoDelete(obj,true);
	while(!Obj_BeDeleted(obj))
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		Obj_SetSpeed(obj,speed);
		speed+=0.06;
		yield;
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		alternative(graphic)
		case(121)
		{
			BulletColor("RED");
				EffectSet(X,Y,"RED");
		}
		case(122)
		{
			BulletColor("ORANGE");
				EffectSet(X,Y,"ORANGE");
		}
		case(123)
		{
			BulletColor("YELLOW");
				EffectSet(X,Y,"YELLOW");
		}
		case(124)
		{
			BulletColor("GREEN");
				EffectSet(X,Y,"GREEN");
		}
		case(125)
		{
			BulletColor("CYAN");
				EffectSet(X,Y,"CYAN");
		}
		case(126)
		{
			BulletColor("BLUE");
				EffectSet(X,Y,"BLUE");
		}
		case(127)
		{
			BulletColor("PURPLE");
				EffectSet(X,Y,"PURPLE");
		}
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		alternative(graphic)
		case(121)
		{
				EffectSet(X,Y,"RED");
		}
		case(122)
		{
				EffectSet(X,Y,"ORANGE");
		}
		case(123)
		{
				EffectSet(X,Y,"YELLOW");
		}
		case(124)
		{
				EffectSet(X,Y,"GREEN");
		}
		case(125)
		{
				EffectSet(X,Y,"CYAN");
		}
		case(126)
		{
				EffectSet(X,Y,"BLUE");
		}
		case(127)
		{
				EffectSet(X,Y,"PURPLE");
		}
	}
}

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