
#Title[文２]
#Text[]
#Image[.] 
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_aya.png";
	let imgBoss2 =csd ~ "..\lib/dot_aya2.png";
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let Step2=false;
	let wIni=60;
let TimeCounter=90*60;
let StandardTimeCounter=TimeCounter;
    @Initialize {
	SetX(GetCommonDataDefault("BossX",0));
	SetY(GetCommonDataDefault("BossY",0));
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
        SetLife(8000);
	InitializeAction();
	SetEnemyMarker(true);
        TMainGrobal;
    }

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

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

    // メインタスク
task TMainGrobal
{
	yield;
	GetDamege;
	OutDamageRateZero;
	Collision;
	//Lissajous(0,100,255);
	BossShadowAnimation(imgBoss2,0,0,100,255);
	standBy;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}
}

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(xIni, yIni, 20,5);
	wait(60);
	//summon;
	Concentration01(30);
	wait(30);
	//Concentration03(GetX,GetY,60,0,64,255);
}

task Collision
{
	SetCommonData("NoCollision",true);
	wait(60);
	SetCommonData("NoCollision",false);

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

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


task shotM
{

let looptime=0;
let X=GetClipMinX;
let Y=GetCenterY;
loop
{
let speed=0;
let angle=rand(0,360);
SpellDraw(19,165);
loop(2)
{
	Y=rand(GetCenterY-128,GetCenterY-64);
	SetAction(ACT_MOVE, 20);
	SetMovePosition02(GetClipMinX, Y, 20);
	wait(15);
	ascent(i in 0..60)
	{
		TolnadeLaser(GetClipMinX-64,Y+i*8,180,220,i*1.5,4.0,20,-180,245);
		TolnadeLaser(GetClipMinX-64,Y-(i+1)*8,180,220,i*1.5,4.0,20,-180,245);
	}
	wait(5);
	speed=rand(2,3);
	angle=rand(0,360);
	ascent(i in 0..36)
	{
	CreateShot12(GetX,GetY,speed*cos(angle+i*10),speed*sin(angle+i*10),0,0.025,5,5,13,5);
	}
	Y=rand(GetCenterY-128,GetCenterY-64);
	SetAction(ACT_MOVE, 20);
	SetMovePosition02(GetClipMaxX, Y, 20);
	wait(15);
	ascent(i in 0..60)
	{
		TolnadeLaser(GetClipMaxX+64,Y+i*8,180,220,180+i*1.5,4.0,20,-180,245);
		TolnadeLaser(GetClipMaxX+64,Y-i*8,180,220,180+i*1.5,4.0,20,-180,245);
	}
	wait(5);
	speed=rand(2,3);
	angle=rand(0,360);
	ascent(i in 0..36)
	{
	CreateShot12(GetX,GetY,speed*cos(angle+i*10),speed*sin(angle+i*10),0,0.025,5,5,13,5);
	}
}
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(xIni, yIni, 20,5);
	wait(30);
	SpellDraw(20,360);
	ToriiShot(rand(64,160));
	ToriiShot(-rand(64,160));
	wait(90);
	SetAction(ACT_SHOT_A, 150);
	ToriiShot(GetPlayerX-GetCenterX);
	wait(60);
	ToriiShot(rand(64,160));
	ToriiShot(-rand(64,160));
	wait(60);
	wait(210);
	SpellDraw(21,480);
	SetAction(ACT_SHOT_A, 420);
	Takama;
	wait(480);
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(xIni, yIni+20, 20,5);
	wait(60);
	Shot1;
	Shot2;
	wait(240);
	let dir=rand_int(0,1)*2-1;
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(rand(GetCenterX+96*dir,GetCenterX+128*dir), rand(GetCenterY-80,GetCenterY-112), 30,3);
	wait(240);
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(rand(GetCenterX-96*dir,GetCenterX-128*dir), rand(GetCenterY-80,GetCenterY-112), 30,3);
	wait(240);
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(xIni, yIni, 20,5);
	wait(75);
	SetAction(ACT_SHOT_B, 60);
	Shot3;
	wait(120);

}

task Shot1
{
	let r=20;
	let speed=4;
	let angle=rand(0,360);
	let Sangle=0;
	loop(8)
	{
	ascent(j in 0..18)
	{
	ascent(i in 0..8)
	{
	CreateShot01(GetX+r*cos(Sangle+i*45),GetY+r*sin(Sangle+i*45),5,angle+j*20,9,5);
	CreateShot01(GetX+r*cos(Sangle+i*45),GetY+r*sin(Sangle+i*45),5,angle+j*20+180,9,5);
	}
	angle+=rand(0,2);
	wait(5);
	}
	}
}

task Shot2
{
	let r=30;
	let speed=4;
	let angle=rand(0,360);
	let Sangle=0;
	loop(17)
	{
	let angleplus=rand(-3,3);
	ascent(i in 0..5)
	{
	ascent(j in 0..18)
	{
	CreateShot01(GetX,GetY,4,angle+j*20,81,5);
	}
	angle+=angleplus;
	wait(6);
	}
	wait(15);
	}
}

task Shot3
{
	let angle=GetAngleToPlayer+180;
	ascent(i in 0..41)
	{
		ascent(j in 0..12)
		{
		CreateShot01(GetX,GetY,7-j*0.5,angle+i*4.5,9,5);
		CreateShot01(GetX,GetY,7-j*0.5,angle-i*4.5,9,5);
		}
	wait(1);
	}
}

task Takama
{
	loop(20)
	{
	ExPondeShot(rand(GetClipMinX,GetClipMaxX-64), GetClipMinY, rand(3.5,4.0),rand(80,105), 12, 5);
	ExPondeShot(rand(GetClipMinX+64,GetClipMaxX), GetClipMinY, rand(3.5,4.0),rand(75,100), 12, 5);
	wait(20);
	}
}

function ToriiShot(x)
{
let j=2;
let ang=360/78;
	BreakShot(GetCenterX+x, GetClipMinY, 2.9,90, 81, 20);
	ascent(let i in 1..79)
	{
		uzu(GetCenterX+x,GetClipMinY,(j+1)*0.20+0.1,ang*i,81,20,3.3-0.12*j,2.9);
		if(j==7)
		{
		j=1;
		}
		j++;
	}
}

task uzu(let x, let y, let speed,let angle, let graphic, let delay, let wspeed, let pspeed)
{
let w=0;
let py=0;
let r=180*speed/wspeed/pi;
    let obj = Obj_Create(OBJ_SHOT);
    //パラメータの設定
    Obj_SetPosition(obj, x , y);
    Obj_SetSpeed(obj, speed);
    Obj_SetAngle(obj, angle);
    ObjShot_SetGraphic(obj, graphic);
    ObjShot_SetDelay(obj, delay);
ObjShot_SetBombResist(obj,true);
wait(20);
while(!Obj_BeDeleted(obj))
{
    Obj_SetPosition(obj, x+r*cos(angle)+r*cos(angle+180+w) , y+r*sin(angle)+r*sin(angle+180+w)+py);
    Obj_SetAngle(obj, angle+w-90);
w+=wspeed;
py+=pspeed;
if(py+y>GetClipMaxY){break;}
yield;
}
//CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,angle+w-90,9,30);
Obj_Delete(obj);
}

task BreakShot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x , y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAlpha(obj,0);
	while(!Obj_BeDeleted(obj))
	{
		if(Obj_GetY(obj)>GetClipMaxY){break;}
		yield;
	}
	ascent(i in 0..72)
	{
		CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,i*5,9,30);
	}
Obj_Delete(obj);
}

