#東方弾幕風
#Title[円心剣｢月輪の太刀｣]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

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

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

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_youmu.png"; 
    let imgMoon=GetCurrentScriptDirectory ~ "..\img/NuclearSpark.png"; 
let imgMenuEffect=GetCurrentScriptDirectory ~ "..\img/effect_tiny.png";
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 112;


   @Initialize {
	SetBulletScorePoint(12,130);
     LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	SetShotAutoDeleteClip(8,8,8,8);
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,7,309,261,334);
        LoadGraphic(imgBoss);
        LoadGraphic(imgMoon);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

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

    @DrawLoop {
	DrawBoss( imgBoss );
    }

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

	}

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

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

task MoveEffect
{
loop(10)
{
	MomijiEffect;
	MomijiEffect;
	yield;
}
}

task MomijiEffect//紅葉の設定
{
		let R=255;let G=rand(200,255); 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 TMove// 浮揚と移動
{
	Slow(1);
	SetAction(ACT_CHARGE,60);
//	SetColor(255,255,0);
//	Concentration01(60);
//	SetColor(255,255,255);
	Concentration03(60,255,255,0);

	let PX=GetPlayerX;
	let PY=GetPlayerY;

	wait(55);
	Slow(0);
	loop
	{
	MoveEffect;
	DoubleSpoilerSetMovePosition02(PX,PY,10);
	SetAction(ACT_SLASH_H,10);
	wait(10);
	SetAction(ACT_SLASH_V,5);
	wait(5);
	SetAction(ACT_SLASH_H,5);
	wait(80);
	Slow(1);
	SetAction(ACT_CHARGE,90);
//	SetColor(255,255,0);
//	Concentration01(90);
//	SetColor(255,255,255);
	Concentration03(90,255,255,0);
	PX=GetPlayerX;
	PY=GetPlayerY;
	wait(85);
	Slow(0);
	//MagicCircleEffectTask;
	}
}

task Sword
{
	let dirangle=GetAngleToPlayer;
	wait(55);
	let angle=0;
	let rudius=30;
	let obj = Obj_Create(OBJ_SINUATE_LASER);
	Obj_SetPosition(obj, GetX+rudius*cos(angle), GetY+rudius*sin(angle));
	ObjShot_SetGraphic(obj, 243);
	ObjSinuateLaser_SetLength(obj,36);
	ObjSinuateLaser_SetWidth(obj,5);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAutoDelete(obj,false);
	loop(10)
	{
		Obj_SetPosition(obj, GetX+rudius*cos(angle), GetY+rudius*sin(angle));
		Obj_SetAngle(obj, dirangle);
		yield;
	}
	loop(36)
	{
		Obj_SetPosition(obj, GetX+rudius*cos(angle), GetY+rudius*sin(angle));
		Obj_SetAngle(obj, angle+90);
		angle+=20;
		yield;
	}
	Obj_Delete(obj);
}

task Shot
{
	Sword;
	wait(75);
	loop
	{
		moon;
		wait(105);
		Sword;
		wait(75);
	}
}

let ShotNum=15;
let ShotWay=30;
let speed=3.25;

task step
{
	while(!StepUp1){yield;}
	ShotNum=20;
	ShotWay=36;
	speed=3.75;
	while(!StepUp2){yield;}
	ShotNum=25;
	ShotWay=40;
	speed=4.25;
	while(!StepUp3){yield;}
	ShotNum=30;
	ShotWay=45;
	speed=4.75;
}

task moon
{
MoonEffect;
let r=0;
let way=36;
loop(ShotNum)
{
let rangle=rand(0,360);
	ascent(let i in 0..ShotWay)
	{
		DoubleSpoilerCreateShot01(GetX+r*cos(rangle+i*360/ShotWay),GetY+r*sin(rangle+i*360/ShotWay),speed,rangle+i*360/ShotWay,83,10,SetBulletColor[2],0,1);
	}
r+=10;
wait(120/ShotNum);
}
}

task MoonEffect
{
		let sc=0.0;

  		let objW = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(objW,GetX,GetY);
		ObjEffect_SetTexture(objW,imgMoon);
		ObjEffect_SetPrimitiveType(objW, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(objW, ADD);
		ObjEffect_SetScale(objW, sc,sc);
		ObjEffect_CreateVertex(objW, 4);
		ObjEffect_SetVertexXY(objW, 0, -100, -100);
		ObjEffect_SetVertexXY(objW, 1,  100, -100);
		ObjEffect_SetVertexXY(objW, 2,  100,  100);
		ObjEffect_SetVertexXY(objW, 3, -100,  100);
		
		ObjEffect_SetVertexUV(objW, 0,  20,  20);
		ObjEffect_SetVertexUV(objW, 1,  236, 20);
		ObjEffect_SetVertexUV(objW, 2, 236,  236);
		ObjEffect_SetVertexUV(objW, 3, 20, 236);

		ObjEffect_SetVertexColor(objW,0,100,255,255,0);
		ObjEffect_SetVertexColor(objW,1,100,255,255,0);
		ObjEffect_SetVertexColor(objW,2,100,255,255,0);
		ObjEffect_SetVertexColor(objW,3,100,255,255,0);

		loop(120)
		{
			sc+=10*ShotNum/120;
			ObjEffect_SetScale(objW, sc/100,sc/100);
			Obj_SetPosition(objW,GetX,GetY);
		ObjEffect_SetVertexColor(objW,0,100,255,255,0);
		ObjEffect_SetVertexColor(objW,1,100,255,255,0);
		ObjEffect_SetVertexColor(objW,2,100,255,255,0);
		ObjEffect_SetVertexColor(objW,3,100,255,255,0);

			wait(1);
		}
	let a=0;
		loop(30)
		{
			a++;
			sc+=10*ShotNum/120;
			ObjEffect_SetScale(objW, sc/100,sc/100);
			Obj_SetPosition(objW,GetX,GetY);
			ObjEffect_SetVertexColor(objW,0,100-a*100/30,255,255,0);
			ObjEffect_SetVertexColor(objW,1,100-a*100/30,255,255,0);
			ObjEffect_SetVertexColor(objW,2,100-a*100/30,255,255,0);
			ObjEffect_SetVertexColor(objW,3,100-a*100/30,255,255,0);

			wait(1);
		}
		Obj_Delete(objW);
}

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