
#Title[スター]
#Text[]
#Image[.]
#BackGround[User] 
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_starsapphire.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
let TimeCounter=40*60;
let StandardTimeCounter=TimeCounter;
    @Initialize {
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
        SetLife(1650);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
	//MotionBlurEx(SHOT,300,200,ADD);
    }

    @MainLoop {
	SetCommonData("BossX",GetX);
	SetCommonData("BossY",GetY);
	SetCommonData("BossLife",GetLife);
	BulletNum=GetEnemyShotCount;
	TimeCounter-=1;
        yield;
    }

    @DrawLoop {
	DrawBoss( imgBoss );
    }

    @Finalize {
	DeleteAllEnemyWithoutBoss;
	SetCommonData("BossX",GetX);
	SetCommonData("BossY",GetY);
	SetCommonData("BossLife",GetLife);
	DeleteEnemyShotToItem(ALL);
		if(!IsTimeOut)
		{
		SetCommonData("DeleteBulletNum",BulletNum);
		SetCommonData("DeleteBulletX",GetX);
		SetCommonData("DeleteBulletY",GetY);
			if(GetCommonDataDefault("BitDefeatNum",0)==14)
			{
				ExtendItemSet(GetX,GetY,1);
			}
		}

	SetCommonData("VanishSignal",false);
	SetCommonData("TimeBonus",TimeCounter/StandardTimeCounter);
	SetCommonData("BossRate",200000);
    }

    // メインタスク
task TMain 
{
	yield;
	GetDamege;
	OutDamageRateZero;
	//Lissajous(0,84,166);
	BossShadowAnimation(imgBoss2,0,0,84,166);
	standBy;
	Collision;
	DamageRateChange;
	wait(60);
	Concentration01(30);
	wait(30);
	SpellDraw(10,6000);
	SetAction(ACT_SHOT_A,60);
	summon1;
	let count=0;
	let FSFlag=false;
	loop(990)
	{
		if(count==720)
		{
			SetAction(ACT_SHOT_A,60);
		}
		if(GetEnemyNum==1){break;}
		count+=1;
		if(GetCommonDataDefault("FullShotFlag",false)==true && !FSFlag)
		{
			SpellDraw(11,540);
			FSFlag=true;
		}
		yield;
	}

	if(GetCommonDataDefault("FullShotFlag",false)==true)
	{
		AchievementSet(87);
		wait(300);
	}
	SetAction(ACT_SHOT_B,60);
	summon2;
	wait(120);
	SetAction(ACT_SHOT_A,6000);
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}
	ZakoVanish;
}

task Collision
{
	loop(90)
	{
        SetCollisionA(GetX, GetY, 48);
	yield;
	}
	loop
	{
        SetCollisionA(GetX, GetY, 48);
        MSDSetCollisionB(GetX, GetY, 16);
	yield;
	}
}


task DamageRateChange
{
loop
{
	DamageRate=100-10*(GetEnemyNum-1);
	BombDamageRate=100-10*(GetEnemyNum-1);
yield;
}
}


task summon1
{
	ascent(i in 0..8)
	{
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 0, i);
	}
}

task summon2
{
	ascent(i in 1..4)
	{
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, 0, i);
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, 0, -i);
	}
}

task TMove
{
loop
{
//	SetMovePosition03(GetX+rand(-10,10), GetY+rand(-10,10), 20,5);
	wait(60);
}
}

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(xIni, yIni, 20,5);
}

