
#Title[大妖精通常]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_alice.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let Step2=false;
	let wIni=60;
let TimeCounter=150*60;
let StandardTimeCounter=TimeCounter;
let DollDrawArray=[];
    @Initialize {
	SetCommonData("SetBossLifeArray",[0]);
	SetCommonData("LifeBerReproduction",true);
	SetX(GetCommonDataDefault("BossX",0));
	SetY(GetCommonDataDefault("BossY",0));
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
	SetCommonData("STAGE5BOSS",true);
	SetShotAutoDeleteClip(64,24,64,24);
	SetCommonData("BossLastAttackColor",[255,255,0]);
	SetCommonData("BossLastAttack",true);
        SetLife(15000);
	InitializeAction();
	SetEnemyMarker(true);
        TMainGrobal;
	if(GetPlayerLife==1)
	{
		SetCommonDataEx(NsScore,NsAchievement[76],1);
	}
    }

    @MainLoop {
	SetCommonData("BossX",GetX);
	SetCommonData("BossY",GetY);
	SetCommonData("BossLife",GetLife);
	BulletNum=GetEnemyShotCount;
	TimeCounter-=1;
        yield;
    }
let aaa=[];
    @DrawLoop {
DrawText(aaa,120,382,12,255);//起動時間の表示
	SetGraphicAngle(0,0,0);
	DrawBoss( imgBoss );
	ascent(i in 0..length(DollDrawArray))
	{
		SetGraphicAngle(0,0,Obj_GetAngle(DollDrawArray[i]));
		DrawDoll(imgBoss,Obj_GetX(DollDrawArray[i]),Obj_GetY(DollDrawArray[i]));
	}
    }

    @Finalize {
	ascent(i in 0..length(DollDrawArray))
	{
		MagicCircleBreak(Obj_GetX(DollDrawArray[i]),Obj_GetY(DollDrawArray[i]),1000,0.3);
	}
	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",40000);
    }

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

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

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

	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 BombBarrier
{
loop
{
	while(!OnBomb){yield;}
	DamageRate=50;
	BombDamageRate=0;
	BarrierEffect(1);
	BarrierEffect(0);	
	while(OnBomb){yield;}
	wait(60);
	DamageRate=100;
	BombDamageRate=100;
}

task BarrierEffect(type)
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\CircleLine.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -64, -64);
		ObjEffect_SetVertexXY(obj, 1,64,  -64);
		ObjEffect_SetVertexXY(obj, 2,64, 64);
		ObjEffect_SetVertexXY(obj, 3,  -64,  64);
		
		ObjEffect_SetVertexUV(obj, 0,  0, 0);
		ObjEffect_SetVertexUV(obj, 1,  128, 0);
		ObjEffect_SetVertexUV(obj, 2, 128, 128);
		ObjEffect_SetVertexUV(obj, 3, 0, 128);

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

		alternative(GetPlayerInfo(PLAYER_SPEED_HIGH))
		case(4){R=100;G=100;B=255;}
		case(4/2){R=100;G=100;B=255;}
		case(5/2){R=255;G=100;B=100;}
		case(5){R=255;G=100;B=100;}
		case(5.5){R=255;G=100;B=255;}
		case(5.5/5){R=255;G=100;B=255;}
		case(4.5){R=50;G=205;B=50;}
		case(4.5/2){R=50;G=205;B=50;}

		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}

		ObjEffect_SetLayer(obj,4);

		let X=GetCenterX;
		let Y=GetCenterY;
		Obj_SetPosition(obj,GetX,GetY);

		let Scale=0;

		let Xangle=0;
		let Yangle=0;
		let Zangle=0;

		if(type)
		{
		}
		else
		{
			Yangle+=90;
		}

		while(OnBomb)
		{
			Obj_SetPosition(obj,GetX,GetY);
			if(Scale<1)
			{
			Scale+=1/30;
			}
			if(type)
			{
			if(Xangle%90>5 && Xangle%90<85)
			{
			BombEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			}
			}
			else
			{
			if(Yangle%90>5 && Yangle%90<85)
			{
			BombEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			}
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			if(type)
			{
			Xangle+=3;
			}
			else
			{
			Yangle+=3;
			}
			yield;
		}

		loop(60)
		{
			Scale-=1/60;
			BombEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			if(type)
			{
			Xangle+=3;
			}
			else
			{
			Yangle+=3;
			}
			yield;
		}
		Obj_Delete(obj);
}

task BombEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B)
{
		let obj = Obj_Create(OBJ_EFFECT);

		ObjEffect_SetTexture(obj, csd~"..\img\CircleLine.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -64, -64);
		ObjEffect_SetVertexXY(obj, 1,64,  -64);
		ObjEffect_SetVertexXY(obj, 2,64, 64);
		ObjEffect_SetVertexXY(obj, 3,  -64,  64);
		
		ObjEffect_SetVertexUV(obj, 0,  0, 0);
		ObjEffect_SetVertexUV(obj, 1,  128, 0);
		ObjEffect_SetVertexUV(obj, 2, 128, 128);
		ObjEffect_SetVertexUV(obj, 3, 0, 128);

		ObjEffect_SetLayer(obj,4);

		Obj_SetPosition(obj,GetX,GetY);

		ObjEffect_SetScale(obj, Scale,Scale);
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

		let BAlpha=Alpha;

		loop(60)
		{
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Alpha-=BAlpha/60;
			yield;
		}
		Obj_Delete(obj);
}

}

task shotM
{
let RSAMax=5;
let WideAngle=-0.8;
let d=rand_int(0,1)*2-1;
let color=0;
let grad=75;
let Shotspeed=3.5;
let Intetrval=180;
wait(30);
SetAction(ACT_SHOT_A, 60000);
loop
{
Shot1(d,color,grad,Shotspeed);
wait(floor(Intetrval));
color+=1;
d*=-1;
if(color>=7){color=0;}
WideAngle+=0.02;
if(Shotspeed<10){Shotspeed+=0.15;}
if(RSAMax<45){RSAMax+=1.5;}
if(Intetrval>165){Intetrval-=0.5;}
}

	task Shot1(dir,Dollcolor,Grad,DollShotspeed)
	{
		let RSA=rand(0,RSAMax);
		let DollObj=[];
		let rsangle=rand(-30,30);
		let rangle=rand(0,360);
		let DollCenterX=GetX;
		let DollCenterY=GetY;
		let DollCenterAngle=GetAngleToPlayer+Grad*dir;
		ascent(i in 0..7)
		{
			CreateDoll(i,rangle+i*360/7,GetAngleToPlayer+Grad*dir,3,RSA*dir);
		}
		let Distance=0;
		let BossAngleFromDoll=0;
		loop(300)
		{
			DollCenterX+=0.5*cos(DollCenterAngle);
			DollCenterY+=0.5*sin(DollCenterAngle);
			Distance=((GetY-DollCenterY)^2+(GetX-DollCenterX)^2)^0.5;
			BossAngleFromDoll=atan2(GetY-DollCenterY,GetX-DollCenterX);
			StringLaserEffect(DollCenterX,DollCenterY,Distance,5,BossAngleFromDoll);
			yield;
		}
		loop(60)
		{
			DollCenterX-=5*0.5*cos(DollCenterAngle);
			DollCenterY-=5*0.5*sin(DollCenterAngle);
			Distance=((GetY-DollCenterY)^2+(GetX-DollCenterX)^2)^0.5;
			BossAngleFromDoll=atan2(GetY-DollCenterY,GetX-DollCenterX);
			StringLaserEffect(DollCenterX,DollCenterY,Distance,5,BossAngleFromDoll);
			yield;
		}
		task CreateDoll(num,angle,SpeedAngle,rot,Rangle)
		{
			let DollX=GetX;
			let DollY=GetY;
			let ShotFlag=1;
			let X=GetX;
			let Y=GetY;
			let r=0;
			let rspeed=0.4;
			let DDangle=0;

			let obj = Obj_Create(OBJ_SHOT);
			DollObj=DollObj~[obj];
			DollDrawArray=DollDrawArray~[obj];

			Obj_SetPosition(obj, GetX, GetY);
			//Obj_SetSpeed(obj, Obj_GetSpeed(Pobj));
			//Obj_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, 9+Dollcolor);
			ObjShot_SetDelay(obj, 5);
			ObjShot_SetBombResist(obj,true);
			Obj_SetAutoDelete(obj,false);
			Obj_SetAlpha(obj,0);
			Obj_SetCollisionToPlayer(obj,false);

			FireLaser;
			String;
		//	let SpeedAngle=90+90*dir+rand(-30,30);
			let Speed=0.5;
			loop(300)
			{
				DollX=X+r*cos(angle);
				DollY=Y+r*sin(angle);
				Obj_SetPosition(obj,DollX , DollY);
				angle+=rot*dir;
				r+=rspeed;
				X+=Speed*cos(SpeedAngle);
				Y+=Speed*sin(SpeedAngle);
				if(num==0)
				{
					SetCollisionA(X, Y, r);
				}
				yield;
    			}
			loop(30)
			{
				DollX=X+r*cos(angle);
				DollY=Y+r*sin(angle);
				Obj_SetPosition(obj,DollX , DollY);
				angle+=rot*dir;
				r-=5*rspeed;
				X-=5*Speed*cos(SpeedAngle);
				Y-=5*Speed*sin(SpeedAngle);
				if(num==0)
				{
					SetCollisionA(X, Y, r);
				}
				yield;
    			}
			ShotFlag=0;
			loop(30)
			{
				DollX=X+r*cos(angle);
				DollY=Y+r*sin(angle);
				Obj_SetPosition(obj,DollX , DollY);
				angle+=rot*dir;
				r-=5*rspeed;
				X-=5*Speed*cos(SpeedAngle);
				Y-=5*Speed*sin(SpeedAngle);
				if(num==0)
				{
					SetCollisionA(X, Y, r);
				}
				yield;
    			}
			Obj_Delete(obj);
			DollDrawArray=erase(DollDrawArray,0);

			task String
			{
				loop(360)
				{
					StringLaserEffect(X,Y,r,5,angle);
					yield;
				}
			}

			task FireLaser
			{
			wait(30);
			alternative(Dollcolor)
			case(2)
			{
			while(ShotFlag)
			{
				ascent(i in -1..2)
				{
					let angle=atan2(Y-DollY,X-DollX-WideAngle*1.0*i*dir-i*dir*0.5)+Rangle;
					ShotAndEffect(i,DollX,DollY,angle,DollShotspeed,Dollcolor);
					wait(1);
				}
			wait(8);
			}
			}
			case(6)
			{
			while(ShotFlag)
			{
				ascent(i in -1..2)
				{
					let angle=atan2(Y-DollY,X-DollX-WideAngle*1.0*i*dir-i*dir*0.5)+Rangle;
					ShotAndEffect(i,DollX,DollY,angle,DollShotspeed,Dollcolor);
					wait(1);
				}
			wait(8);
			}
			}
			others
			{
			while(ShotFlag)
			{
				ascent(i in -1..2)
				{
					let angle=atan2(Y-DollY,X-DollX-WideAngle*i*dir)+Rangle;
					ShotAndEffect(i,DollX,DollY,angle,DollShotspeed,Dollcolor);
					wait(1);
				}
			wait(7);
			}

			}

			}

			task FireLaser2
			{
			wait(30);
			loop
			{
				ascent(i in 0..3)
				{
			let angle=atan2(Y-DollY,X-DollX);
			CreateShotA(0,DollX,DollY,5-i);
			SetShotDataA(0,0,0,angle,0,0.02,5,81);
			//SetShotDataA(0,60,NULL,NULL,0,0.00,10,gra-144);
			FireShot(0);
			//	CreateShot01(Obj_GetX(obj),Obj_GetY(obj),3,atan2(Y-Obj_GetY(obj),X-Obj_GetX(obj)),81,15-i*5);
				wait(1);
				}
			wait(8);
			}
			}
			task ShotAndEffect(i,x,y,Angle,DollShotSpeed,DollColor)
			{
			//	if((angle+3600)%360<180){return;}
				DelayEffect(x,y,Angle,DollColor);
				wait(10);
				CreateShotA(0,x,y,0);
				SetShotDataA(0,0,0,Angle,0,DollShotSpeed/200,DollShotSpeed,81+DollColor);
				SetShotDataA(0,5-i,0,Angle,0,DollShotSpeed/200,DollShotSpeed,81+DollColor);
				FireShot(0);

				task DelayEffect(x,y,Angle,type)
				{
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\shot_all.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

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

		ObjEffect_SetVertexUV(obj, 0,  0+18*type,  493);
		ObjEffect_SetVertexUV(obj, 1,  17+18*type, 493);
		ObjEffect_SetVertexUV(obj, 2, 17+18*type, 508);
		ObjEffect_SetVertexUV(obj, 3, 0+18*type,  508);

		Obj_SetPosition(obj,x,y);
		ObjEffect_SetAngle(obj,0,0,Angle+90);

		let scale=3;

		loop(10)
		{
			scale-=2/10;
				Angle+=360/10;
			yield;
			ObjEffect_SetScale(obj, scale, scale);
			ObjEffect_SetAngle(obj,0,0,Angle+90);
		}
		Obj_Delete(obj);
				}
			}
		}

	task Laser(x,y,angle,length,width,delay,time,gra)
	{
	let HueCount=rand(0,360);
	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);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAlpha(obj,150);
	let dcount=30;
	let lcount=0;
	loop(delay)
	{
		ObjShot_SetGraphic(obj,gra);
		EffectLaser(x,y,angle,length*lcount/30,width,0,2,gra);
		SetShotColor(255,255,255);
		ObjLaser_SetLength(obj,length*lcount/30);
		if(lcount<30)
		{
		lcount+=1;
		}
	yield;
	}
	loop(time-delay)
	{
		EffectLaser(x,y,angle,length,width*2,0,5,gra);
		ObjShot_SetGraphic(obj,gra);
		SetShotColor(255,255,255);
		yield;
	}
	Obj_SetCollisionToPlayer(obj,false);
	LaserShot;
	Obj_Delete(obj);

	task LaserShot
	{
		length/=5;
		let time=60;
		let StartX=x;
		let StartY=y;
		let EndX=ObjLaser_GetEndX(obj);
		let EndY=ObjLaser_GetEndY(obj);
		let DX=EndX-StartX;
		let DY=EndY-StartY;
		let sep=15;
		let CX=(StartX+EndX)/2;
		let CY=(StartY+EndY)/2;
		let TX=CX+length*cos(angle+90);
		let TY=CY+length*sin(angle+90);

		ascent(i in -7..8)
		{
			let ShotX=CX+i/sep*DX;
			let ShotY=CY+i/sep*DY;
			let Sangle=atan2(TY-ShotY,TX-ShotX);
			let speed=((TY-ShotY)^2+(TX-ShotX)^2)^0.5/time;
			speed=2;

			CreateShotA(0,ShotX,ShotY,5);
			SetShotDataA(0,0,speed+absolute(i)/5,Sangle,-i/8,-0.02,speed,gra-144);
			SetShotDataA(0,60,NULL,NULL,0,0.00,10,gra-144);
			FireShot(0);
		}

	}

	}



	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)
	{
	ObjLaser_SetWidth(obj,width*rand(0.5,1));
	yield;
	}
	Obj_Delete(obj);
	}

	}

