
#Title[ぬえ３]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_nue.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 116;
	let Step2=false;
	let wIni=60;
let TimeCounter=44*60;
let StandardTimeCounter=TimeCounter;
let ColorRed=255;
let ColorGreen=0;
let ColorBlue=0;
    @Initialize {
	SetX(GetCommonDataDefault("BossX",0));
	SetY(GetCommonDataDefault("BossY",0));
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
	SetCommonData("BossLastAttackColor",[148,0,211]);
	SetCommonData("BossLastAttack",true);
	SetShotAutoDeleteClip(64,64,64,64);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetLife(2600);
 LoadGraphic(GetCurrentScriptDirectory~"..\img\CircleEffect.png");
	InitializeAction();
	SetEnemyMarker(true);
        TMainGrobal;
    }

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

    @DrawLoop {
//DrawText(GetCommonDataDefault("XXX",0),120,452,12,255);
//DrawText(GetCommonDataDefault("XXX2",0),120,402,12,255);
	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",300000);
    }

    // メインタスク
task TMainGrobal
{
	yield;
	GetDamege;
	OutDamageRateZero;
	Collision;
	//Lissajous(148,0,211);
	BossShadowAnimation(imgBoss2,0,148,0,211);
	standBy;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	DamageRate=85;
	shotA;
	}
	SpellDraw(14,6000);
	wait(29);
	HueDifine;
}

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

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

}

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(xIni, yIni,30,8);
	wait(90);
	Concentration01(30);
}