////////////////////////////////////////////////////////////
task shotM
{
loop
{
	if(GetEnemyNum>1)
	{
	ascent(i in 0..24)
	{
	//CreateLaser01(GetX,GetY,4,GetAngleToPlayer+i*15,150,6,246,5);
	Laser01(GetX,GetY,4,GetAngleToPlayer+i*15,150,6,246,5);
	}
	wait(60);
	}
	else
	{
	ascent(i in 0..36)
	{
	//CreateLaser01(GetX,GetY,4,GetAngleToPlayer+i*10,150,6,246,5);
Laser01(GetX,GetY,4,GetAngleToPlayer+i*10,150,6,246,5);
	}
	wait(45);
	}
}


task Laser01(x,y,speed,angle,Slength,width,graphic,delay)
{
	let length=0;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,x,y);
	Obj_SetSpeed(obj,speed);
	Obj_SetAngle(obj,angle);
	ObjShot_SetGraphic(obj,graphic);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,width);
	ObjLaser_SetSource(obj,false);
	ObjShot_SetDelay(obj,delay);
	Obj_SetAutoDelete(obj,true);
	//Obj_SetCollisionToPlayer(obj,false);
	//ObjShot_SetBombResist(obj,true);
	let r=0;
	loop(Slength/speed)
	{
	//	LaserEffect(ObjLaser_GetEndX(obj)-speed*cos(angle),ObjLaser_GetEndY(obj)-speed*sin(angle),3,200,[0,84,166]);
		ObjLaser_SetLength(obj,length);
		length+=speed;
		yield;
	}
	Obj_SetSpeed(obj,speed);
	Obj_SetAngle(obj,angle);
	while(!Obj_BeDeleted(obj))
	{
	//	LaserEffect(ObjLaser_GetEndX(obj)-speed*cos(angle),ObjLaser_GetEndY(obj)-speed*sin(angle),3,200,[0,84,166]);
		Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
		yield;
	}
	Obj_Delete(obj);
}

	task LaserEffect(x,y,delay,Alpha,color)
	{
		let R=color[0];
		let G=color[1];
		let B=color[2];
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\Light.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, -32, -32);
		ObjEffect_SetVertexXY(obj, 1,32, -32);
		ObjEffect_SetVertexXY(obj, 2, 32, 32);
		ObjEffect_SetVertexXY(obj, 3, -32, 32);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  64, 0);
		ObjEffect_SetVertexUV(obj, 2, 64, 64);
		ObjEffect_SetVertexUV(obj, 3, 0,  64);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}

		Obj_SetPosition(obj,x,y);

		ObjEffect_SetLayer(obj,2);

		let Zangle=rand(0,360);
		ObjEffect_SetAngle(obj,0,0,Zangle);

		let Scale=0.8;
		loop(delay)
		{
			ObjEffect_SetScale(obj, Scale, Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=6;
			Scale-=0.8/delay;
			yield;
		}
		Obj_Delete(obj);
	}

}
//////////////////////////////////////////////////////////////////////
task shotE
{
loop
{
	if(GetEnemyNum>1)
	{
	ascent(i in 0..36)
	{
	CreateLaser01(GetX,GetY,4,GetAngleToPlayer+i*15,150,6,246,5);
	}
	wait(60);
	}
	else
	{
	ascent(i in 0..45)
	{
	CreateLaser01(GetX,GetY,4,GetAngleToPlayer+i*10,150,6,246,5);
	}
	wait(45);
	}
}
}
///////////////////////////////////////////////////////////////////////////
task shotA
{
ShotB;
loop
{
	StarShot;
	wait(240);
}

task ShotB
{
loop
{
	if(GetEnemyNum>1)
	{
	ascent(i in 0..36)
	{
	CreateShot01(GetX,GetY,4,GetAngleToPlayer+i*10,126,5);
	}
	wait(60);
	}
	else
	{
	ascent(i in 0..72)
	{
	CreateShot01(GetX,GetY,4,GetAngleToPlayer+i*5,126,5);
	}
	wait(30);
	}
}
}

task StarShot
{
		let speed=1.5;
		let angle=GetAngleToPlayer;
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, GetX,GetY);
		Obj_SetSpeed(obj, 0);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, 12);
		ObjShot_SetDelay(obj, 0);
		Obj_SetAutoDelete(obj,false);
		Obj_SetAlpha(obj,0);
		Obj_SetCollisionToPlayer(obj,false);
		ObjShot_SetBombResist(obj,true);
		//wait(30);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		let dir=rand_int(0,1)*2-1;
		ascent(i in 0..6)
		{
		StarLaser(obj,i*60,dir);
		}
		Obj_SetSpeed(obj, speed*0);
		loop(90)
		{
			yield;
		}
		Obj_SetSpeed(obj, speed);
		angle=GetAngleToPlayer;
		Obj_SetAngle(obj, angle);
		wait(450-90);
		Obj_Delete(obj);
}

task StarLaser(Cobj,angle,dir)
{
	let R=0;
	let length=R*3^0.5+3;
	let width=0;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,Obj_GetX(Cobj)+R*cos(angle),Obj_GetY(Cobj)+R*sin(angle));
	//Obj_SetSpeed(obj,speed);
	Obj_SetAngle(obj,angle+210);
	ObjShot_SetGraphic(obj,158);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,width);
	ObjLaser_SetSource(obj,false);
	ObjShot_SetDelay(obj,0);
	Obj_SetAutoDelete(obj,false);
	//Obj_SetAlpha(obj,0);
	//Obj_SetCollisionToPlayer(obj,false);
	ObjShot_SetBombResist(obj,true);

