#東方弾幕風
#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 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 {
	DrawBossAndShadow( imgBoss,255,255,0);
	DrawBoss( imgBoss );
    }

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

	}

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

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

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
	{
	DoubleSpoilerSetMovePosition02(PX,PY,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"
}
