
#Title[大妖精通常]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_daiyousei.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 {
	SetCommonData("BossLastAttackColor",[0,250,154]);
	SetCommonData("BossLastAttack",true);
	SetShotAutoDeleteClip(10,10,10,10);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetTimer(TimeCounter/60);
        SetLife(3500);
	InitializeAction();
	SetEnemyMarker(true);
        TMainGrobal;
    }

    @MainLoop {
	BulletNum=GetEnemyShotCount;
	TimeCounter-=1;
        yield;
    }

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

    @Finalize {
		if(!IsTimeOut)
		{
		SetCommonData("DeleteBulletNum",BulletNum);
		SetCommonData("DeleteBulletX",GetX);
		SetCommonData("DeleteBulletY",GetY);
		}

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

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

task Collision
{
	wait(90);

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

}

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

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,15);
	CreateShot01(GetX+r*cos(angle),GetY+r*sin(angle),3,angle,248,16);
	CreateShot01(GetX+r*cos(180-angle),GetY+r*sin(180-angle),3,180-angle,16,15);
	CreateShot01(GetX+r*cos(180-angle),GetY+r*sin(180-angle),3,180-angle,248,16);
	SetShotColor(255,255,255);

	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 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,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,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
{
	SpellDraw(2,6000);
	shot;

task shot
{
wait(30);
let angle=-90;
let dir=rand_int(0,1)*2-1;
let waittime=60;
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);

}
}
dir=dir*-1;
wait(waittime);
if(waittime>30)
{
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"
