#東方弾幕風
#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,255);
	SetGraphicScale(1.5-0.5/30*appearecount,1.5-0.5/30*appearecount);
	if(appearecount<30)
	{
	appearecount+=1;
	}

	DrawBoss( imgBoss );

    }
function appeare(num)
{
let count=0;
loop(150)
{
	SetAlpha(255/15*count);
	SetColor(255/15*count,255,255);
	SetGraphicScale(1.5-0.5/15*count,1.5-0.5/15*count);
	DrawBoss( imgBoss );
	count+=1;
	//yield;
}
}
    @Finalize {
        DeleteGraphic(imgBoss);
	FinalizeDoubleSpoiler;
    }
	@BackGround
	{

	}

    // メインタスク
task TMain 
{
	yield;
	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 StandardSpeed=speed;
	let r=0;
	let dirangle=GetAngleToPlayer;
	let rudius=30;
	let obj = Obj_Create(OBJ_SINUATE_LASER);
	Obj_SetPosition(obj, GetX+rudius*cos(angle), GetY+rudius*sin(angle));
	ObjShot_SetGraphic(obj, graphic+112);
	ObjSinuateLaser_SetLength(obj,36);
	ObjSinuateLaser_SetWidth(obj,8);
	Obj_SetAutoDelete(obj,false);
	let angleplus=0;
	let VanishJudg=false;//画面外にいって消えたかを判定。
	let count=0;
	loop(delay)
	{
		if(Obj_BeDeleted(Cobj)){VanishJudg=false;break;}
	wait(1);
	}
	loop(60)
	{
		Obj_SetPosition(obj, GetX+r*cos(angle), GetY+r*sin(angle));
		Obj_SetAngle(obj, angle+75*(count>30)*dir);
		r+=speed;
		angle+=angleplus*dir;
		angleplus+=1/30;
		speed-=StandardSpeed/60;
		if(Obj_BeDeleted(Cobj)){VanishJudg=false;break;}
		VanishJudg=true;
		count+=1;
		wait(1);
	}
	let time=30;
	loop(60)
	{
		angle+=2.0*dir;
		Obj_SetPosition(obj, GetX+r*cos(angle), GetY+r*sin(angle));
		Obj_SetAngle(obj, angle+90*dir);
		if(Obj_BeDeleted(Cobj)){VanishJudg=false;break;}
		VanishJudg=true;
		wait(1);
	}
	ascent(let i in 0..36)
	{
		ObjSinuateLaser_SetLength(obj,36-i);
		wait(1);
	}
	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 X=Obj_GetX(obj);//毎フレーム座標を記録するための値
	let Y=Obj_GetY(obj);//毎フレーム座標を記録するための値
	let VanishJudg=false;//画面外にいって消えたかを判定。

	let angleplus=0;

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

	loop(delay)
	{
		if(Obj_BeDeleted(obj)){VanishJudg=false;break;}
	wait(1);
	}
	loop(60)
	{
		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)){VanishJudg=false;break;}
		VanishJudg=true;
		wait(1);
	}
	let time=30;
	let count=0;
	loop(60)
	{
		angle+=2.0*dir;
		Obj_SetPosition(obj, GetX+r*cos(angle), GetY+r*sin(angle));
		if(Obj_BeDeleted(obj)){VanishJudg=false;break;}
		VanishJudg=true;
		if(count%3==0)
		{
		StarShot(Obj_GetX(obj),Obj_GetY(obj),angle,graphic-8,10,time);
		}
		count+=1;
		wait(1);
	}
	Obj_Delete(obj);
	if(GetCommonDataDefault("Shooting",false))
	{
		BasePoint(220);
		alternative(graphic)
		case(129)
		{
			BulletColor("RED");
		}
		case(130)
		{
			BulletColor("ORANGE");
		}
		case(131)
		{
			BulletColor("YELLOW");
		}
		case(132)
		{
			BulletColor("GREEN");
		}
		case(133)
		{
			BulletColor("CYAN");
		}
		case(134)
		{
			BulletColor("BLUE");
		}
		case(135)
		{
			BulletColor("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);

	wait(time);
	loop(60)
	{
		Obj_SetSpeed(obj,speed);
		if(speed<9)
		{
		speed+=0.06;
		}
		if(Obj_BeDeleted(obj)){break;}
		wait(1);
	}
	Obj_SetAutoDelete(obj,true);
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetSpeed(obj,speed);
		if(speed<9)
		{
		speed+=0.06;
		}
		wait(1);
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		alternative(graphic)
		case(121)
		{
			BulletColor("RED");
		}
		case(122)
		{
			BulletColor("ORANGE");
		}
		case(123)
		{
			BulletColor("YELLOW");
		}
		case(124)
		{
			BulletColor("GREEN");
		}
		case(125)
		{
			BulletColor("CYAN");
		}
		case(126)
		{
			BulletColor("BLUE");
		}
		case(127)
		{
			BulletColor("PURPLE");
		}
	}
}

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