let count=0;
	while(!Obj_BeDeleted(Cobj))
	{
	//	if(count%2==1)
	//	{
		StarLaserEffect2(Obj_GetX(Cobj)+R*cos(angle),Obj_GetY(Cobj)+R*sin(angle),length,width,angle+210);
	//	StarShotEffect(Obj_GetX(Cobj)+R*cos(angle),Obj_GetY(Cobj)+R*sin(angle));
		//StarLaserEffect(Obj_GetX(Cobj)+R*cos(angle),Obj_GetY(Cobj)+R*sin(angle),length,width,angle+210,158,10);
	//	}
		Obj_SetPosition(obj,Obj_GetX(Cobj)+R*cos(angle),Obj_GetY(Cobj)+R*sin(angle));
		Obj_SetAngle(obj,angle+210);
		ObjLaser_SetLength(obj,length);
		ObjLaser_SetWidth(obj,width);
		if(R<80)
		{
		R+=80/90;
		length=R*3^0.5+3;
		width+=28/360;
		}
		angle+=2*dir;
		count++;
		yield;
	}
}


task StarLaserEffect(x,y,length,width,angle,gra,delay)
{
	let alpha=255;
	let obj=Obj_Create(OBJ_LASER);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetAngle(obj,angle);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,width);
	ObjLaser_SetSource(obj,false);
	ObjShot_SetGraphic(obj,gra);
	ObjShot_SetDelay(obj,0);
	Obj_SetAutoDelete(obj,false);
	ObjShot_ToItem(obj,false);
	Obj_SetCollisionToPlayer(obj,false);
/*
	loop(255/delay)
	{
		Obj_SetAlpha(obj,alpha);
		alpha-=255/delay;
		yield;
	}
*/
	ObjShot_FadeDelete(obj);
}

task StarLaserEffect2(x,y,length,width,angle)
{
		let imgBer=csd ~ "../img/ber.png";
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjShot_SetBombResist(obj,true);
		ObjEffect_SetVertexXY(obj, 0, -0, -3);
		ObjEffect_SetVertexXY(obj, 1,length,  -3);
		ObjEffect_SetVertexXY(obj, 2,length, 3);
		ObjEffect_SetVertexXY(obj, 3,  -0,  3);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  228, 27);
		ObjEffect_SetVertexUV(obj, 2, 228, 33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);

		let Alpha=100;
		let R=255;
		let G=255;
		let B=255;

		R=0;
		G=84;
		B=166;


		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,angle);
		ObjEffect_SetAngle(obj,0,0,angle);

		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		loop(15)
		{
		Obj_SetPosition(obj,x,y);
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		Alpha-=100/15;
		//if(OnPlayerMissed){Alpha=0;}
		yield;
		}
		Obj_Delete(obj);
}


task StarShotEffect(x,y)
{
	let alpha=255;
	let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	//Obj_SetAngle(obj,angle);
	//Obj_SetAlpha(obj,0);
	ObjShot_SetGraphic(obj,126);
	ObjShot_SetDelay(obj,0);
	Obj_SetAutoDelete(obj,false);
	ObjShot_ToItem(obj,false);
	Obj_SetCollisionToPlayer(obj,false);
/*
	loop(5)
	{
		Obj_SetAlpha(obj,alpha);
		alpha-=255/5;
		yield;
	}
*/
	ObjShot_FadeDelete(obj);
}


}
////////////////////////////////////////////////////////////////////////
task ZakoVanish
{
	wait(300);
	SetCommonData("VanishSignal",true);
}



#include_function ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_Starsapphire.txt"
}
/////////////////////////////////////////////////////////////////////////////////////////////
script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
    @Initialize {
	BombDamageRate=10;
	//SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(340);
        SetDamageRateEx(100,10,0,0);
	TMain;
    }

    @MainLoop {
	BulletNum=GetEnemyShotCount;
        SetCollisionA(GetX, GetY, 36);
        MSDSetCollisionB(GetX, GetY, 12);
        yield;
    }

    @DrawLoop {
     //  DrawGraphic(GetX, GetY);
    }

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,10,0.3);
	if(!BeVanished && GetCommonDataDefault("BossLife",0)>0)
	{
		FinalizeItemSet(3);
		SetCommonData("BitDefeatNum",GetCommonDataDefault("BitDefeatNum",0)+1);
	}
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{

		}
		case("Extream")
		{

		}
		case("Apocalypse")
		{

		}
        }

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	ZakoEffect(255,0,0);
	ZakoEnemyLifeDisplay;
	move;

	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}

    }