task ExPondeShot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let count=0;
	let count1=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	Obj_SetAlpha(obj,0);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	let r=rand(-60,-20);
	let rPlus=rand(0.65,0.9);
	ascent(i in 0..15)
	{
		Exshot(obj,speed,angle,i*24,r,rPlus);
	}
	loop(300)
	{
		yield;
    	}
	Obj_Delete(obj);
}

task Exshot(Pobj,speed,angle,SetAngle,r,rPlus)
{
	let count=0;
	let graphic=12;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetSpeed(obj, Obj_GetSpeed(Pobj));
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, 5);
	Obj_SetAutoDelete(obj,false);
	loop(300)
	{
		Obj_SetPosition(obj, Obj_GetX(Pobj)+r*cos(SetAngle), Obj_GetY(Pobj)+r*sin(SetAngle));
		r+=rPlus;
		yield;
    	}
	Obj_Delete(obj);
}

task TolnadeLaser(x,y,angle,length,LengAngle,LengAnglePlus,width,DeleteAngle,type){
let obj=Obj_Create(OBJ_LASER);
Obj_SetX(obj,x);
Obj_SetY(obj,y);
ObjLaser_SetLength(obj,length);
Obj_SetAngle(obj,angle);
Obj_SetCollisionToPlayer(obj,true);
ObjLaser_SetWidth(obj,width);
ObjShot_SetDelay(obj, 0);
ObjShot_SetGraphic(obj,type);
ObjShot_SetBombResist(obj,true);
Obj_SetAutoDelete(obj,false);
Obj_SetAlpha(obj,255);
ObjLaser_SetSource(obj,false);
while(LengAngle>=DeleteAngle)
{
ObjLaser_SetLength(obj,length*sin(LengAngle));
wait(1);
LengAngle+=-LengAnglePlus;
}
Obj_Delete(obj);
}

}
/////////////////////////////////////////////////////////////////////////////
task shotE
{
let looptime=0;
Concentration01(30);
wait(30);
loop
{
	SpellDraw(23,720);
	SetAction(ACT_SHOT_A, 630);
	Shot1;
	Shot2;
	wait(60);
	Wind(GetClipMaxX,GetClipMinY-32);
	wait(180);
	Wind(GetClipMinX,GetClipMinY-32);
	wait(180);
	Wind(GetClipMaxX,GetClipMinY-32);
	Wind(GetClipMinX,GetClipMinY-32);
	wait(300);
	SetAction(ACT_SHOT_B, 60);
	ascent(j in 1..4)
	{
	ascent(i in 0..10)
	{
     		CreateEnemyFromScript("Familiar", GetX, GetY,
       	                       0, i*20, j);
	}
	}
	wait(780);
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(GetCenterX, GetCenterY, 20,5);
	wait(60);
	let Langle=rand(0,360);
	SetAction(ACT_SHOT_B, 60);
	SpellDraw(24,1200);
	ascent(i in 0..12)
	{
	Shield(Langle+i*30,1);
	Shield(Langle+i*30,-1);
	EffectLaser(GetX,GetY,i*30);
	}
	wait(1170);
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(xIni, yIni, 20,5);
	wait(60);
	Concentration01(30);
	wait(30);
}

task EffectLaser(x,y,angle)
{
	let BaseAngle=angle;
	let obj = Obj_Create(OBJ_SINUATE_LASER);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	ObjShot_SetBombResist(obj,true);
	//ObjShot_SetDelay(obj,delay);
	ObjShot_SetGraphic(obj,12);
	Obj_SetAutoDelete(obj,false);
	ObjSinuateLaser_SetLength(obj,30);
	ObjSinuateLaser_SetWidth(obj,8);
	ObjShot_SetBombResist(obj,true);
	Obj_SetCollisionToPlayer(obj,false);
	//	Shot;
	//	EffectBullet(obj,color);
		let R=0;
		loop(55)
		{
			Obj_SetX(obj,GetX+R*cos(angle));
			Obj_SetY(obj,GetY+R*sin(angle));
			R+=4;
			angle+=18;
			Obj_SetAngle(obj,angle);
			wait(1);
		}
		R=220;
		let Rangle=0;
		loop(900)
		{
			Obj_SetX(obj,GetX+R*cos(angle));
			Obj_SetY(obj,GetY+R*sin(angle));
			angle+=18;
			R=220+10*sin(Rangle);
			Rangle+=12;
			Obj_SetAngle(obj,angle);
			wait(1);
		}
		loop(55)
		{
			Obj_SetX(obj,GetX+R*cos(angle));
			Obj_SetY(obj,GetY+R*sin(angle));
			R+=4;
			angle+=18;
			Obj_SetAngle(obj,angle);
			wait(1);
		}
		Obj_Delete(obj);
}

task Shield(angle,dir)
{
	let R=0;
	let Zangle=rand(0,360);
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, GetX, GetY);
	Obj_SetSpeed(obj, 0);
	ObjShot_SetGraphic(obj, 44);
	ObjShot_SetDelay(obj, 5);
	Obj_SetAlpha(obj,150*0);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	BitShot;
	loop(900)
	{		
		Obj_SetAngle(obj, Zangle);
		Obj_SetPosition(obj, GetX+R*cos(angle), GetY+R*sin(angle));
		if(R<220){R+=4;}
		angle+=3*dir*2;
		Zangle+=9;
		yield;
	}
	loop(60)
	{		
		Obj_SetAngle(obj, Zangle);
		Obj_SetPosition(obj, GetX+R*cos(angle), GetY+R*sin(angle));
		if(R<360){R+=2;}
		angle+=3*dir*2;
		Zangle+=9;
		yield;
	}
	Obj_Delete(obj);

	task BitShot
	{
	wait(60);
	let angle=90;
	let angleplus=0;
		while(!Obj_BeDeleted(obj))
		{
		CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1.25,angle*dir,84,0);
		angle=90+20*sin(angleplus)*dir;
		angleplus+=1.5*1.5;
		wait(9);
		}
	}
}