task StringLaserEffect(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, -2);
		ObjEffect_SetVertexXY(obj, 1,length,  -2);
		ObjEffect_SetVertexXY(obj, 2,length, 2);
		ObjEffect_SetVertexXY(obj, 3,  0,  2);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  22, 27);
		ObjEffect_SetVertexUV(obj, 2, 22, 33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);

		let Alpha=60;

		let R=39;
		let G=64;
		let B=200;


		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(1)
		{
		yield;
		}
		Obj_Delete(obj);
}

}
/////////////////////////////////////////////////////////////////////////////
task moveE
{
}

task shotE
{
let RandType=0;
let RSAMax=5;
let WideAngle=0;
let d=rand_int(0,1)*2-1;
let color=0;
let grad=75;
let Shotspeed=3.5;
let Intetrval=180;
wait(30);
SetAction(ACT_SHOT_B, 60);
loop(1)
{
Shot1(d,color,grad,Shotspeed);
wait(floor(Intetrval));
color+=1;
d*=-1;
if(color>=7){color=0;}
//if(grad>60){grad-=2;}
WideAngle+=0.05;
if(Shotspeed<10){Shotspeed+=0.175;}
if(RSAMax<45){RSAMax+=1.5;}
if(Intetrval>165){Intetrval-=0.5;}
}

	task Shot1(dir,Dollcolor,Grad,DollShotspeed)
	{
		let WaitTime=240;
		let MaxLife=GetLife;
		let limit=0;
		let PresentType=0;
		let PastType=0;
		let PastType2=0;
		let PastType3=0;
		let LaserType=rand_int(153,159+limit);
		PastType=LaserType;
		let RSA=rand(0,RSAMax);
		let DollObj=[];
		let rsangle=rand(-30,30);
		let rangle=rand(0,360);
		let DollCenterX=GetX;
		let DollCenterY=GetY;
		let DollCenterAngle=90;
		ascent(i in 0..7)
		{
			CreateDoll(i,rangle+i*360/7,90,RSA*dir);
		}
		let Distance=0;
		let BossAngleFromDoll=0;
		loop
		{
		loop(60)
		{
			if(DollCenterY<GetCenterY)
			{
			DollCenterY+=1;
			}
			Distance=((GetY-DollCenterY)^2+(GetX-DollCenterX)^2)^0.5;
			BossAngleFromDoll=atan2(GetY-DollCenterY,GetX-DollCenterX);
		//	StringLaserEffect(DollCenterX,DollCenterY,Distance,5,BossAngleFromDoll);
			yield;
		}
		SetType;

		function SetType
		{
			PresentType=rand_int(153,159+limit);
			if(PresentType==PastType)
			{
				SetType;	
			}
			else if(PresentType==PastType2)
			{
				if(rand_int(0,1)==0)
				{
				SetType;
				}	
			}
			else if(PresentType==PastType3)
			{
				if(rand_int(0,2)==0)
				{
				SetType;
				}	
			}
		}
		if(PresentType!=160)
		{
		PastType3=PastType2;
		PastType2=PastType;
		PastType=PresentType;
		}
		LaserType=PresentType;
		wait(WaitTime-30);
		SetMovePosition03(rand(GetClipMinX+64,GetClipMaxX-64),rand(GetClipMinY+32,GetCenterY-32),20,3);
		SetAction(ACT_MOVE, 105);
	//	Shot1;
		wait(90);
		if(WaitTime>60)
		{
		WaitTime-=12;
		}
		RandType=rand_int(153,159);
		if(GetLife<MaxLife)
		{
			limit=1;
		}

		}
		task CreateDoll(num,angle,SpeedAngle,Rangle)
		{
			let DollX=GetX;
			let DollY=GetY;
			let ShotFlag=1;
			let X=GetX;
			let Y=GetY;
			let r=0;
			let rspeed=4;
			let DDangle=0;
			let rot=0;
			let rotmax=4.5;
			let obj = Obj_Create(OBJ_SHOT);
			DollObj=DollObj~[obj];
			DollDrawArray=DollDrawArray~[obj];

			Obj_SetPosition(obj, GetX, GetY);
			//Obj_SetSpeed(obj, Obj_GetSpeed(Pobj));
			//Obj_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, 9+Dollcolor);
			ObjShot_SetDelay(obj, 5);
			ObjShot_SetBombResist(obj,true);
			Obj_SetAutoDelete(obj,false);
			Obj_SetAlpha(obj,0);
			Obj_SetCollisionToPlayer(obj,false);

		//	FireLaser;
			String;
		//	let SpeedAngle=90+90*dir+rand(-30,30);
			let Speed=0.5;
		loop
		{
			let count=0;
			loop(30)
			{
				DollX=DollCenterX+r*cos(angle);
				DollY=DollCenterY+r*sin(angle);
				Obj_SetPosition(obj,DollX , DollY);
				angle+=rot*dir;		
				rot+=rotmax/30;
				if(r<320)
				{
				r+=rspeed;
				}
				count+=1;
				yield;
    			}
			loop(60)
			{
				DollX=DollCenterX+r*cos(angle);
				DollY=DollCenterY+r*sin(angle);
				Obj_SetPosition(obj,DollX , DollY);
				angle+=rot*dir;		
				if(r<320)
				{
				r+=rspeed;
				}
				count+=1;
				yield;
    			}
			loop(30)
			{
				DollX=DollCenterX+r*cos(angle);
				DollY=DollCenterY+r*sin(angle);
				Obj_SetPosition(obj,DollX , DollY);
				angle+=rot*dir;		
				rot-=rotmax/30;
				if(r<320)
				{
				r+=rspeed;
				}
				count+=1;
				yield;
    			}
			rot=0;
			DollX=DollCenterX+r*cos(angle);
			DollY=DollCenterY+r*sin(angle);
			Obj_SetPosition(obj,DollX , DollY);
			Laser(DollX,DollY,atan2(GetPlayerY-DollY,GetPlayerX-DollX),650,12,60,150,LaserType);
			wait(WaitTime);
			rotmax+=0.1;
		}

			task String
			{
				loop
				{
					StringLaserEffect(DollX,DollY,((GetY-DollY)^2+(GetX-DollX)^2)^0.5,5,atan2(GetY-DollY,GetX-DollX));
					yield;
				}
			}

		}
	}


task Laser(x,y,angle,length,width,delay,time,gra)
{
	let PX=GetPlayerX;
	let PY=GetPlayerY;
	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);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);
	Obj_SetAlpha(obj,150);
	let dcount=30;
	let lcount=0;
	loop(delay)
	{
		ObjShot_SetGraphic(obj,gra);
		EffectLaser(x,y,angle,length*lcount/30,width,0,2,gra);
		SetShotColor(255,255,255);
		ObjLaser_SetLength(obj,length*lcount/30);
		if(lcount<30)
		{
		lcount+=1;
		}
	yield;
	}
	loop(time-delay-15)
	{
		EffectLaser(x,y,angle,length,width*2,0,5,gra);
		ObjShot_SetGraphic(obj,gra);
		SetShotColor(255,255,255);
		yield;
	}
	Obj_SetCollisionToPlayer(obj,false);
	loop(15)
	{
		EffectLaser(x,y,angle,length,width*2*dcount/30,0,2,gra);
		ObjShot_SetGraphic(obj,gra);
		SetShotColor(255,255,255);
	ObjLaser_SetWidth(obj,width*dcount/30);
	dcount-=1;
	yield;
	}
	if(gra==160)
	{
		gra=RandType;
	}
	let SX=Obj_GetX(obj);
	let SY=Obj_GetY(obj);
	let EX=ObjLaser_GetEndX(obj);
	let EY=ObjLaser_GetEndY(obj);
	let sep=30;
	if(gra==155 || gra==156 || gra==157){sep=20;}
	let rangle=rand(0,360);
	ascent(i in 1..sep)
	{
		let ShotX=SX-(SX-EX)*i/sep;
		let ShotY=SY-(SY-EY)*i/sep;
		alternative(gra)
		case(153)
		{
		CreateShotA(0,ShotX,ShotY,10);
		SetShotDataA(0,0,0,rangle+i*10,0,0.01,1.25,gra-144);
		FireShot(0);
		}
		case(154)
		{
		CreateShotA(0,ShotX,ShotY,10);
		SetShotDataA(0,0,0,rand(0,360),0,0.01,rand(0.5,1),gra-144);
		FireShot(0);
		}
		case(155)
		{
		CreateShotA(1,ShotX,ShotY,10);
		CreateShotA(3,ShotX,ShotY,10);
		SetShotDataA(1,0,0,angle+90,0,0.0125,1.5,gra-144);
		SetShotDataA(3,0,0,angle-90,0,0.0125,1.5,gra-144);
		FireShot(1);
		FireShot(3);
		}
		case(156)
		{
		CreateShotA(0,ShotX,ShotY,10);
		SetShotDirectionType(PLAYER);
		SetShotDataA(0,0,0,rand(-5,5),0,0.02,2.0,gra-144);
		SetShotDirectionType(ABSOLUTE);
		FireShot(0);
		}
		case(157)
		{
		CreateShotA(0,ShotX,ShotY,10);
		SetShotDataA(0,0,0,atan2(GetPlayerY-PY,GetPlayerX-PX),0,0.02,2.0,gra-144);
		FireShot(0);
		}
		case(158)
		{
		CreateShotA(0,ShotX,ShotY,10);
		SetShotDataA(0,0,0,atan2(PY-ShotY,PX-ShotX)+rand(-10,10),0,0.015,1.5,gra-144);
		FireShot(0);
		}
		case(159)
		{
		CreateShotA(0,ShotX,ShotY,10);
		SetShotDataA(0,0,0,atan2(GetY-ShotY,GetX-ShotX)+rand(5,15)*(rand_int(0,1)*2-1),0,0.015,1.5,gra-144);
		FireShot(0);
		}
		//CreateShot01(ShotX,ShotY,2,angle,gra-144,10);
	}

	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 StringLaserEffect(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, -2);
		ObjEffect_SetVertexXY(obj, 1,length,  -2);
		ObjEffect_SetVertexXY(obj, 2,length, 2);
		ObjEffect_SetVertexXY(obj, 3,  0,  2);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  22, 27);
		ObjEffect_SetVertexUV(obj, 2, 22, 33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);

		let Alpha=60;

		let R=39;
		let G=64;
		let B=200;


		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(1)
		{
		yield;
		}
		Obj_Delete(obj);
}

}
//////////////////////////////////////////////////////////////////////
task shotA
{
let RSAMax=5;
let WideAngle=0;
let d=rand_int(0,1)*2-1;
let color=0;
let grad=75;
let Shotspeed=3.5;
let Intetrval=180;
let MaxLife=GetLife;
wait(30);
SetAction(ACT_SHOT_A, 60000);
Shot2;
Shot3;
loop
{
Shot1(d,color,grad,Shotspeed);
wait(floor(Intetrval));
color+=1;
d*=-1;
if(color>=7){color=0;}
}

task Shot2
{
wait(300);
let dir=1;
let waittime=60;
loop
{
	let ShotX=GetCenterX+rand(-10,10);
	ascent(i in -10..10)
	{
	//CreateShot01(ShotX+i*30,GetClipMinY-8,1,90-10*dir,9,0);
	CreateShot02(ShotX+i*30,GetClipMinY-8,6,90-10*dir,-0.1,1,9,0);
	}
	wait(waittime);
	if(GetLife>MaxLife*3/4)
	{
	if(waittime>50)
	{
		waittime-=1;
	}
	}
	else if(GetLife>MaxLife/2)
	{
	if(waittime>40)
	{
		waittime-=1;
	}
	}
	else if(GetLife>MaxLife/4)
	{
	if(waittime>30)
	{
		waittime-=1;
	}
	}
	else
	{
	if(waittime>20)
	{
		waittime-=1;
	}
	}
	dir*=-1;
}

}


task Shot3
{
while(GetLife>MaxLife/2){yield;}
let Cdir=rand_int(0,1)*2-1;
loop
{
	CircleCentralShot(Cdir);
	Cdir*=-1;
	wait(120);
}

	task CircleCentralShot(dir)
	{

			let obj = Obj_Create(OBJ_SHOT);
			Obj_SetPosition(obj, GetX, GetY);
			//Obj_SetSpeed(obj, Obj_GetSpeed(Pobj));
			//Obj_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, 9);
			ObjShot_SetDelay(obj, 5);
			ObjShot_SetBombResist(obj,true);
			Obj_SetAutoDelete(obj,false);
			Obj_SetAlpha(obj,0);
			Obj_SetCollisionToPlayer(obj,false);

			let angle=rand(0,360);
			let Yspeed=-1.5;
			ascent(i in 0..7)
			{
				CircleShot(obj,angle+360/7*i,dir);
			}
			loop(120)
			{
				Obj_SetY(obj,Obj_GetY(obj)+Yspeed);
				Yspeed+=0.025;
				yield;
			}
			loop(240)
			{
				Obj_SetY(obj,Obj_GetY(obj)+Yspeed);
				yield;
			}
			Obj_Delete(obj);
	}

	task CircleShot(Cobj,Cangle,dir)
	{

			let obj = Obj_Create(OBJ_SHOT);
			Obj_SetPosition(obj, GetX, GetY);
			//Obj_SetSpeed(obj, Obj_GetSpeed(Pobj));
			//Obj_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, 165);
			ObjShot_SetDelay(obj, 30);
			ObjShot_SetBombResist(obj,true);
			Obj_SetAutoDelete(obj,false);
		//	Obj_SetAlpha(obj,0);
		//	Obj_SetCollisionToPlayer(obj,false);

			let R1=0;
			let R2=0;
			while(!Obj_BeDeleted(Cobj))
			{
				Obj_SetPosition(obj, Obj_GetX(Cobj)+R1*cos(Cangle), Obj_GetY(Cobj)+R2*sin(Cangle));
				Cangle+=0.5*dir;
				if(R1<185)
				{
					ObjShot_SetDelay(obj, 10);
					R1+=185/60;
					R2+=20/60;
				}
				yield;
			}
			Obj_Delete(obj);
	}

}

	task Shot1(dir,Dollcolor,Grad,DollShotspeed)
	{
		let RSA=rand(0,RSAMax);
		let DollObj=[];

			let obj = Obj_Create(OBJ_SHOT);
			DollObj=DollObj~[obj];
			DollDrawArray=DollDrawArray~[obj];

			Obj_SetPosition(obj, GetX, GetY);
			//Obj_SetSpeed(obj, Obj_GetSpeed(Pobj));
			//Obj_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, 9+Dollcolor);
			ObjShot_SetDelay(obj, 5);
			ObjShot_SetBombResist(obj,true);
			Obj_SetAutoDelete(obj,false);
			Obj_SetAlpha(obj,0);
			Obj_SetCollisionToPlayer(obj,false);

		let rsangle=rand(-30,30);
		let rangle=rand(0,360);
		let DollCenterX=GetCenterX+192*dir;
		let DollCenterY=GetClipMinY-64;
		let DollCenterAngle=GetAngleToPlayer+Grad*dir;

		let Distance=0;
		let BossAngleFromDoll=0;
		let speed=1;
		let BaseAngleToPlayerFromCentralDoll=atan2((GetClipMaxY-48)-DollCenterY,GetCenterX-DollCenterX);
		let AngleToPlayerFromCentralDoll=atan2(GetPlayerY-DollCenterY,GetPlayerX-DollCenterX);
		let GapAngle=AngleToPlayerFromCentralDoll-BaseAngleToPlayerFromCentralDoll;
		let angle=90;
		DollCenterAngle=90+GapAngle;
		CShot1;
		loop(900)
		{
			DollCenterAngle+=0.105*dir;
			DollCenterX+=speed*cos(DollCenterAngle);
			DollCenterY+=speed*sin(DollCenterAngle);
			Obj_SetPosition(obj, DollCenterX, DollCenterY);
			Distance=((GetY-DollCenterY)^2+(GetX-DollCenterX)^2)^0.5;
			BossAngleFromDoll=atan2(GetY-DollCenterY,GetX-DollCenterX);
			StringLaserEffect(DollCenterX,DollCenterY,Distance,5,BossAngleFromDoll);
			yield;
		}
		DollDrawArray=erase(DollDrawArray,0);
		Obj_Delete(obj);
			task String
			{
				loop
				{
			//		StringLaserEffect(DollX,DollY,((GetY-DollY)^2+(GetX-DollX)^2)^0.5,5,atan2(GetY-DollY,GetX-DollX));
					yield;
				}
			}

		task CShot1
		{
		let Shotdir=rand_int(0,1)*2-1;
		let CSAngle=rand(0,360);
		loop
		{
			loop(4)
			{
				ascent(i in 0..4)
				{
				CreateShot01(DollCenterX,DollCenterY,1.5,CSAngle+i*90,9,0);
				}
				CSAngle-=1*Shotdir;
				wait(3);
			}
			wait(15);
			CSAngle-=5*Shotdir;
		}
		}

	}

task StringLaserEffect(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, -2);
		ObjEffect_SetVertexXY(obj, 1,length,  -2);
		ObjEffect_SetVertexXY(obj, 2,length, 2);
		ObjEffect_SetVertexXY(obj, 3,  0,  2);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  22, 27);
		ObjEffect_SetVertexUV(obj, 2, 22, 33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);

		let Alpha=60;

		let R=39;
		let G=64;
		let B=200;


		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(1)
		{
		yield;
		}
		Obj_Delete(obj);
}

}

#include_function ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_Alice.txt"
#include_function ".\..\lib/lib_anime_doll.txt"
}

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