
#Title[大妖精通常]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_daiyousei.png"; 
    let imgBoss2 =csd ~ "..\lib/dot_daiyousei2.png";
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let Step2=false;
	let wIni=60;
let TimeCounter=50*60;
let StandardTimeCounter=TimeCounter;
let ColorRed=255;
let ColorGreen=0;
let ColorBlue=0;
let countangle=0;
    @Initialize {
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
	SetX(GetCommonDataDefault("BossX",0));
	SetY(GetCommonDataDefault("BossY",0));
	SetCommonData("BossLastAttackColor",[0,250,154]);
	SetCommonData("BossLastAttack",true);
	SetShotAutoDeleteClip(32,40,32,32);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetLife(3500);
	InitializeAction();
	SetEnemyMarker(true);
        TMainGrobal;
    }

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

    @DrawLoop {
	DrawBoss( imgBoss );
	//DrawText(countangle,120,382,12,255);//起動時間の表示
    }

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

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

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 Particle
{
loop
{
ParticleEffect;
wait(5);
}
}

task ParticleEffect
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd~"..\img\ParticleEffect.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,  0);
		ObjEffect_SetVertexUV(obj, 1,  16, 0);
		ObjEffect_SetVertexUV(obj, 2, 16,  16);
		ObjEffect_SetVertexUV(obj, 3, 0, 16);
		let Alpha=100;
		let StandardAlpha=Alpha;
		let R;let G;let B;
		R=0;G=255;B=0;
		ObjEffect_SetLayer(obj,1);
		Obj_SetPosition(obj,GetX+rand(-20,20),GetY+rand(-20,20));
		let speed=rand(0.5,1.0);
		let angle=rand(88,92);
		let Scale=0.5;
		let StandardScale=Scale;
		if(GetCommonDataDefault("LightMode_BossBlur",0)==1){Obj_Delete(obj);return;}
		loop(30)
		{
			Alpha-=StandardAlpha/30;
			Scale-=StandardScale/30;
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			ObjEffect_SetScale(obj,Scale,Scale);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		Obj_Delete(obj);
}