task move
{
	let x=GetX;
	let y=GetY;
	let RX=0;
	let RY=0;
	let angle=45*num;
	loop(720)
	{
	SetX(x+RX*cos(angle));
	SetY(y+RY*sin(angle));
	if(RX<120)
	{
		RX+=2;
	}
	if(RY<60)
	{
		RY+=1;
	}
	angle+=0.5;
	yield;
	}

	if(GetEnemyNum!=9)
	{

	let AY=0;
	let AYplus=0;
	loop(270)
	{
	SetX(x+RX*cos(angle));
	SetY(y+RY*sin(angle)+AY);
	angle+=0.5;
	if(AYplus<2)
	{
		AYplus+=2/120;
	}
	AY+=AYplus;
	yield;
	}
	VanishEnemy;
	}
	else
	{
	loop(120)
	{
		SetCommonData("FullShotFlag",true);
		SetX(x+RX*cos(angle));
		SetY(y+RY*sin(angle));
		if(y<GetCenterY)
		{
		y+=2;
		}

		RX+=2;
		RY+=2.5;
		angle+=0.5;
		yield;
	}
	let Aangle=GetAngleToPlayer;
	x=GetPlayerX;
	y=GetPlayerY;
	let dis=((GetY-y)^2+(GetX-x)^2)^0.5;
	wait(90);
	SetAngle(Aangle);
	SetSpeed(dis/30);
	loop(30)
	{
	//	MagicExplosion(GetX,GetY,1.0,[0,84,166],60,60);
		yield;
	}
	yield;
	ascent(i in 0..15)
	{
	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,1+0.1*i,num*45,(2+0.2*i),0,0,134);
	SetShotDataA(0,30,NULL,NULL,(2+0.2*i)/2,0,0,134);
	SetShotDataA(0,90,NULL,NULL,0,0,0,134);
	FireShot(0);

	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,1+0.1*i,num*45,-(2+0.2*i),0,0,134);
	SetShotDataA(0,30,NULL,NULL,-(2+0.2*i)/2,0,0,134);
	SetShotDataA(0,90,NULL,NULL,0,0,0,134);
	FireShot(0);

	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,1+0.1*i,num*45+22.5,(2+0.2*i),0,0,134);
	SetShotDataA(0,30,NULL,NULL,(2+0.2*i)/2,0,0,134);
	SetShotDataA(0,90,NULL,NULL,0,0,0,134);
	FireShot(0);

	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,1+0.1*i,num*45+22.5,-(2+0.2*i),0,0,134);
	SetShotDataA(0,30,NULL,NULL,-(2+0.2*i)/2,0,0,134);
	SetShotDataA(0,90,NULL,NULL,0,0,0,134);
	FireShot(0);

	}
	VanishEnemy;
	}
}

