#東方弾幕風
#Title[木符「シルフィウィスパー」]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

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

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

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

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


   @Initialize {
	SetBulletScorePoint(12,70);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	SetShotAutoDeleteClip(8,8,8,8);
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,9,7,365,33);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
	SetX(xIni);
	SetY(yIni);
        TMain;
    }

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

let appearecount=0;

    @DrawLoop {
	if(appearecount<30)
	{
	appearecount+=1;
	}
	SetAlpha(255/30*appearecount);
	DrawBoss( imgBoss );
    }

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

	}

    // メインタスク
task TMain 
{
	yield;
	BossShadowAnimation(imgBoss,0,170,60,225);
	standBy;
	TMove;
	Shot;
	Shot2;	
}

sub standBy//初期位置へ
{
	AppearEffect;
	let wIni = 30;
	wait(wIni);
}

task TMove// 浮揚と移動
{
	loop
	{
	let angle=0;
	let y =GetY;
	loop(120)
	{
		SetY(y+4*sin(angle));
		yield;
		angle+=3;
	}
	DoubleSpoilermoveToPlayer(rand(40, 60), rand(-30, 30), 30,
                     GetClipMinX + 48, GetClipMinY +  80,
                     GetClipMaxX - 48, GetClipMinY + 144);
	MagicCircleEffectTask;
	}
}

task AppearEffect
{
		let Scale=0.5;
		let Zangle=0;
		let Xangle=0;
  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetTexture(obj,DoubleSpoilerimgCircle);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, Scale,Scale);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -128, -128);
		ObjEffect_SetVertexXY(obj, 1,  128, -128);
		ObjEffect_SetVertexXY(obj, 2,  128,  128);
		ObjEffect_SetVertexXY(obj, 3, -128,  128);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  256, 0);
		ObjEffect_SetVertexUV(obj, 2, 256,  256);
		ObjEffect_SetVertexUV(obj, 3, 0, 256);
		loop(30)
		{
			Xangle+=3;
			Zangle+=6;
			ObjEffect_SetAngle(obj,Xangle,0,Zangle);
			yield;
		}
		Obj_Delete(obj);
}

task Shot2
{
while(!StepUp1){yield;}
let w=90;
let dir=1;
	loop
	{
		loop(7)
		{
			SetShotColor(200,255,200);
			DoubleSpoilerCreateShot01(rand(GetClipMinX-64,GetClipMaxX+64), GetClipMinY,rand(2,3),w,44,30,SetBulletColor[3],0,2);
			SetShotColor
(255,255,255);
		}
		if(w<=170 && dir==1)
		{
			w+=4;
		}
		if(w>=10 && dir==-1)
		{
			w-=4;
		}
		if(w>=170)
		{
			dir=-1;
			wait(30);
		}
		if(w<=10)
		{
			dir=1;
			wait(30);
		}
	wait(6);
	}
}

task Shot
{
let w=90;
let dir=1;
	loop
	{
		loop(8)
		{
			DoubleSpoilerCreateShot01(rand(GetClipMinX-64,GetClipMaxX+64), GetClipMinY,rand(2,3),w,44,30,SetBulletColor[3],0,2);
		}
		if(w<=170 && dir==1)
		{
			w+=4;
		}
		if(w>=10 && dir==-1)
		{
			w-=4;
		}
		if(w>=170)
		{
			dir=-1;
			wait(30);
		}
		if(w<=10)
		{
			dir=1;
			wait(30);
		}
	wait(4);
	}
}

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