#東方弾幕風
#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_iku.png"; 

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


   @Initialize {
	SetBulletScorePoint(12,120);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	SetShotAutoDeleteClip(8,8,8,8);
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,4,507,509,533);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
	SetX(GetClipMinX);
	SetY(GetCenterY);
        TMain;
    }

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


    @DrawLoop {
	DrawBoss( imgBoss );
    }

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

	}

    // メインタスク
task TMain 
{
	yield;
	BossShadowAnimation(imgBoss,0,255,255,127);
	standBy;
	TMove;
	Shot;
	step;
}

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

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

let LightningWay=6;

task step
{
	while(!StepUp1){yield;}
	LightningWay=7;
	while(!StepUp2){yield;}
	LightningWay=8;
	while(!StepUp3){yield;}
	LightningWay=9;
	while(!StepUp4){yield;}
	LightningWay=10;
}

task Shot
{
let angle=rand(0,360);
let dir=rand_int(0,1)*2-1;
let graphic1=11;
let graphic2=14;
	loop
	{
		SetAction(ACT_SHOT_A,60);
		ascent(let i in 0..LightningWay)
		{
			LightningShot(angle+360/LightningWay*i,dir,graphic1);
		}
		dir=dir*-1;
		wait(120);
		//SetAction(ACT_SHOT_A,30);
		ascent(let i in 0..LightningWay)
		{
			LightningShot(angle+360/LightningWay*i,dir,graphic2);
		}
		dir=dir*-1;
		wait(180);
	}
}

task LightningShot(Angle,dir,graphic)
{
		let StandardAngle=Angle;

		let SX=GetX;
		let SY=GetY;
		let PX=SX;
		let PY=SY;
		let StandardAnglePlus=5*dir;
		let RandumWide=0;
		while (SX>GetClipMinX-32 && SX<GetClipMaxX+32 && SY>GetClipMinY-32 && SY<GetClipMaxY+32)
		{
			loop (1)
			{
				if(StandardAngle>Angle)
				{
					Angle+=rand(0,RandumWide);
				}
				else
				{
					Angle-=rand(0,RandumWide);
				}
				SX+=10*cos(Angle);
				SY+=10*sin(Angle);
				Lightning(PX,PY,SX,SY,graphic);
				PX=SX;
				PY=SY;
				StandardAngle+=StandardAnglePlus;
				if(StandardAnglePlus!=0)
				{
				StandardAnglePlus-=0.1*dir;
				}
				if(RandumWide<90)
				{
				RandumWide+=10;
				}
			}
			yield;
		}
}

	task Lightning(PX,PY,SX,SY,graphic)
	{
		let color;
		if(graphic==11){color="YELLOW"}
		if(graphic==14){color="BLUE"}
/*
		let Dobj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(Dobj, (PX+SX)/2,(PY+SY)/2);
		ObjShot_SetGraphic(Dobj, 41);
		Obj_SetAlpha(Dobj,0);
		Obj_SetCollisionToPlayer(Dobj,false);
*/
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj,PX,PY);
		Obj_SetAngle(obj,atan2(SY-PY,SX-PX));
		ObjShot_SetDelay(obj,10);
		ObjShot_SetGraphic(obj,graphic+146);
		ObjLaser_SetLength(obj,((SX-PX)^2+(SY-PY)^2)^(1/2)*1.5);
		ObjLaser_SetWidth(obj,8);
		ObjLaser_SetSource(obj,false);
		Obj_SetCollisionToPlayer(obj,false);
		ObjShot_SetBombResist(obj,false);

		loop(30)
		{
			if(SX>GetClipMinX && SX<GetClipMaxX && SY>GetClipMinY && SY<GetClipMaxY && !OnPlayerMissed)
			{
			if(Obj_BeDeleted(obj)){EffectSet((PX+SX)/2,(PY+SY)/2,color);BulletColor(color);break;}
			}
			yield;
		}
		if(!Obj_BeDeleted(obj))
		{
		DoubleSpoilerCreateShot02((PX+SX)/2,(PY+SY)/2,0,atan2(SY-PY,SX-PX)+rand(-10,10),0.02,rand(1,2),graphic,10,color,0,1);
		}
		Obj_Delete(obj);
	}

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