task shotM
{
wait(60);
loop
{
let dir=0;
let angle=atan2(GetY-GetEnemyY,GetX-GetEnemyX);
let angleplus=1;
loop(24)
{
		ascent(let j in 0..1)
		{
			CreateShot01(GetX,GetY,1.75+0.5*j,angle,126,5);
			CreateShot01(GetX,GetY,1.75+0.5*j,angle+90,126,5);
			CreateShot01(GetX,GetY,1.75+0.5*j,angle-90,126,5);
			CreateShot01(GetX,GetY,1.75+0.5*j,angle+180,126,5);
			wait(10);
		}
	angle+=angleplus;
	angleplus+=1;
}
wait(60);
let angle=270;
let speed=3;
loop(10)
{
CreateShot12(GetX,GetY,speed*cos(angle),speed*sin(angle),0,0.045,0,5,126,5);
CreateShot12(GetX,GetY,speed*cos(angle+15),speed*sin(angle+15),0,0.045,0,5,126,5);
CreateShot12(GetX,GetY,speed*cos(angle+30),speed*sin(angle+30),0,0.045,0,5,126,5);
CreateShot12(GetX,GetY,speed*cos(angle-15),speed*sin(angle-15),0,0.045,0,5,126,5);
CreateShot12(GetX,GetY,speed*cos(angle-30),speed*sin(angle-30),0,0.045,0,5,126,5);
wait(30);
}
wait(60);
if(GetEnemyNum!=9)
{
loop(27)
{
	CreateShot01(GetX,GetY,1.5,0,126,5);
	CreateShot01(GetX,GetY,1.5,180,126,5);
	wait(10);
}
}
else
{
	SpecialStarEffect;
	wait(120);
	Laser(GetX,GetY,GetAngleToPlayer,800,6,45,0,14);
	wait(90);

	loop(15)
	{
	let angle=rand(0,360);
		ascent(i in 0..15)
		{
		CreateShotA(0,GetX,GetY,5);
		SetShotDataA(0,0,0.1,angle+i*24,0,0.005,1,126);
		SetShotDataA(0,60,NULL,angle+i*24,0,0.01,1.0,126);
		FireShot(0);
		}
		wait(2);
	}

	wait(1200);
}

}

}
/////////////////////////////////////////////////
task shotE
{
wait(60);
loop(10)
{
starshot(GetX,GetY,4,GetAngleToPlayer+rand(-10,10),134,10);
wait(60);
}
wait(60);
if(GetEnemyNum!=9)
{
let angle=GetAngleToPlayer-180;
let speed=3;
loop(8)
{
CreateShot12(GetX,GetY,speed*cos(angle),speed*sin(angle),0,0.045,0,5,126,5);
CreateShot12(GetX,GetY,speed*cos(angle+15),speed*sin(angle+15),0,0.045,0,5,126,5);
CreateShot12(GetX,GetY,speed*cos(angle+30),speed*sin(angle+30),0,0.045,0,5,126,5);
CreateShot12(GetX,GetY,speed*cos(angle-15),speed*sin(angle-15),0,0.045,0,5,126,5);
CreateShot12(GetX,GetY,speed*cos(angle-30),speed*sin(angle-30),0,0.045,0,5,126,5);
wait(30);
}
}
else
{
	SpecialStarEffect;
	wait(120);
	Laser(GetX,GetY,GetAngleToPlayer,800,6,45,0,14);
	wait(90);

	loop(15)
	{
	let angle=rand(0,360);
		ascent(i in 0..15)
		{
		CreateShotA(0,GetX,GetY,5);
		SetShotDataA(0,0,0.1,angle+i*24,0,0.005,1,126);
		SetShotDataA(0,60,NULL,angle+i*24,0,0.01,1.0,126);
		FireShot(0);
		}
		wait(2);
	}

	wait(1200);
}
task starshot(x,y,speed,angle,gra,delay)
{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, gra);
		ObjShot_SetDelay(obj, delay);
		//Obj_SetAutoDelete(obj,false);
		//Obj_SetAlpha(obj,0);
		//Obj_SetCollisionToPlayer(obj,false);
		shot1;

	task shot1
	{
		loop
		{
			StarCreateShot02(Obj_GetX(obj),Obj_GetY(obj),0,Obj_GetAngle(obj)+rand(-55,55)+180,0.01,3,126,15);
			wait(15);
		}
	}
}

}
////////////////////////////////////////////////////
task shotA
{
wait(60);
//Laser;
let angle=atan2(GetY-GetEnemyY,GetX-GetEnemyX);
let AnglePlus=0;
let SpeedAngle=0;
let Speed=2+3*sin(SpeedAngle);
loop(90)
{
/*
	let angle=atan2(GetY-GetEnemyY,GetX-GetEnemyX);
	ascent(i in 0..12)
	{
	CreateShot01(GetX,GetY,1+i*0.20,angle,126,5);
	}
	wait(7);

	CreateLaser01(GetX,GetY,3,angle,90,6,246,5);
	wait(7);
	angle+=10;
*/
	let angle=atan2(GetY-GetEnemyY,GetX-GetEnemyX);
//	CreateShot01(GetX,GetY,3,angle,126,5);
	CreateShot01(GetX,GetY,3,angle+AnglePlus,126,5);
	CreateShot01(GetX,GetY,3,angle-AnglePlus,126,5);
	CreateShot01(GetX,GetY,3,angle+AnglePlus*2,126,5);
	CreateShot01(GetX,GetY,3,angle-AnglePlus*2,126,5);
	
	Speed=2+3*absolute(sin(SpeedAngle));
	//SpeedAngle+=6;
	AnglePlus+=6;
	wait(7);
}
wait(30);
if(GetEnemyNum!=9)
{
loop
{

let angle=GetAngleToPlayer-180;
let speed=3;
	ascent(i in 0..8)
	{
	CreateShot12(GetX,GetY,speed*cos(angle+i*45),speed*sin(angle+i*45),0,0.045,0,5,126,5);
	}
	wait(10);

}
}
else
{
	SpecialStarEffect;
	wait(120);
	Laser(GetX,GetY,GetAngleToPlayer,800,6,45,0,14);
	wait(90);

	loop(15)
	{
	let angle=rand(0,360);
		ascent(i in 0..15)
		{
		CreateShotA(0,GetX,GetY,5);
		SetShotDataA(0,0,0.1,angle+i*24,0,0.005,1,126);
		SetShotDataA(0,60,NULL,angle+i*24,0,0.01,1.0,126);
		FireShot(0);
		}
		wait(2);
	}

	wait(1200);
}
/*
	task Laser
	{
		loop(4)
		{
		StarLaser(GetPlayerX,GetPlayerY);
		wait(180);
		}
	}
*/
	task StarLaser(PX,PY)
	{
		ascent(i in 0..12)
		{
			ascent(j in -1..2)
			{
			CreateShot01(GetX,GetY,4+i*0.5,atan2(GetPlayerY-GetY,GetPlayerX-GetX)+j*30,134,5);
		//	CreateShot01(GetX,GetY,4+i*0.5,atan2(PY-GetY,PX-GetX)+j*30,134,5);
			}
			wait(5);
		}
/*
	let length=400;
	let width=30;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,GetX,GetY);
	//Obj_SetSpeed(obj,speed);
	//Obj_SetAngle(obj,angle);
	ObjShot_SetGraphic(obj,158);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,width);
	ObjLaser_SetSource(obj,false);
	ObjShot_SetDelay(obj,30);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAngle(obj,atan2(PY-GetY,PX-GetX));
	//Obj_SetCollisionToPlayer(obj,false);
	//ObjShot_SetBombResist(obj,true);
	let r=0;
	loop(120)
	{
		if(GetLife==0){break;}
		Obj_SetPosition(obj,GetX,GetY);
		Obj_SetAngle(obj,atan2(PY-GetY,PX-GetX));
		yield;
	}
	loop(30)
	{
		if(GetLife==0){break;}
		Obj_SetPosition(obj,GetX,GetY);
		ObjLaser_SetWidth(obj,width);
		width-=1;
		yield;
	}
	Obj_Delete(obj);	

*/	
	}

}
task StarCreateShot02(x,y,speed,angle,aspeed,maxspeed,gra,delay)
{
	ShotEffect(x,y,delay,255,0,84,200);
	wait(delay);
	CreateShot02(x,y,speed,angle,aspeed,maxspeed,gra,0);
}

