
#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 {
        SetTimer(TimeCounter/60);
        SetLife(1650);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
	//MotionBlurEx(SHOT,300,200,ADD);
    }

    @MainLoop {
	BulletNum=GetEnemyShotCount;
	TimeCounter-=1;
        yield;
    }

    @DrawLoop {
	DrawBoss( imgBoss );
    }

    @Finalize {
		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",30000);
    }

    // メインタスク
task TMain 
{
	yield;
	GetDamege;
	OutDamageRateZero;
	//Lissajous(0,84,166);
	BossShadowAnimation(imgBoss,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;
	loop(990)
	{
		if(count==720)
		{
			SetAction(ACT_SHOT_A,60);
		}
		if(GetEnemyNum==1){break;}
		count+=1;
		yield;
	}
	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, 8);
	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..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 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
{
loop
{
	StarShot;
	wait(240);
}

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);
		ascent(i in 0..6)
		{
		StarLaser(obj,i*60);
		}
		wait(450);
		Obj_Delete(obj);
}

task StarLaser(Cobj,angle)
{
	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);
		R+=220/360;
		length=R*3^0.5+3;
		width+=28/360;
		angle+=2;
	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);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

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

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

        @Finalize
        {
	if(!BeVanished && GetEnemyLife>0)
	{
		FinalizeItemSet(5);
		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 RX=0;
	let RY=0;
	let angle=45*num;
	loop(720)
	{
	SetX(RX*cos(angle));
	SetY(RY*sin(angle));
	if(RX<120)
	{
		RX+=2;
	}
	if(RY<60)
	{
		RY+=1;
	}
	angle+=0.5;
	yield;
	}
	let AY=0;
	let AYplus=0;
	loop(270)
	{
	SetX(RX*cos(angle));
	SetY(RY*sin(angle)+AY);
	angle+=0.5;
	if(AYplus<2)
	{
		AYplus+=2/120;
	}
	AY+=AYplus;
	yield;
	}
	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.5+0.5*j,angle,126,5);
			CreateShot01(GetX,GetY,1.5+0.5*j,angle+90,126,5);
			CreateShot01(GetX,GetY,1.5+0.5*j,angle-90,126,5);
			CreateShot01(GetX,GetY,1.5+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);
loop(27)
{
	CreateShot01(GetX,GetY,1.5,0,126,5);
	CreateShot01(GetX,GetY,1.5,180,126,5);
	wait(10);
}
}
}
/////////////////////////////////////////////////
task shotE
{
wait(60);
loop(12)
{
starshot(GetX,GetY,4,GetAngleToPlayer+rand(-10,10),134,10);
wait(60);
}

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);
}

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
		{
			CreateShot02(Obj_GetX(obj),Obj_GetY(obj),0,Obj_GetAngle(obj)+rand(-55,55)+180,0.01,3,126,5);
			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(96)
{
/*
	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);
}
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);

}
	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);	

*/	
	}
}
    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#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);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

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

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

        @Finalize
        {
	if(!BeVanished && GetEnemyLife>0)
	{
		FinalizeItemSet(5);
		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(6);
}
}
////////////////////////////////////////////////////
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,246,5);
	}
	wait(6);
}

}
    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#include_function ".\..\txt/StageEnemydata.txt"
}

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