
#Title[スター通常]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "スター通常";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_starsapphire.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
let TimeCounter=40*60;
let StandardTimeCounter=TimeCounter;
let VanishLife=1000;
    @Initialize {
        SetTimer(TimeCounter/60);
        SetLife(1500);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
	//MotionBlurEx(SHOT,300,200,ADD);
    }

    @MainLoop {
	BulletNum=GetEnemyShotCount;
	TimeCounter-=1;
        SetCollisionA(GetX, GetY, 48);
	MSDSetCollisionB(GetX(),GetY(),8);
        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);
       DeleteGraphic(imgBoss);
	SetCommonData("TimeBonus",TimeCounter/StandardTimeCounter);
	SetCommonData("BossRate",20000);
    }

    // メインタスク
task TMain 
{
	yield;
	GetDamege;
	OutDamageRateZero;
	Lissajous(0,84,166);
	BossShadowAnimation(imgBoss,0,0,84,166);
	standBy;
	wait(90);
	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 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);
	SetInvincibility(wIni);
}

////////////////////////////////////////////////////////////
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)
		{
		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 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 {
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(350);
        SetDamageRateEx(100,10,0,0);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

    @MainLoop {
	BulletNum=GetEnemyShotCount;
        SetCollisionA(GetX, GetY, 48);
        SetCollisionB(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;
	OutDamageRateZeroOnSet(100,10);
	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;
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);
}
loop
{
let angle=GetAngleToPlayer-180;
let speed=3;
	ascent(i in 0..12)
	{
	CreateShot12(GetX,GetY,speed*cos(angle+i*30),speed*sin(angle+i*30),0,0.045,0,5,126,5);
	}
	wait(5);
}
	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(PY-GetY,PX-GetX)+j*20,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_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 {
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(350);
        SetDamageRateEx(100,10,0,0);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

    @MainLoop {
	BulletNum=GetEnemyShotCount;
        SetCollisionA(GetX, GetY, 48);
        SetCollisionB(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;
	OutDamageRateZeroOnSet(100,10);
	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+240,126,5);
		CreateShot01(GetX,GetY,2.5,angle+120,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+240,126,5);
		CreateShot01(GetX,GetY,2.5,angle+120,126,5);
	}
	wait(3);
	}
	wait(3);
}
}
////////////////////////////////////////////////////
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+240,165,6,246,5);
		CreateLaser01(GetX,GetY,3,angle+120,165,6,246,5);
	}
	wait(6);
}

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

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