task ShotEffect(x,y,delay,Alpha,R,G,B)
{
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\Light.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, -32, -32);
		ObjEffect_SetVertexXY(obj, 1,32, -32);
		ObjEffect_SetVertexXY(obj, 2, 32, 32);
		ObjEffect_SetVertexXY(obj, 3, -32, 32);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  64, 0);
		ObjEffect_SetVertexUV(obj, 2, 64, 64);
		ObjEffect_SetVertexUV(obj, 3, 0,  64);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}

		Obj_SetPosition(obj,x,y);

		ObjEffect_SetLayer(obj,2);

		let Zangle=rand(0,360);
		ObjEffect_SetAngle(obj,0,0,Zangle);

		let Scale=1.0;
		loop(delay)
		{
			ObjEffect_SetScale(obj, Scale, Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=6;
			Scale-=1.0/delay;
			yield;
		}
		Obj_Delete(obj);
}

task Laser(x,y,angle,length,width,delay,time,gra)
{
	let PX=GetPlayerX;
	let PY=GetPlayerY;
	//let Color=HueDifine(HueCount);;
	let lengthmax=length;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,x,y);
	Obj_SetAngle(obj,angle);
	ObjShot_SetGraphic(obj,gra);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,width);
	ObjLaser_SetSource(obj,false);
	ObjShot_SetDelay(obj,delay*2);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAlpha(obj,150);
	let dcount=30;
	let lcount=0;
	loop(delay*2)
	{
	//	Color=HueDifine(HueCount);
	//	SetShotColor(Color[0],Color[1],Color[2]);
		ObjShot_SetGraphic(obj,gra);
		EffectLaser(x,y,angle,length*lcount/30,width,0,2,gra);
		SetShotColor(255,255,255);
	//	Obj_SetPosition(obj,GetX,GetY);
		ObjLaser_SetLength(obj,length*lcount/30);
		if(lcount<30)
		{
		lcount+=1;
		}
	yield;
	}
	loop(time-delay-15)
	{
	//	Color=HueDifine(HueCount);
	//	SetShotColor(Color[0],Color[1],Color[2]);
		EffectLaser(x,y,angle,length,width*2,0,5,gra);
		ObjShot_SetGraphic(obj,gra);
		SetShotColor(255,255,255);
	//	Obj_SetPosition(obj,GetX,GetY);
		yield;
	}
	Obj_SetCollisionToPlayer(obj,false);

	Obj_Delete(obj);
}