task Shot1
{
	let angle=GetAngleToPlayer;
	loop(16)
	{
	ascent(i in 0..8)
	{
		ascent(j in 0..12)
		{
		CreateShot01(GetX,GetY,4.0,angle+i*1.75+j*360/12,84,5);
		}
		wait(3);
	}
	angle+=16;
	wait(15);
	}
}

task Shot2
{
	let angle=GetAngleToPlayer;
	loop(24)
	{
	ascent(i in 0..5)
	{
		ascent(j in 0..12)
		{
		CreateShot01(GetX,GetY,3.0,angle-i*1.75+j*360/12,84,5);
		}
		wait(3);
	}
	angle-=10;
	wait(9);
	}
}

task Wind(X,Y)
{
	//let X=GetClipMinX-16;
	//let Y=GetCenterY;
	let speed=12;
	let angle=atan2(GetPlayerY-Y,GetPlayerX-X);
	CLaser(X,Y,speed,angle);
	wait(30);
	ascent(i in 0..3)
	{
	WindLaser(X,Y,angle,i*120);
	}
}

task WindLaser(x,y,Langle,Rangle)
{
	let length=650;
	let obj=Obj_Create(OBJ_LASER);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	ObjLaser_SetLength(obj,length);
	Obj_SetAngle(obj,Langle);
	Obj_SetCollisionToPlayer(obj,true);
	ObjLaser_SetWidth(obj,8);
	ObjShot_SetDelay(obj, 0);
	ObjShot_SetGraphic(obj,157);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAlpha(obj,200);
	ObjLaser_SetSource(obj,false);
	let X;
	let Y;
	let R1=0;
	let R2=0;
	loop(120)
	{
		X=x+R1*cos(Langle)*cos(Rangle)-R2*sin(Langle)*sin(Rangle);
		Y=y+R1*sin(Langle)*cos(Rangle)+R2*cos(Langle)*sin(Rangle);
		StarLaserEffect(X,Y,length,8,Langle);
		Obj_SetX(obj,X);
		Obj_SetY(obj,Y);
		Rangle+=6;
		if(R2<30)
		{
			R1+=10/30;
			R2+=30/30;
		}
		yield;
	}
	loop(30)
	{
		X=x+R1*cos(Langle)*cos(Rangle)-R2*sin(Langle)*sin(Rangle);
		Y=y+R1*sin(Langle)*cos(Rangle)+R2*cos(Langle)*sin(Rangle);
		StarLaserEffect(X,Y,length,8,Langle);
		Obj_SetX(obj,X);
		Obj_SetY(obj,Y);
		Rangle+=6;
		R1-=10/30;
		R2-=30/30;
		yield;
	}
	Obj_Delete(obj);
}

