#東方弾幕風
#Title[秋符「フォーリンフォール」]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

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

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

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_sizuha.png"; 
let imgMenuEffect=GetCurrentScriptDirectory ~ "..\img/effect_tiny.png";

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


   @Initialize {
	SetShotAutoDeleteClip(100,16,100,16);
	SetBulletScorePoint(12,40);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
        LoadGraphic(imgBoss);
        LoadGraphic(imgMenuEffect);
        SetTexture(imgBoss);
//	InitializeAction();
	DrawSpellName(imgSpellName,5,408,364,434);
	SetY(GetClipMinY-32);
	SetX(GetCenterX-32);
        TMain;
    }

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

    @DrawLoop {
	SetTexture(imgBoss);
	SetGraphicRect(0,0,128,128);
	DrawBossAndShadow( imgBoss,255,127,0);
	DrawGraphic(GetX,GetY);
    }

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

	}

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

sub standBy//初期位置へ
{
	AppearEffect;
	SetAction(ACT_MOVE, 30);
	let wIni = 30;
	SetMovePosition03(xIni, yIni, 10,5);
	//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);
	}
}

task AppearEffect
{
loop(30)
{
	MomijiEffect;
	yield;
}
}

task MomijiEffect//紅葉の設定
{
		let R=255;let G=rand(0,165); let B=0;
		let Angle=rand(0,360);
		let Speed=rand(0.2,0.4);
		let RotateAngle=rand(2,10);
		let Zangle=rand(0,360);
		let dir=rand_int(0,1)*2-1;
		let Scale=0.6;
		let Alpha=150;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMenuEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -15, -15);
		ObjEffect_SetVertexXY(obj, 1, 15,  -15);
		ObjEffect_SetVertexXY(obj, 2, 15, 15);
		ObjEffect_SetVertexXY(obj, 3,  -15,  15);
		
		ObjEffect_SetVertexUV(obj, 0,  2,  24);
		ObjEffect_SetVertexUV(obj, 1,  32, 24);
		ObjEffect_SetVertexUV(obj, 2, 32,  55);
		ObjEffect_SetVertexUV(obj, 3, 2, 55);
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		Obj_SetPosition(obj,GetX+10*cos(Angle),GetY+10*sin(Angle));
		Obj_SetAngle(obj,Angle);
		Obj_SetSpeed(obj,Speed);

		loop(30)
		{
			ObjEffect_SetAngle(obj,0,0,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Zangle+=RotateAngle*dir;
			Scale-=0.02;
			yield;
		}
		Obj_Delete(obj);
}

task Shot
{
loop
{
	LShot(1);
	wait(180);
	LShot2(-1);
	wait(120);
	Concentration03(60,255,127,0);
	wait(60);
	MiniShot(1);
	wait(20);
	MiniShot(-1);
	wait(20);
	MagicCircleEffectTask;
	wait(20);
	DoubleSpoilermoveToPlayer(rand(20, 40), rand(-20, 20), 30,
                     GetClipMinX + 80, GetClipMinY +  96,
                     GetClipMaxX - 80, GetClipMinY + 144);	
}
}

task LShot(dir)
{
	loop(180)
	{
		SetShotColor(255,200,200);
		LeafShot(rand(GetClipMinX-80*dir,GetClipMaxX-16*dir),GetClipMinY,rand(2,5),90,41,5,dir,"RED");
		wait(1);
	}
}

task LShot2(dir)
{
	loop(180)
	{
		SetShotColor(255,255,200);
		LeafShot(rand(GetClipMinX-16*dir,GetClipMaxX-80*dir),GetClipMinY+1,rand(2,5),90,43,5,dir,"YELLOW");
		wait(1);
	}
}

task MiniShot(dir)
{
let angle=rand(0,360);
	ascent(let i in 0..180)
	{
		SetShotColor(255,165,0);
		DoubleSpoilerCreateShot01(GetX,GetY,1.5+0.5*(i%5),angle+i*2.0*dir,2,10,"ORANGE",0,1);
	}
}

task LeafShot(let x,let y,let speed,let angle,let graphic,let delay,let dir,setgraphic)
{
	let StandardSpeed=speed;
	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);

	let X=Obj_GetX(obj);//毎フレーム座標を記録するための値
	let Y=Obj_GetY(obj)-10;//毎フレーム座標を記録するための値

	let gradangle=rand(78,82);
	loop(15)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(obj)){break;}
		Obj_SetSpeed(obj, speed);
		speed-=(StandardSpeed-1.0)/30;
		yield;
	}
	loop(15)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(obj)){break;}
		angle-=gradangle/30*dir;
		speed-=(StandardSpeed-1.0)/30;
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, speed);
		yield;
	}
	loop(15)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(obj)){break;}
		angle-=gradangle/30*dir;
		Obj_SetAngle(obj, angle);
		yield;
	}
	let aspeed=rand(1/50,1/25);
	loop(60)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(obj)){break;}
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, speed);
		speed+=aspeed;
		angle+=80/60*dir;
		yield;
	}
	while(Obj_GetY(obj)<320)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(obj)){break;}
		Obj_SetSpeed(obj, speed);
		speed+=aspeed;
		yield;
	}
///////////////////////////////////////////////////////////
	StandardSpeed=speed;
	loop(15)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(obj)){break;}
		Obj_SetSpeed(obj, speed);
		speed-=(StandardSpeed-1.0)/30;
		yield;
	}
	loop(15)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(obj)){break;}
		angle-=gradangle/30*dir;
		speed-=(StandardSpeed-1.0)/30;
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, speed);
		yield;
	}
	loop(15)
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_BeDeleted(obj)){break;}
		angle-=gradangle/30*dir;
		Obj_SetAngle(obj, angle);
		yield;
	}
	while(!Obj_BeDeleted(obj))
	{
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, speed);
		speed+=1/60;
		angle+=80/60*dir;
		yield;
	}
	if(GetCommonDataDefault("Shooting",false))
	{
		if(X<GetClipMaxX && X>GetClipMinX && Y<GetClipMaxY && Y>GetClipMinY)
		{
		BasePoint(40);
		BulletColor(setgraphic);
		EffectSet(X,Y,setgraphic);
		}
	}
	if(GetCommonDataDefault("EndDefeatBullet",false))
	{
		EffectSet(X,Y,setgraphic);
	}
}

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