task EffectLaser(x,y,angle,length,width,delay,time,gra)
{
	let obj = Obj_Create(OBJ_LASER);
	//Obj_SetPosition(obj,x,y);
	Obj_SetAngle(obj,angle);
	ObjShot_SetGraphic(obj,gra);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,width*rand(0.5,1));
	ObjLaser_SetSource(obj,false);
	ObjShot_SetDelay(obj,delay);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAlpha(obj,200);
	loop(time)
	{
	Obj_SetPosition(obj,x,y);
	ObjLaser_SetWidth(obj,width*rand(0.5,1));
	yield;
	}
	Obj_Delete(obj);
}

task SpecialStarEffect
{
	  	let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd ~ "..\img/effects.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

	ObjEffect_SetVertexUV(obj, 0, 0, 40);
	ObjEffect_SetVertexUV(obj, 1, 50, 40);
	ObjEffect_SetVertexUV(obj, 2, 50, 90);
	ObjEffect_SetVertexUV(obj, 3, 0, 90);

	ObjEffect_SetVertexXY(obj, 0, -25, -25);
	ObjEffect_SetVertexXY(obj, 1, 25,  -25);
	ObjEffect_SetVertexXY(obj, 2,  25,  25);
	ObjEffect_SetVertexXY(obj, 3,  -25, 25);

	let Alpha=200;
	let R=0;
	let G=84;
	let B=166;
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}

		ObjEffect_SetLayer(obj,3);

		let Zangle=rand(0,360);
		ObjEffect_SetAngle(obj,0,0,Zangle);

		let Scale=1.0;
		loop
		{
			Obj_SetPosition(obj,GetX,GetY);
			SpecialStarEffectBlur(GetX,GetY,Alpha,R,G,B);
			yield;
		}
	//	Obj_Delete(obj);
}

task SpecialStarEffectBlur(x,y,Alpha,R,G,B)
{
	  	let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd ~ "..\img/effects.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

	ObjEffect_SetVertexUV(obj, 0, 0, 40);
	ObjEffect_SetVertexUV(obj, 1, 50, 40);
	ObjEffect_SetVertexUV(obj, 2, 50, 90);
	ObjEffect_SetVertexUV(obj, 3, 0, 90);

	ObjEffect_SetVertexXY(obj, 0, -25, -25);
	ObjEffect_SetVertexXY(obj, 1, 25,  -25);
	ObjEffect_SetVertexXY(obj, 2,  25,  25);
	ObjEffect_SetVertexXY(obj, 3,  -25, 25);

		Obj_SetPosition(obj,x,y);
		ObjEffect_SetLayer(obj,3);

		let Zangle=rand(0,360);
		ObjEffect_SetAngle(obj,0,0,Zangle);

		let Balpha=Alpha;
		let Scale=1.0;
		loop(30)
		{
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			Alpha-=Balpha/30;
			yield;
		}
		Obj_Delete(obj);
}

task MagicExplosion(x,y,size,color,time,fadeintime)
{
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,csd ~ "..\img/effects.png");
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);

	ObjEffect_SetLayer(obj,2);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ADD);

	ObjEffect_SetVertexUV(obj, 0, 128, 0);
	ObjEffect_SetVertexUV(obj, 1, 256, 0);
	ObjEffect_SetVertexUV(obj, 2, 256, 128);
	ObjEffect_SetVertexUV(obj, 3, 128, 128);

	ObjEffect_SetVertexXY(obj, 0, -64, -64);
	ObjEffect_SetVertexXY(obj, 1, 64,  -64);
	ObjEffect_SetVertexXY(obj, 2,  64,  64);
	ObjEffect_SetVertexXY(obj, 3,  -64, 64);

	Obj_SetPosition(obj, x,y);
	let Alpha=100*time/60;
	let Xangle=rand(0,360);
	let Yangle=rand(0,360);
	let Zangle=rand(0,360);
	ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

	let Xsize=0;
	let Ysize=0;
	let SizePlus=rand(0.2,0.4)*time/60;
	let alphaPlus=100/fadeintime*time/60;
	let frame=0;
	let dir=rand_int(0,1)*2-1;
	loop(time)
	{
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
		ObjEffect_SetScale(obj,Xsize,Ysize);
		if(Alpha>0)
		{
			Alpha-=alphaPlus;
		}
		Xsize+=SizePlus;
		Ysize+=SizePlus;
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,color[0],color[1],color[2]);
		}
		frame++;
		yield;
	}
	Obj_Delete(obj);
}

