#東方弾幕風
#Title[新星｢地底の原始太陽｣]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

let Norma=5;//撮影枚数の設定
let SpellTimer=7200;//制限時間の設定（フレーム単位）
let StepUp=[1,2,3,4];

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

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_utuho.png"; 
    let imgNuclear =GetCurrentScriptDirectory ~ "..\img/s_shot.png"; 
    let imgNuclearWave =GetCurrentScriptDirectory ~ "..\img/NuclearWave2.png"; 

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


   @Initialize {
	SetBulletScorePoint(12,0);
	SetShotAutoDeleteClip(8,8,8,8);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,6,274,291,300);
        LoadGraphic(imgBoss);
        LoadGraphic(imgNuclear);
        LoadGraphic(imgNuclearWave);
        SetTexture(imgBoss);
	InitializeAction();
	SetX(GetClipMaxX);
	SetY(GetClipMinY-150);
        TMain;
    }

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

    @DrawLoop {
	DrawBossAndShadow( imgBoss,255,69,0);
	DrawBoss( imgBoss );
    }

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

	}

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

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


task Shot
{
	Concentration01(30);
	wait(30);
	while(!StepUp1)
	{
	SetAction(ACT_SUN,240);
	loop(3)
	{
		if(!StepUp1)
		{
			CreateEnemyFromScript("Familiar", GetX, GetY,2, GetAngleToPlayer, 1);
		}
		loop(60)
		{
			if(StepUp1){break;}
			wait(1);
		}
	}
		if(!StepUp1)
		{
			CreateEnemyFromScript("Familiar", GetX, GetY,2, GetAngleToPlayer, 1);
		}
		loop(270)
		{
			if(StepUp1){break;}
			wait(1);
		}
		Concentration01(30);
		loop(30)
		{
			if(StepUp1){break;}
			wait(1);
		}
	}
	SetAction(ACT_STAND,31);
	wait(1);
	Concentration01(30);
	wait(30);
	while(!StepUp2)
	{
	SetAction(ACT_SUN,300);
	loop(4)
	{
		if(!StepUp2)
		{
			CreateEnemyFromScript("Familiar", GetX, GetY,2, GetAngleToPlayer, 1);
		}
		loop(60)
		{
			if(StepUp2){break;}
			wait(1);
		}
	}
		if(!StepUp2)
		{
			CreateEnemyFromScript("Familiar", GetX, GetY,2, GetAngleToPlayer, 1);
		}
		loop(270)
		{
			if(StepUp2){break;}
			wait(1);
		}
		Concentration01(30);
		loop(30)
		{
			if(StepUp2){break;}
			wait(1);
		}
	}
	SetAction(ACT_STAND,31);
	wait(1);
	Concentration01(30);
	wait(30);
	while(!StepUp3)
	{
	SetAction(ACT_SUN,360);
	loop(5)
	{
		if(!StepUp3)
		{
			CreateEnemyFromScript("Familiar", GetX, GetY,2, GetAngleToPlayer, 1);
		}
		loop(60)
		{
			if(StepUp3){break;}
			wait(1);
		}
	}
		if(!StepUp3)
		{
			CreateEnemyFromScript("Familiar", GetX, GetY,2, GetAngleToPlayer, 1);
		}
		loop(210)
		{
			if(StepUp3){break;}
			wait(1);
		}
		Concentration01(30);
		loop(30)
		{
			if(StepUp3){break;}
			wait(1);
		}
	}
	SetAction(ACT_STAND,30);
	wait(1);
	Concentration01(30);
	wait(30);
	while(!StepUp4)
	{
	SetAction(ACT_SUN,270);
	loop(9)
	{
		if(!StepUp4)
		{
			CreateEnemyFromScript("Familiar", GetX, GetY,2, GetAngleToPlayer, 1);
		}
		loop(30)
		{
			if(StepUp4){break;}
			wait(1);
		}
	}
		if(!StepUp4)
		{
			CreateEnemyFromScript("Familiar", GetX, GetY,2, GetAngleToPlayer, 1);
		}
		loop(210)
		{
			if(StepUp4){break;}
			wait(1);
		}
		Concentration01(30);
		loop(30)
		{
			if(StepUp4){break;}
			wait(1);
		}
	}
	SetAction(ACT_STAND,30);
	wait(1);
	Concentration01(30);
	wait(30);
	loop
	{
	SetAction(ACT_SUN,360);
	loop(11)
	{

		CreateEnemyFromScript("Familiar", GetX, GetY,2, GetAngleToPlayer, 1);
		loop(30)
		{
			wait(1);
		}
	}
		CreateEnemyFromScript("Familiar", GetX, GetY,2, GetAngleToPlayer, 1);
		loop(210)
		{
			wait(1);
		}
		Concentration01(30);
		loop(30)
		{
			wait(1);
		}
	}
}

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


CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer, 0, RED01);
///////////////////////////////////////////////////////////////////////////////////////
script_enemy Familiar{
let StepUp=[];
#include_function ".\..\txt/DoubleSpoilerDataServant.txt"

       let out=false;
       let gr=GetArgument;
    let imgNuclear =GetCurrentScriptDirectory ~ "..\img/s_shot.png"; 
    let imgNuclearWave =GetCurrentScriptDirectory ~ "..\img/NuclearWave2.png"; 
	let exp=2.71828;
	let size=0;
	let VanishFlag=false;
       @Initialize{
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	SetLife(2000);
	//SetDefault(GetArgument);
	Tmain;
       }
       @MainLoop {
AddLife(1);
        SetCollisionB(GetX, GetY, size);
if(GetCommonDataDefault("TimeStop",false)==true)
{
	SetSpeed(0);
}
	DoubleSpoilerYield;
          }
       @DrawLoop {

       }
       @Finalize{

	}

task Tmain
{
	effect;
	DoubleSpoilerSetMovePosition03(GetPlayerX,GetPlayerY,10,8);
	shot;
	eraze;
}

task effect
{
		let sc=0.5;
  		let objE = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(objE,GetX,GetY);
		ObjEffect_SetTexture(objE,imgNuclear);
		ObjEffect_SetPrimitiveType(objE, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(objE, ADD);
		ObjEffect_SetScale(objE, sc,sc);
		ObjEffect_CreateVertex(objE, 4);
		ObjEffect_SetVertexXY(objE, 0, -128, -128);
		ObjEffect_SetVertexXY(objE, 1,  128, -128);
		ObjEffect_SetVertexXY(objE, 2,  128,  128);
		ObjEffect_SetVertexXY(objE, 3, -128,  128);
		
		ObjEffect_SetVertexUV(objE, 0,  0,  0);
		ObjEffect_SetVertexUV(objE, 1,  256, 0);
		ObjEffect_SetVertexUV(objE, 2, 256,  256);
		ObjEffect_SetVertexUV(objE, 3, 0, 256);

		ObjEffect_SetVertexColor(objE,0,100,255,250,250);
		ObjEffect_SetVertexColor(objE,1,100,255,250,250);
		ObjEffect_SetVertexColor(objE,2,100,255,250,250);
		ObjEffect_SetVertexColor(objE,3,100,255,250,250);
	
		ObjEffect_SetLayer(objE,5);
		while((!Obj_BeDeleted(objE) && GetSpeed>0.1) || GetSpeed==0)
		{	
			Obj_SetPosition(objE,GetX,GetY);
			wait(1);
		}
		Obj_Delete(objE);
}

task shot
{
	NuClear;
	NuClearWave;
}

task NuClearWave
{
		let sc=0.0;

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

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

		while((!Obj_BeDeleted(objW) && GetSpeed>0.1) || GetSpeed==0)
		{	
			Obj_SetPosition(objW,GetX,GetY);
			wait(1);
		}

		loop(60)
		{
			sc+=1;
			ObjEffect_SetScale(objW, sc/10,sc/10);
			Obj_SetPosition(objW,GetX,GetY);

		ObjEffect_SetVertexColor(objW,0,100-sc*100/60,100,150,250);
		ObjEffect_SetVertexColor(objW,1,100-sc*100/60,100,150,250);
		ObjEffect_SetVertexColor(objW,2,100-sc*100/60,100,150,250);
		ObjEffect_SetVertexColor(objW,3,100-sc*100/60,100,150,250);

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

task NuClear
{
		let sc=0.0;

  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,GetX,GetY);
		ObjEffect_SetTexture(obj,imgNuclear);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, sc,sc);
		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);

	/*	ObjEffect_SetVertexColor(obj,0,100,255,250,250);
		ObjEffect_SetVertexColor(obj,1,100,255,250,250);
		ObjEffect_SetVertexColor(obj,2,100,255,250,250);
		ObjEffect_SetVertexColor(obj,3,100,255,250,250);
	*/

  		let objE = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(objE,GetX,GetY);
		ObjEffect_SetTexture(objE,imgNuclear);
		ObjEffect_SetPrimitiveType(objE, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(objE, ADD);
		ObjEffect_SetScale(objE, sc,sc);
		ObjEffect_CreateVertex(objE, 4);
		ObjEffect_SetVertexXY(objE, 0, -128, -128);
		ObjEffect_SetVertexXY(objE, 1,  128, -128);
		ObjEffect_SetVertexXY(objE, 2,  128,  128);
		ObjEffect_SetVertexXY(objE, 3, -128,  128);
		
		ObjEffect_SetVertexUV(objE, 0,  256,  0);
		ObjEffect_SetVertexUV(objE, 1,  512, 0);
		ObjEffect_SetVertexUV(objE, 2, 512,  256);
		ObjEffect_SetVertexUV(objE, 3, 256, 256);

	/*	ObjEffect_SetVertexColor(objE,0,100,255,250,250);
		ObjEffect_SetVertexColor(objE,1,100,255,250,250);
		ObjEffect_SetVertexColor(objE,2,100,255,250,250);
		ObjEffect_SetVertexColor(objE,3,100,255,250,250);
	*/
//////////////////////////////////////////////////////////////////////////////

	
/////////////////////////////////////////////////////////////////////////
		ObjEffect_SetLayer(obj,5);
		ObjEffect_SetLayer(objE,5);
ascent(let i in 0..12)
{
RoundShot(40*1.5,i*360/12);
}
		while((!Obj_BeDeleted(obj) && GetSpeed>0.1) || GetSpeed==0)
		{	
			Obj_SetPosition(obj,GetX,GetY);
			Obj_SetPosition(objE,GetX,GetY);
			wait(1);
		}
		while(!Obj_BeDeleted(obj))
		{
			if(GetLife!=2000)
			{
				Obj_Delete(obj);
				Obj_Delete(objE);
				size=0;
			}
			if(sc<1.0*4/6)
			{
			size+=40*1.5/15;
			sc+=4/6*0.10*2/3;
			}
			else{break;}
			ObjEffect_SetScale(obj, sc,sc);
			ObjEffect_SetScale(objE, sc,sc);
			Obj_SetPosition(obj,GetX,GetY);
			Obj_SetPosition(objE,GetX,GetY);
			wait(1);
		}
		loop(10)
		{
			if(!VanishFlag){break;}
			if(GetLife!=2000)
			{
				Obj_Delete(obj);
				Obj_Delete(objE);
				size=0;
			}
		wait(1)
		}
		BlueShot(obj);
		while(!Obj_BeDeleted(obj) && GetLife==2000)
		{	
			if(VanishFlag){break;}
			wait(1);
		}
		if(!VanishFlag && GetCommonDataDefault("DefeatBoss",false)==false)
		{
		if(!OnPlayerMissed)
		{
			BasePoint(3000);

			ascent(let i in 0..18)
			{
				let EffectR=rand(20,60);
				EffectSet(GetX+EffectR*cos(i*360/18),GetY+EffectR*sin(i*360/18),"RED");
			}
		}
		Obj_Delete(obj);
		Obj_Delete(objE);
		size=0;
		}
		else
		{
		loop(10)
		{
			if(!VanishFlag){break;}	
			size-=40*1.5/15;
			sc-=4/6*0.10*2/3;
			ObjEffect_SetScale(obj, sc,sc);
			ObjEffect_SetScale(objE, sc,sc);
			wait(1);
		}
	//	VanishEnemy;
		size=0;
		if(GetCommonDataDefault("EndDefeatBullet",false))
		{
			ascent(let i in 0..18)
			{
				let EffectR=rand(20,60);
				EffectSet(GetX+EffectR*cos(i*360/18),GetY+EffectR*sin(i*360/18),"RED");
			}
		}
		Obj_Delete(obj);
		Obj_Delete(objE);
		}
}

task BlueShot(obj)
{
let r=100*2/3;
while(!Obj_BeDeleted(obj) && !VanishFlag)
{
	let angle=rand(0,360);
	DoubleSpoilerCreateShot02(GetX+r*cos(angle),GetY+r*sin(angle),0,angle,0.01,1,BLUE01,10,"BLUE",0,1);
	wait(5);
}
}

task RoundShot(let r,let angle)
{
	let obj = Obj_Create(OBJ_SHOT);
	ObjShot_SetGraphic(obj, 121);
	ObjShot_SetDelay(obj, 0);
	ObjShot_SetBombResist(obj,true);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAlpha(obj,0);
	let X;
	let Y;
	let VanishJudg=false;
	let sc=0;
	while((!Obj_BeDeleted(obj) && GetSpeed>0.1) || GetSpeed==0)
	{
		Obj_SetPosition(obj, GetX,GetY);
		wait(1);
	}
	ObjShot_SetBombResist(obj,false);
	loop(15)
	{
		if(Obj_BeDeleted(obj)){break;}
		sc+=1/15;
		Obj_SetPosition(obj, GetX+r*sc*cos(angle),GetY+r*sc*sin(angle));	
		wait(1);
	}
	while(!Obj_BeDeleted(obj) && GetLife==2000)
	{
	if(VanishFlag){Obj_Delete(obj);}
	Obj_SetPosition(obj, GetX+r*cos(angle),GetY+r*sin(angle));
	wait(1);
	}
	if(!VanishFlag)
	{

	AddLife(-1);
	Obj_Delete(obj);
	}
}

task eraze
{
	wait(480);
	VanishFlag=true;
}

function wait(w)
{
    loop(w) {
	 yield; 
	}
}

function CsdDistanceToPlayer(X,Y,EX,EY)
{//距離を返す
	return(((X-EX)^2+(Y-EY)^2)^0.5);
}

} 