#東方弾幕風
#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/data.txt"

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

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


   @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,4,200,348,225);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

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

    @DrawLoop {
	DrawBoss( imgBoss );
    }

    @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 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, speed);
	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;//画面外にいって消えたかを判定。
	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;
		speed-=StandardSpeed/60;
		if(Obj_BeDeleted(obj)){VanishJudg=false;break;}
		VanishJudg=true;
		if(Obj_GetX(obj)<GetClipMinX-64)//左端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetX(obj)>GetClipMaxX+64)//右端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)<GetClipMinY-96)//上端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)>GetClipMaxY+64)//下端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		wait(1);
	}
	let time=60;
	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,5,time);
		//time-=5;
		}
		count+=1;
		if(Obj_GetX(obj)<GetClipMinX-64)//左端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetX(obj)>GetClipMaxX+64)//右端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)<GetClipMinY-96)//上端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)>GetClipMaxY+64)//下端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		wait(1);
	}
	Obj_Delete(obj);
	if(VanishJudg==false)
	{
		if(DistanceToPlayer(X,Y)<=70)
		{
			RiskShot(80);
		}
		if(DistanceToBoss(X,Y)<=70)
		{
			ClearShot;
		}
		BasePoint(300);
		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);

	let X=Obj_GetX(obj);
	let Y=Obj_GetY(obj);
	let VanishJudg=false;
	wait(time);
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetSpeed(obj,speed);
		if(speed<9)
		{
		speed+=0.06;
		}
		if(Obj_GetX(obj)<GetClipMinX-96)//左端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetX(obj)>GetClipMaxX+96)//右端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)<GetClipMinY-128)//上端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)>GetClipMaxY+32)//下端での挙動
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		wait(1);
	}
	if(VanishJudg==false)
	{
		if(DistanceToPlayer(X,Y)<=50)
		{
			RiskShot(80);
		}
		if(DistanceToBoss(X,Y)<=50)
		{
			ClearShot;
		}

		BasePoint(80);

		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 ".\..\lib/lib_anime_Patchouli.txt"
}