#include_function ".\..\txt/StageEnemydata.txt"
}
///////////////////////////////////////////////////////////////////////////////////
script_enemy Familiar2 {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
    @Initialize {
	BombDamageRate=10;
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(320);
        SetDamageRateEx(100,10,0,0);

	TMain;
    }

    @MainLoop {
	BulletNum=GetEnemyShotCount;
        SetCollisionA(GetX, GetY, 36);
	MSDSetCollisionB(GetX, GetY, 12);
        yield;
    }

    @DrawLoop {
     //  DrawGraphic(GetX, GetY);
    }

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,10,0.3);
	if(!BeVanished && GetCommonDataDefault("BossLife",0)>0)
	{
		FinalizeItemSet(3);
		SetCommonData("BitDefeatNum",GetCommonDataDefault("BitDefeatNum",0)+1);
	}
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{

		}
		case("Extream")
		{

		}
		case("Apocalypse")
		{

		}
        }

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	ZakoEffect(255,0,0);
	ZakoEnemyLifeDisplay;
	move;

	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}

    }

task move
{
	SetMovePosition03(absolute(num)/num*100, 0, 20,5);
	wait(60);
	let X=absolute(num)/num*100;
	let Y=0;
	let angle=120*num;
	//if(num<0){angle+=60;}
	let r=0;
	loop
	{
		SetX(X+r*cos(angle));
		SetY(Y+r*sin(angle));
		angle+=absolute(num)/num;
		if(r<60)
		{
			r+=1;
		}
		yield;
	}
}

task shotM
{
wait(60);
loop
{
	let angle=atan2(GetEnemyY-GetY,GetEnemyX+absolute(num)/num*100-GetX);
	CreateShot01(GetX,GetY,2.5,angle,126,5);
	if(GetEnemyNum<=4)
	{
		CreateShot01(GetX,GetY,2.5,angle+180,126,5);
	}
	wait(5);
}
}
/////////////////////////////////////////////////
task shotE
{
wait(60);
loop
{
	loop(5)
	{
	let angle=atan2(GetEnemyY-GetY,GetEnemyX+absolute(num)/num*100-GetX);
	CreateShot01(GetX,GetY,2.5,angle,126,5);
	if(GetEnemyNum<=4)
	{
		CreateShot01(GetX,GetY,2.5,angle+180,126,5);
	}
	wait(2);
	}
	wait(4);
}
}
////////////////////////////////////////////////////
task shotA
{
wait(60);
loop
{
	let angle=atan2(GetEnemyY-GetY,GetEnemyX+absolute(num)/num*100-GetX);
	CreateLaser01(GetX,GetY,3,angle,165,6,246,5);
	if(GetEnemyNum<=4)
	{
		CreateLaser01(GetX,GetY,3,angle+180,150,6,14,5);
	}
	wait(6);
}

}

task StarCreateShot01(x,y,speed,angle,gra,delay)
{
	ShotEffect(x,y,delay,255,0,84,166);
	wait(delay);
	CreateShot01(x,y,speed,angle,gra,0);
}

task ShotEffect(x,y,delay,Alpha,R,G,B)
{
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\Light.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, -32, -32);
		ObjEffect_SetVertexXY(obj, 1,32, -32);
		ObjEffect_SetVertexXY(obj, 2, 32, 32);
		ObjEffect_SetVertexXY(obj, 3, -32, 32);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  64, 0);
		ObjEffect_SetVertexUV(obj, 2, 64, 64);
		ObjEffect_SetVertexUV(obj, 3, 0,  64);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}

		Obj_SetPosition(obj,x,y);

		ObjEffect_SetLayer(obj,2);

		let Zangle=rand(0,360);
		ObjEffect_SetAngle(obj,0,0,Zangle);

		let Scale=1.0;
		loop(delay)
		{
			ObjEffect_SetScale(obj, Scale, Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=6;
			Scale-=1.0/delay;
			yield;
		}
		Obj_Delete(obj);
}

#include_function ".\..\txt/StageEnemydata.txt"
}

#include_script ".\..\txt/EnemyShotData.txt"