task shotM
{
//wait(60);
SetAction(ACT_SHOT_A, 6000);
shot;

task shot
{
let way=1;
let maxway=8;
let angle=270;
let angle2=270;
let dangle=rand(0,360);
let dir=rand_int(0,1)*2-1;
let speed=3.5;
	loop
	{
		let Spin=rand(0.48,0.5);
		
		ascent(i in -way..way+1)
		{
			CreateShot01(GetX,GetY,speed,angle+i*180/maxway,9,5);
			CreateShot01(GetX,GetY,speed,angle+i*180/maxway+90/maxway,14,5);
			CreateShotA(0,GetX,GetY,5);
			SetShotDataA(0,0,speed,angle+i*180/maxway+90/maxway,Spin*dir,0,0,14);
			FireShot(0);
			CreateShotA(0,GetX,GetY,5);
			SetShotDataA(0,0,speed,angle+i*180/maxway+90/maxway,-Spin*dir,0,0,14);
			FireShot(0);
		
		}
		angle=270+5*sin(dangle)+rand(-1.8,1.8);
		angle2=270+5*sin(dangle)+rand(-1.5,1.5);
		dangle+=12;
		dir=dir*-1;
		if(way<maxway)
		{
		way+=1;
		wait(10);
		}
		else
		{
		wait(rand_int(10,13));
		}
	}
}

task Bullet1(x,y,angle)
{
		let speed=4;
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, 12);
		ObjShot_SetDelay(obj, 5);
		Obj_SetAutoDelete(obj,false);
		//Obj_SetAlpha(obj,0);
		//Obj_SetCollisionToPlayer(obj,false);
		wait(30);
		CreateShot01(Obj_GetX(obj),Obj_GetY(obj),speed,angle+60,9,0);
		CreateShot01(Obj_GetX(obj),Obj_GetY(obj),speed,angle-60,9,0);
}

}
///////////////////////////////////////////////////////
task shotE
{
SetAction(ACT_SHOT_A, 6000);
upLaser;
wait(30);
downLaser1;
wait(30);
downLaser2;

task upLaser
{
	let Radius=25;
	loop
	{
		let angle1=rand(200,300);
		let angle2=rand(240,340);
		Laser01(GetX+Radius*cos(angle1),GetY+Radius*sin(angle1),4,angle1,96,8,231,0);
		Laser01(GetX+Radius*cos(angle2),GetY+Radius*sin(angle2),4,angle2,96,8,225,0);
		wait(3);
	}
	wait(30);
}


task downLaser1
{
let speed=5;
let waittime=60;
	loop
	{
		ascent(let i in -12..8)
		{
		Laser01(GetCenterX+i*25,GetClipMinY-rand(0,100),rand(5,6),80-i,120,10,231,0);
		//Laser01(GetCenterX+i*60+rand(-5,5),GetClipMinY-rand(30,120),speed,rand(67.5,72.5),200,10,231,0);
		wait(2);
		}
/*
		ascent(let i in -6..4)
		{
		Laser01(GetCenterX+i*50,GetClipMinY-rand(0,150),speed,70,120,10,231,0);
		//Laser01(GetCenterX+i*60+rand(-5,5),GetClipMinY-rand(30,120),speed,rand(67.5,72.5),200,10,231,0);
		wait(3);
		}
*/
	wait(30);
	}
}

task downLaser2
{
let speed=5;
let waittime=60;
	loop
	{
		descent(let i in -8..12)
		{
		Laser01(GetCenterX+i*25,GetClipMinY-rand(0,100),rand(5,6),100-i,120,10,225,0);
	//	Laser01(GetCenterX+i*60+rand(-5,5),GetClipMinY-rand(30,120),speed,rand(107.5,112.5),200,10,225,0);
		wait(2);
		}
/*
		descent(let i in -4..6)
		{
		Laser01(GetCenterX+i*50,GetClipMinY-rand(0,150),speed,110,120,10,225,0);
	//	Laser01(GetCenterX+i*60+rand(-5,5),GetClipMinY-rand(30,120),speed,rand(107.5,112.5),200,10,225,0);
		wait(3);
		}
*/
		wait(30);
	}
}

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,false);
	//Obj_SetCollisionToPlayer(obj,false);
	//ObjShot_SetBombResist(obj,true);
	let r=0;
	loop(Slength/speed)
	{
		ObjLaser_SetLength(obj,length);
		length+=speed;
		yield;
	}
	let time=rand_int(15,30);
	loop(20)
	{
		Obj_SetPosition(obj,x+r*cos(angle),y+r*sin(angle));
		r+=speed;
		yield;
	}
	if(y<GetClipMinY+32)
	{
	let PX=Obj_GetX(obj);
	let PY=Obj_GetY(obj);
	let SX=ObjLaser_GetEndX(obj);
	let SY=ObjLaser_GetEndY(obj);
	if(graphic==225)
	{
	ascent(i in 0..4)
	{
		CreateShot01(PX-(PX-SX)*i/3,PY-(PY-SY)*i/3,3-i/3,angle+rand(-7,7),41,0);
		ShotEffect(PX-(PX-SX)*i/3,PY-(PY-SY)*i/3,5,150,255,50,50)
	}
	}
	if(graphic==231)
	{
	ascent(i in 0..4)
	{
		CreateShot01(PX-(PX-SX)*i/3,PY-(PY-SY)*i/3,3-i/3,angle+rand(-7,7),47,0);
		ShotEffect(PX-(PX-SX)*i/3,PY-(PY-SY)*i/3,5,150,255,50,255)
	}
	}
	}
	else
	{
	loop(30)
	{
		Obj_SetPosition(obj,x+r*cos(angle),y+r*sin(angle));
		r+=speed;
		yield;
	}
	}
	Obj_Delete(obj);
}

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 shotA
{
wait(30);
SetAction(ACT_SHOT_A, 6000);
let dir=rand_int(0,1)*2-1;
let time=60;

Shot1;
Shot2;
	task Shot1
	{
	upLaser;
	wait(75);
	let angle;
	let anglePlus;
	loop
	{
		angle=rand(85,95);
		anglePlus=rand(0.25,0.5)*(rand_int(0,1)*2-1);
		Bullet1(rand(GetClipMinX,GetCenterX),rand(-32,-96),6,angle,anglePlus,241);
		wait(18);
		angle=rand(85,95);
		anglePlus=rand(0.25,0.5)*(rand_int(0,1)*2-1);
		Bullet1(rand(GetCenterX,GetClipMaxX),rand(-32,-64),6,angle,anglePlus,241);
		wait(18);
	}

	}

task Shot2
{
	wait(120);
	let R=30;
	let angle=0;
	loop
	{
		loop(15)
		{
		ascent(j in -1..2)
		{
		ascent(i in -2..3)
		{
		CreateShot01(GetX+R*cos(angle+j*120),GetY+R*sin(angle+j*120),3,angle+i*2+j*120,14,5);
		CreateShot01(GetX+R*cos(angle+j*120),GetY+R*sin(angle+j*120),3,angle+i*2+j*120,246,6);
		}
		}
		angle+=21;
		wait(7);
		}
		//wait(120);
	}
}

task upLaser
{
	let Radius1=60;
	let Radius2=10;
	let angle1=0;
	loop(60)
	{
		Laser01(GetX+Radius1*cos(angle1),GetY+Radius2*sin(angle1)+20,8,270,128,8+2*cos(angle1-90),225,0);
		Laser01(GetX+Radius1*cos(angle1+120),GetY+Radius2*sin(angle1+120)+20,8,270,128,8+2*cos(angle1-90+120),225,0);
		Laser01(GetX+Radius1*cos(angle1+240),GetY+Radius2*sin(angle1+240)+20,8,270,128,8+2*cos(angle1-90+240),225,0);
		angle1+=6;
		wait(1);
	}
	wait(30);
}

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,false);
	Obj_SetAlpha(obj,255*width/10);
	//Obj_SetCollisionToPlayer(obj,false);
	ObjShot_SetBombResist(obj,false);
	let r=0;
	loop(Slength/speed)
	{
		ObjLaser_SetLength(obj,length);
		length+=speed;
		yield;
	}
	let time=rand_int(15,30);
	loop(20)
	{
		Obj_SetPosition(obj,x+r*cos(angle),y+r*sin(angle));
		r+=speed;
		yield;
	}
	if(y<GetClipMinY+32)
	{
	let PX=Obj_GetX(obj);
	let PY=Obj_GetY(obj);
	let SX=ObjLaser_GetEndX(obj);
	let SY=ObjLaser_GetEndY(obj);
	if(graphic==225)
	{
	ascent(i in 0..4)
	{
		CreateShot01(PX-(PX-SX)*i/3,PY-(PY-SY)*i/3,3-i/3,angle+rand(-7,7),41,0);
	//	ShotEffect(PX-(PX-SX)*i/3,PY-(PY-SY)*i/3,5,150,255,50,50)
	}
	}
	if(graphic==231)
	{
	ascent(i in 0..4)
	{
		CreateShot01(PX-(PX-SX)*i/3,PY-(PY-SY)*i/3,3-i/3,angle+rand(-7,7),47,0);
	//	ShotEffect(PX-(PX-SX)*i/3,PY-(PY-SY)*i/3,5,150,255,50,255)
	}
	}
	}
	else
	{
	loop(30)
	{
		Obj_SetPosition(obj,x+r*cos(angle),y+r*sin(angle));
		r+=speed;
		yield;
	}
	}
	Obj_Delete(obj);
}