task shotM
{
	SpellDraw(0,6000);
	shot;
	shot2;

task shot2
{
wait(20);
let angle=-80;
let dir=1;
let r=24;
	SetAction(ACT_SHOT_B,6000);
loop
{
	loop(3)
	{
	SetShotColor(ColorRed,ColorGreen,ColorBlue);
	CreateShot01(GetX+r*cos(angle),GetY+r*sin(angle),3,angle,16,0);
	CreateShot01(GetX+r*cos(angle),GetY+r*sin(angle),3,angle,248,1);
	CreateShot01(GetX+r*cos(180-angle),GetY+r*sin(180-angle),3,180-angle,16,0);
	CreateShot01(GetX+r*cos(180-angle),GetY+r*sin(180-angle),3,180-angle,248,1);
	SetShotColor(255,255,255);
	ShotEffect(GetX+r*cos(angle),GetY+r*sin(angle),10,150,ColorRed,ColorGreen,ColorBlue);
	ShotEffect(GetX+r*cos(180-angle),GetY+r*sin(180-angle),10,150,ColorRed,ColorGreen,ColorBlue);
	if(dir==1)
	{
		angle+=1.27;
		if(angle>75)
		{
			dir=-1;
		}
	}
	else if(dir==-1)
	{
		angle-=1.27;
		if(angle<-75)
		{
			dir=1;
		}
	}
	countangle=angle;
	yield;
	}
wait(1);
angle+=7.5*dir;
	
}
}

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=0.8;
		loop(delay)
		{
			ObjEffect_SetScale(obj, Scale, Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=6;
			Scale-=1.0/delay;
			yield;
		}
		Obj_Delete(obj);
}

task shot
{
wait(120);
loop
{
let WaitTime=50;
loop(6)
{
	Laser(GetClipMinX-8,GetCenterY+rand(-80,10),rand(-30,-15));
	wait(WaitTime);
	Laser(GetClipMaxX+8,GetCenterY+rand(-80,10),rand(195,220));
	wait(WaitTime);
	if(WaitTime>20)
	{
	WaitTime-=2;
	}
}
}
}

task Laser(x,y,angle)
{
	let length=0;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,x,y);
	Obj_SetAngle(obj,angle);
	ObjShot_SetGraphic(obj,161);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,8);
	ObjLaser_SetSource(obj,false);
	Obj_SetCollisionToPlayer(obj,false);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAlpha(obj,0);
	let count=0;
	EffectShot(x,y,angle);
	while(ObjLaser_GetEndY(obj)>=GetClipMinY-4 && count<90)
	{
		ObjLaser_SetLength(obj,length);
		ObjShot_SetDelay(obj,1);
		length+=8;
		count+=1;
		yield;
	}
	let LX=x-ObjLaser_GetEndX(obj);
	let LY=y-ObjLaser_GetEndY(obj);
	ascent(let i in 0..12)
	{
		SetShotColor(255,255,255);
	//	CreateShot01(x-LX*i/14,y-LY*i/14,rand(2.5,4),rand(87.5,92.5),9+round(i/2),5);
		CreateShot02(x-LX*i/14,y-LY*i/14,0,rand(87.5,92.5),0.1,rand(2.0,3.5),9+round(i/2),15);
	}
	ascent(let i in 12..14)
	{
		SetShotColor(255,255,255);
	//	CreateShot01(x-LX*i/14,y-LY*i/14,rand(2.5,4),rand(87.5,92.5),9,5);
		CreateShot02(x-LX*i/14,y-LY*i/14,0,rand(87.5,92.5),0.1,rand(2.0,3.5),9,15);
	}
	Obj_Delete(obj);

	task EffectShot(x,y,angle)
	{
		let Sobj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(Sobj, x,y);
		Obj_SetSpeed(Sobj, 8);
		Obj_SetAngle(Sobj, angle);
		ObjShot_SetGraphic(Sobj, 16);
	//	ObjShot_SetDelay(Sobj, 5);
		Obj_SetAutoDelete(Sobj,false);
		Obj_SetAlpha(Sobj,0);
		Obj_SetCollisionToPlayer(Sobj,false);
		ObjShot_SetBombResist(Sobj,true);
		let CircleAngle=rand(0,360);

		let ShotColorRed=255;
		let ShotColorGreen=0;
		let ShotColorBlue=0;

		let time=absolute((y-(GetClipMinY-4))/(8*sin(angle)));

		time=round(time);
		if(time>90){time=90;}
		ShotHueDifine(time);

		let count=time;
		loop(time)
		{
			SetShotColor(ShotColorRed,ShotColorBlue,ShotColorGreen);
			DelayEffectShot(Obj_GetX(Sobj),Obj_GetY(Sobj),count);
			SetShotColor(255,255,255);
			count-=1;
			yield;
		}
		Obj_Delete(Sobj);

	task DelayEffectShot(x,y,time)
	{
		SetShotColor(ShotColorRed,ShotColorBlue,ShotColorGreen);
		let Eobj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(Eobj, x,y);
	//	Obj_SetSpeed(Eobj, 6);
	//	Obj_SetAngle(Eobj, angle);
		ObjShot_SetGraphic(Eobj, 16);		
		Obj_SetAutoDelete(Eobj,false);
		Obj_SetAlpha(Eobj,0);
		Obj_SetCollisionToPlayer(Eobj,false);
		ObjShot_SetBombResist(Eobj,true);
		let CircleAngle=rand(0,360);
		loop(time)
		{
			ObjShot_SetDelay(Eobj, 2);
			yield;
		}
		Obj_Delete(Eobj);
	}

	task ShotHueDifine(time)
	{
	let HueCount=375;
	let MinColor=50;
	while(!Obj_BeDeleted(obj))
	{
		if(0<HueCount && HueCount<=60)
		{
		ShotColorRed=255;
		ShotColorGreen=255*(HueCount)/60;
		ShotColorBlue=0;
		}
		else if(HueCount<=120)
		{
		ShotColorRed=255*(120-HueCount)/60;
		ShotColorGreen=255;
		ShotColorBlue=0;
		}
		else if(HueCount<=180)
		{
		ShotColorRed=0;
		ShotColorGreen=255;
		ShotColorBlue=255*(HueCount-120)/60;
		}
		else if(HueCount<=240)
		{
		ShotColorRed=0;
		ShotColorGreen=255*(240-HueCount)/60;
		ShotColorBlue=255;
		}
		else if(HueCount<=300)
		{
		ShotColorRed=255*(HueCount-240)/60;
		ShotColorGreen=0;
		ShotColorBlue=255;
		}
		else if(HueCount<=360)
		{
		ShotColorRed=255;
		ShotColorGreen=0;
		ShotColorBlue=255*(360-HueCount)/60;
		}
		HueCount-=360/time;
	//	if(HueCount>=361){HueCount=1;}
		yield;
	}
	}
	
	}

}

}
///////////////////////////////////////////////////////
task shotE
{
	SpellDraw(1,6000);
	shot2;

task shot2
{
wait(30);
let angle=rand(0,360);
let angleplus=0.5*5/6;
let r=0;
let t=0;
SetAction(ACT_SHOT_B,6000);
loop
{
loop(6)
{
	ascent(let i in -15..15)
	{
		//CreateShot01(GetX+r*cos(angle+i*12),GetY+r*sin(angle+i*12),4.75,angle+i*12,9+t%7,5);
		CreateShotA(0,GetX,GetY,5);
		SetShotDataA(0,0,3,angle+i*12,0,-0.05,-10,241+t%7);
		SetShotDataA(0,60,NULL,angle+i*12+15,0,-0.05,-5,9+t%7);
	//	SetShotDataA(0,60,NULL,NULL,0,+0.05,10,9+t%7);
		FireShot(0);
	}
	angle+=angleplus;
	wait(5);
}

angleplus+=0.25+0.05;
wait(15);
	t+=1;

loop(6)
{
	ascent(let i in -15..15)
	{
	//	CreateShot01(GetX+r*cos(angle+i*12),GetY+r*sin(angle+i*12),4.75,angle+i*12,9+t%7,5);
		CreateShotA(0,GetX,GetY,5);
		SetShotDataA(0,0,3,angle+i*12,0,-0.05,-10,241+t%7);
		SetShotDataA(0,60,NULL,angle+i*12-15,0,-0.05,-5,9+t%7);
	//	SetShotDataA(0,60,NULL,NULL,0,+0.05,10,9+t%7);
	//	SetShotDataA(0,0,5,angle+i*12,0,-0.05,-10,9+t%7);
		FireShot(0);
	}
	angle-=angleplus;
	wait(5);
}
angleplus+=0.25+0.05;
wait(15);
t+=1;

}
}

}
/////////////////////////////////////////////////////////////////
task shotA
{
wait(60);
	SpellDraw(2,6000);
	shot;

task shot
{
let angle=-90;
let dir=rand_int(0,1)*2-1;
let waittime=162;
let speed=2;
let color=999;
let gra=0;
SetAction(ACT_SHOT_B,6000);
loop
{
	angle=rand(0,360);

ascent(i in 0..72)
{
	CreateShotA(0,GetX,GetY,5);
	SetShotDataA(0,0,4.5*1.75,angle+i*5,0,-0.1*1.75,0,248);
	SetShotDirectionType(PLAYER);
	SetShotDataA(0,45,0,0,0,0.02+4*0.009,1.0+4*0.45,16);
	SetShotDirectionType(ABSOLUTE);
	FireShot(0);
}


ascent(i in 0..24)
{
	ascent(j in 0..7)
	{
	let R=40+j*20;
	let x=GetX+R*cos(angle+i*15+j%2*5);
	let y=GetY+R*sin(angle+i*15+j%2*5);
	let sangle=atan2(GetY-y,GetX-x);
	CreateShotA(0,x,y,5);
	SetShotDataA(0,0,0,angle+i*15+j%2*5,0,0,0,247-j);
	SetShotDataA(0,45-i,0,sangle+45*((j%2)*2-1),0,0.02+j*0.008,1.25+j*0.45,15-j);
	FireShot(0);
	}
	ascent(j in 0..7)
	{
	let R=40+j*20;
	let x=GetX+R*cos(angle-i*15+7.5+j%2*5);
	let y=GetY+R*sin(angle-i*15+7.5+j%2*5);
	let sangle=atan2(GetY-y,GetX-x);
	CreateShotA(0,x,y,5);
	SetShotDataA(0,0,0,angle-i*15+7.5+j%2*5,0,0,0,247-j);
	SetShotDataA(0,45-i,0,sangle+45*((j%2)*2-1),-0,0.02+j*0.008,1.25+j*0.45,15-j);
	FireShot(0);
	}

	wait(1);
}
wait(waittime);
if(waittime>60)
{
waittime-=6;
}
}

}

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

}

/*
task shotA
{
	SpellDraw(2,6000);
	shot;

task shot
{
wait(30);
let angle=-90;
let dir=rand_int(0,1)*2-1;
let waittime=30;
let speed=2;
let color=999;
let gra=0;
SetAction(ACT_SHOT_B,6000);
loop
{
let r=2.5;
angle=rand(0,360);
ascent(let j in 1..7)
{
ascent(let i in 0..36)
{
gra=(j)%2+color%7;
if(gra==7){gra=0;}
CreateShotA(0,GetX,GetY,0);
SetShotDataA(0,0,j,angle+i*10,r*dir,-j/60,0,247-gra);
SetShotDataA(0,60,speed,NULL,0,0,5,15-gra);
FireShot(0);
}
wait(5);
}
dir=dir*-1;
wait(waittime);
if(waittime>5)
{
waittime-=2;
speed+=1/15;
}
color-=1;
	
}
}

}
*/

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_Daiyousei.txt"
}

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