task StarLaserEffect(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*width/20;
		let R=255;
		let G=255;
		let B=255;

		R=150;
		G=255;
		B=150;


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

		if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){Obj_Delete(obj);return;}

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

task CLaser(x,y,speed,angle)
{
	let length=600;
	let obj=Obj_Create(OBJ_LASER);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	ObjLaser_SetLength(obj,length);
	Obj_SetAngle(obj,angle);
	Obj_SetCollisionToPlayer(obj,true);
	ObjLaser_SetWidth(obj,20);
	ObjShot_SetDelay(obj, 60);
	ObjShot_SetGraphic(obj,157);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAlpha(obj,200);
	ObjLaser_SetSource(obj,false);
	wait(30);
	Obj_Delete(obj);

}

}
//////////////////////////////////////////////////////////////////////
task shotA
{
wait(30);
loop
{
	SpellDraw(27,600);
	let angle=rand(0,360);
	loop(3)
	{
	SetAction(ACT_SHOT_B, 60);
	Shear(angle);
	angle+=rand(70,110);
	wait(180);
	}
	wait(120);
	SetAction(ACT_SHOT_A, 60);
	SpellDraw(28,660);
	UpLeafs;
	wait(30);
	bush;
	wait(780);
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(xIni, yIni-30, 20,5);
	wait(60);

	let X=[GetClipMinX+64,GetClipMaxX-64];
	let Y=[GetClipMinY+96,GetClipMaxY-64];

	let dir=rand_int(0,1);
	Shot1(-1);
	wait(60);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(X[dir%2]+rand(-20,20), Y[0]+rand(-20,20), 30);
	dir+=1;
	wait(60);
	Shot1(dir%2);
	wait(60);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(X[dir%2]+rand(-20,20), Y[0]+rand(-20,20), 30);
	dir+=1;
	wait(60);
	Shot1(dir%2);
	wait(60);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(X[dir%2]+rand(-20,20), Y[0]+rand(-20,20), 30);
	dir+=1;
	wait(60);
	Shot1(dir%2);
	wait(60);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(X[dir%2]+rand(-20,20), Y[0]+rand(-20,20), 30);
	dir+=1;
	wait(60);
	Shot1(dir%2);
	wait(60);
	SetAction(ACT_MOVE, 30);
	SetMovePosition02(xIni, yIni, 30);
	wait(210);
}

task Shot1(num)
{
	alternative(num)
	case(-1)
	{
	ascent(i in 0..15)
	{
	ascent(j in 0..8)
	{
		CreateShot01(GetX,GetY,2+j*0.5,36+i*8,105,5);
	}
	wait(2);
	}
	}
	case(0)
	{
	ascent(i in 0..16)
	{
	ascent(j in 0..8)
	{
		CreateShot01(GetX,GetY,2+j*0.5,36+i*8+47,105,5);
	}
	wait(2);
	}
	}
	case(1)
	{
	ascent(i in 0..16)
	{
	ascent(j in 0..8)
	{
		CreateShot01(GetX,GetY,2+j*0.5,36+i*8-47,105,5);
	}
	wait(2);
	}
	}
	wait(30);
	loop(5)
	{
	ascent(j in 0..8)
	{
		CreateShot01(GetX,GetY,2+j*0.5,GetAngleToPlayer,110,5);
	}
	wait(5);
	}

}

task bush
{
	let angle=rand(0,360);
	ascent(i in 0..16)
	{
	Leaf(GetCenterX+140,GetCenterY+20,i*360/16+angle,120-i*3,-1);
	Leaf(GetCenterX-140,GetCenterY-70,i*360/16+angle,120-i*3,1);
	Leaf(GetCenterX+140,GetCenterY-160,i*360/16+angle,120-i*3,-1);
	Leaf(GetCenterX-140,GetCenterY-250,i*360/16+angle,120-i*3,1);
	wait(3);
	}
}

task Leaf(sx,sy,PosAngle,time,dir)
{
	let XR=rand(-80,80);
	let YR=rand(-80,80);
	sx+=XR;
	sy+=YR;
	let X=sx;
	let Y=GetClipMinY-120;
	let Radius1=0;
	let Radius2=0;
	let speed=rand(5,5.5);
	let Zangle=rand(0,360);
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, X, Y);
	Obj_SetSpeed(obj, 0);
	ObjShot_SetGraphic(obj, 44);
	ObjShot_SetDelay(obj, 0);
	//Obj_SetAlpha(obj,0);
	//Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	loop(time)
	{		
		if(Obj_GetY(obj)>sy)
		{
			speed=0;
		}
		Obj_SetPosition(obj, sx, Obj_GetY(obj)+speed);
		Obj_SetAngle(obj, Zangle);
		Zangle+=9;
		yield;
	}
	BushShot;
	let count=0;
	loop(90)
	{		
		if(count<90)
		{
			Radius1+=80/90;
			Radius2+=40/90;
			sx-=XR/90;
			sy-=YR/90;
		}
		Obj_SetPosition(obj, sx+Radius1*cos(PosAngle),sy+Radius2*sin(PosAngle));
		Obj_SetAngle(obj, Zangle);
		PosAngle+=16/60*dir+24/16*dir;
		Zangle+=9;
		count+=1;
		yield;
	}
	speed=0;
	loop(600)
	{		
		if(speed<1.2)
		{
			speed+=0.005;
		}
		sy+=speed;
		Obj_SetPosition(obj, sx+Radius1*cos(PosAngle),sy+Radius2*sin(PosAngle));
		Obj_SetAngle(obj, Zangle);
		PosAngle+=16/60*dir+24/16*dir;
		Zangle+=9;
		yield;
	}
	Obj_Delete(obj);

	task BushShot
	{
		wait(90);
		loop
		{
			let angle=atan2(Obj_GetY(obj)-sy,Obj_GetX(obj)-sx);
			CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1,angle,37,0);
			wait(30);
		}
	}
}

