#東方弾幕風
#Title[お燐通常]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

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

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

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

    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 160;


   @Initialize {
	SetShotAutoDeleteClip(4,4,4,4);
	SetBulletScorePoint(12,80);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
//	InitializeAction();
	SetX(GetClipMaxX);
	SetY(GetClipMinY+32);
        TMain;
    }

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

    @DrawLoop {
	DrawBossAndShadow( imgBoss,255,48,48);
	DrawBoss( imgBoss );
    }

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

	}

    // メインタスク
task TMain 
{
	yield;
	BossShadowPosition(0);
	standBy;
//	TMove;
	wait(15);
	Shot;
	Shot2;
	step
}

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

task TMove// 浮揚と移動
{
	loop
	{
	wait(120);
	DoubleSpoilermoveToPlayer(rand(40, 60), rand(-30, 30), 30,
                     GetClipMinX + 48, GetClipMinY +  64,
                     GetClipMaxX - 48, GetClipMinY + 144);
	MagicCircleEffectTask;
	}
}

task step
{
	while(!StepUp1){yield;}
	LineWait=270;
	BulletWait=12;
	while(!StepUp2){yield;}
	LineWait=240;
	BulletWait=10;
	while(!StepUp3){yield;}
	LineWait=210;
	LineWay=18;
	while(!StepUp4){yield;}
	LineWait=180;
	BulletWait=6;
	while(!StepUp5){yield;}
	BulletWait=4;
	while(!StepUp6){yield;}
	BulletWait=3;
}

task Shot2
{
let angle=90;
loop
{
	ascent(let i in 0..3)
	{
		DoubleSpoilerCreateShot01(GetX+10,GetY-35,rand(1.3,1.7),120*i+angle+rand(-10,10),BLUE01,15,"BLUE",0,1);
	}
	angle+=15;
	wait(BulletWait);
}
}

let LineWay=16;
let LineWait=300;
let BulletWait=15;

task Shot
{
	loop
	{
		let angle=rand(0,360);
		ascent(let i in 0..LineWay)
		{
			LineShot(angle+i*360/LineWay,1,41);
		}
		wait(90);
		ascent(let i in 0..LineWay)
		{
			LineShot(-12+angle+i*360/LineWay,-1,46);
		}
		wait(LineWait);
	}
}

task LineShot(angle,dir,graphic)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, GetX, GetY);
	Obj_SetSpeed(obj, 25);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, 0);
	ObjShot_SetBombResist(obj,true);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAutoDelete(obj,false);
	let X=Obj_GetX(obj);//毎フレーム座標を記録するための値
	let Y=Obj_GetY(obj);//毎フレーム座標を記録するための値
	let VanishJudg=false;//画面外にいって消えたかを判定。

	loop(13)
	{
		Obj_SetAngle(obj, angle);
		angle+=5*dir;
		wait(1);
		if(DistanceToPlayer(Obj_GetX(obj),Obj_GetY(obj))>50 && Obj_GetX(obj)!=X)
		{
			X=Obj_GetX(obj);
			SpShot(Obj_GetX(obj),Obj_GetY(obj),graphic);
		}
	}
	Obj_Delete(obj);
}

task SpShot(let x,let y,graphic)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, 0);
	Obj_SetAngle(obj, atan2(GetY-y,GetX-x));
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, 5);
	//ObjShot_SetBombResist(obj,true);

	Obj_SetAutoDelete(obj,false);

	let speed=0;

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

	wait(15);
	loop(105)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		Obj_SetSpeed(obj, speed);
		if(speed<2)
		{
		speed+=0.01;
		}
		if(speed<4)
		{
		speed+=0.025;
		}
		if(Obj_BeDeleted(obj)){break;}
		wait(1);
	}
	Obj_SetAutoDelete(obj,true);
	while(!Obj_BeDeleted(obj))
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		Obj_SetSpeed(obj, speed);
		if(speed<2)
		{
		speed+=0.01;
		}
		if(speed<4)
		{
		speed+=0.025;
		}
		wait(1);
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		if(graphic==41)
		{
			BulletColor("RED");
				EffectSet(X,Y,"RED");
		}
		if(graphic==46)
		{
			BulletColor("BLUE");
				EffectSet(X,Y,"BLUE");
		}
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		if(graphic==41)
		{
			EffectSet(X,Y,"RED");
		}
		if(graphic==46)
		{
			EffectSet(X,Y,"BLUE");
		}
	}

}

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