task Bullet1(x,y,speed,angle,anglespeed,color)
{
	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,color);
	Obj_SetAutoDelete(obj,false);
	ObjSinuateLaser_SetLength(obj,30);
	ObjSinuateLaser_SetWidth(obj,8);
	ObjShot_SetBombResist(obj,false);

	//	Shot;
	//	EffectBullet(obj,color);
		let R=0;
		loop(30)
		{
			Obj_SetX(obj,Obj_GetX(obj)+speed*cos(angle));
			Obj_SetY(obj,Obj_GetY(obj)+speed*sin(angle));
			angle+=anglespeed;
			Obj_SetAngle(obj,angle);
			wait(1);
		}
		//EffectBullet(obj,color);
		Bullet2(Obj_GetX(obj),Obj_GetY(obj),speed,angle+20,anglespeed,color);
		Bullet2(Obj_GetX(obj),Obj_GetY(obj),speed,angle-20,anglespeed,color);
		loop(120)
		{
			Obj_SetX(obj,Obj_GetX(obj)+speed*cos(angle));
			Obj_SetY(obj,Obj_GetY(obj)+speed*sin(angle));
			angle+=anglespeed;
			Obj_SetAngle(obj,angle);
			wait(1);
		}
		Obj_Delete(obj);
}

task Bullet2(x,y,speed,angle,anglespeed,color)
{
	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,color);
	Obj_SetAutoDelete(obj,false);
	ObjSinuateLaser_SetLength(obj,30);
	ObjSinuateLaser_SetWidth(obj,8);
	ObjShot_SetBombResist(obj,false);
	//	Shot;
	//	EffectBullet(obj,color);
		let R=0;
		loop(120)
		{
			Obj_SetX(obj,Obj_GetX(obj)+speed*cos(angle));
			Obj_SetY(obj,Obj_GetY(obj)+speed*sin(angle));
			angle+=anglespeed;
			Obj_SetAngle(obj,angle);
			wait(1);
		}
		Obj_Delete(obj);
}

task EffectBullet(Cobj,gra)
{
		let speed=4;
		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, 5);
	//	Obj_SetAutoDelete(obj,false);
		Obj_SetAlpha(obj,0);
		//Obj_SetCollisionToPlayer(obj,false);
		ObjShot_SetBombResist(obj,true);
		while(!Obj_BeDeleted(Cobj))
		{
			Obj_SetPosition(obj, Obj_GetX(Cobj),Obj_GetY(Cobj));
			ObjShot_SetDelay(obj, 5);
			yield;
		}
		Obj_Delete(obj);
}

}

task HueDifine
{
let HueCount=0;
let MinColor=50;
loop
{
	if(0<HueCount && HueCount<=60)
	{
		ColorRed=255;
		ColorGreen=255*(HueCount)/60;
		ColorBlue=0;
	}
	else if(HueCount<=120)
	{
		ColorRed=255*(120-HueCount)/60;
		ColorGreen=255;
		ColorBlue=0;
	}
	else if(HueCount<=180)
	{
		ColorRed=0;
		ColorGreen=255;
		ColorBlue=255*(HueCount-120)/60;
	}
	else if(HueCount<=240)
	{
		ColorRed=0;
		ColorGreen=255*(240-HueCount)/60;
		ColorBlue=255;
	}
	else if(HueCount<=300)
	{
		ColorRed=255*(HueCount-240)/60;
		ColorGreen=0;
		ColorBlue=255;
	}
	else if(HueCount<=360)
	{
		ColorRed=255;
		ColorGreen=0;
		ColorBlue=255*(360-HueCount)/60;
	}
	HueCount+=3;
	if(HueCount>=361){HueCount=1;}
yield;
}
}

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

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