task UpLeafs
{
	loop(64)
	{
		UpLeaf(rand(4,6),rand(230,310));
		wait(1);
	}
}

task UpLeaf(speed,angle)
{
	let Zangle=rand(0,360);
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, GetX, GetY);
	Obj_SetSpeed(obj, 0);
	ObjShot_SetGraphic(obj, 44);
	ObjShot_SetDelay(obj, 15);
	//Obj_SetAlpha(obj,0);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	loop(120)
	{		
		Obj_SetPosition(obj, Obj_GetX(obj)+speed*cos(angle), Obj_GetY(obj)+speed*sin(angle));
		Obj_SetAngle(obj, Zangle);
		Zangle+=9;
		yield;
	}
	Obj_Delete(obj);
}

task Shear(angle)
{
	let X=0;
	let Y=0;
	let PX=GetPlayerX;
	let PY=GetPlayerY;
	let XGrid=0;
	let YGrid=25;
	let XGridPlus=3;
	let YGridPlus=0;
	//let angle=rand(0,360);
	let R1=460;
	let R2=30;
	let LSX=PX+R1*cos(angle)+R2*cos(angle+90);
	let LSY=PY+R1*sin(angle)+R2*sin(angle+90);
	let LSX2=PX-R1*cos(angle)-R2*cos(angle+90);
	let LSY2=PY-R1*sin(angle)-R2*sin(angle+90);
	SLaser(LSX,LSY,angle,1);
	SLaser(LSX2,LSY2,angle,-1);
	wait(80);
}

task SLaser(x,y,angle,dir)
{
let length=0;
let obj=Obj_Create(OBJ_LASER);
Obj_SetX(obj,x);
Obj_SetY(obj,y);
ObjLaser_SetLength(obj,length);
Obj_SetAngle(obj,angle);
Obj_SetCollisionToPlayer(obj,false);
ObjLaser_SetWidth(obj,4);
ObjShot_SetDelay(obj, 0);
ObjShot_SetGraphic(obj,157);
ObjShot_SetBombResist(obj,true);
Obj_SetAutoDelete(obj,false);
Obj_SetAlpha(obj,0);
ObjLaser_SetSource(obj,false);
let speed=0;
loop(45)
{
ObjLaser_SetLength(obj,length);
yield;
length+=22;
	StarLaserEffect(x,y,length,angle,false,dir);
}
loop(30)
{
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	x-=speed*cos(angle+90)*dir;
	y-=speed*sin(angle+90)*dir;
	StarLaserEffect(x,y,length,angle,true,dir);
	yield;
	speed+=3;
}
wait(30);
Obj_Delete(obj);
}

task StarLaserEffect(x,y,length,angle,fire,dir)
{
		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, -length, -3);
		ObjEffect_SetVertexXY(obj, 1,length,  -3);
		ObjEffect_SetVertexXY(obj, 2,length, 3);
		ObjEffect_SetVertexXY(obj, 3,  -length,  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;
		if(OnPlayerMissed){Alpha=0;}
		let R=255;
		let G=255;
		let B=255;

		R=50;
		G=205;
		B=50;


		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);
		}
		let XGrid=0;
		let YGrid=20;
		loop(20)
		{
		Obj_SetPosition(obj,x,y);
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		Alpha-=100/20;
		if(OnPlayerMissed){Alpha=0;}
		yield;
		}
		if(fire)
		{
		ascent(i in -40..0)
		{
			let X=Obj_GetX(obj)+(i*YGrid)*cos(angle)*dir;
			let Y=Obj_GetY(obj)+(i*YGrid)*sin(angle)*dir;
			let dis=((X-GetPlayerX)^2+(Y-GetPlayerY)^2)^0.5;
			if(dis>20)
			{
				CreateShotA(0,X,Y,5);
				SetShotDataA(0,0,0,angle+dir*90+90+rand(-3,3),0,0.01,1.0,44);
				FireShot(0);
			}
		}
		}
		Obj_Delete(obj);
}

}

#include_function ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_Aya.txt"
}

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
	let angle = GetAngle;
	let num = GetArgument;
    @Initialize {
	DamageRate=100;
	BombDamageRate=0;
	//SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(120);
        SetDamageRateEx(100,0,0,0);
	TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 12);
        MSDSetCollisionB(GetX, GetY, 4);
        yield;
    }

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

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,12,0.3);
	DeleteEnemyShotImmediatelyInCircle(ALL,GetX,GetY,10);
	if(GetCommonDataDefault("BossLife",0)>0)
	{
		//FinalizeItemSet(1);
	}
        }

    task TMain {
        yield;
	Leaf;
	GetDamege;
	OutDamageRateZero;
	ZakoEnemyLifeDisplay;
	move;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}
    }

task move
{
	SetMovePosition03(GetX+num*50*cos(angle), GetY+num*50*sin(angle), 10,5);
	wait(150);
	SetMovePosition03(rand(GetClipMinX+32,GetClipMaxX-32),rand(GetCenterY-150,GetCenterY), 10,5);
	wait(150);
	SetMovePosition03(rand(GetClipMinX+32,GetClipMaxX-32),rand(GetCenterY-150,GetCenterY), 10,5);
	wait(150);
	SetMovePosition03(rand(GetClipMinX+32,GetClipMaxX-32),rand(GetCenterY-150,GetCenterY), 10,5);
	wait(150);
	SetAngle(GetAngleToPlayer);
	let speed=0;
	loop(120)
	{
		SetSpeed(speed);
		speed+=0.05;
		yield;
	}
	wait(60);
	VanishEnemy;
}

task Leaf
{
	let Zangle=rand(0,360);
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, GetX, GetY);
	Obj_SetSpeed(obj, 0);
	ObjShot_SetGraphic(obj, 44);
	ObjShot_SetDelay(obj, 5);
	//Obj_SetAlpha(obj,0);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	while(!Obj_BeDeleted(obj))
	{		
		Obj_SetAngle(obj, Zangle);
		Obj_SetPosition(obj, GetX, GetY);
		Zangle+=9;
		yield;
	}
	//Obj_Delete(obj);
}
task shotM
{

}
/////////////////////////////////////////////////////////
task shotE
{
	BitShot1;
	wait(150);
	BitShot2;
	BitShot1;
	wait(150);
	BitShot2;
	BitShot1;
	wait(150);
	BitShot2;
	BitShot1;
	wait(150);
	BitShot3;

	task BitShot1
	{
	wait(60);
	let angle=0;
		loop(6)
		{
			angle=GetAngleToPlayer+rand(-4,4);
			CreateShot01(GetX,GetY,5,angle,84,5);
			wait(10);
		}
	}
	task BitShot2
	{
		let angle=rand(0,360);
		ascent(i in 0..8)
		{
			CreateShot01(GetX,GetY,2.75,angle+i*45,84,5);
		}
	}
	task BitShot3
	{
		let angle=rand(0,360);
		let speed=rand(1.5,2.5);
		ascent(i in 0..24)
		{
			CreateShot01(GetX,GetY,speed,angle+i*15,84,30);
		}
	}

}
////////////////////////////////////////////////////////////
task shotA
{

}

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

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