
#Title[大妖精通常]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "大妖精";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_nue.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 116;
	let Step2=false;
	let wIni=60;
let TimeCounter=40*60;
let StandardTimeCounter=TimeCounter;
let VanishLife=1000;
let ColorRed=255;
let ColorGreen=0;
let ColorBlue=0;
    @Initialize {
	SetCommonData("BossLastAttackColor",[148,0,211]);
	SetCommonData("BossLastAttack",true);
	SetShotAutoDeleteClip(10,10,10,10);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetTimer(TimeCounter/60);
        SetLife(2200);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
 LoadGraphic(GetCurrentScriptDirectory~"..\img\CircleEffect.png");
	InitializeAction();
	SetEnemyMarker(true);
        TMainGrobal;
    }

    @MainLoop {
	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 {
		if(!IsTimeOut)
		{
		SetCommonData("DeleteBulletNum",BulletNum);
		SetCommonData("DeleteBulletX",GetX);
		SetCommonData("DeleteBulletY",GetY);
		}

	SetCommonData("VanishSignal",false);
       DeleteGraphic(imgBoss);
	SetCommonData("TimeBonus",TimeCounter/StandardTimeCounter);
	SetCommonData("BossRate",25000);
    }

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

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
{
//wait(60);
SetAction(ACT_SHOT_A, 6000);
shot;

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

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(15);
downLaser2;

task upLaser
{
	loop
	{
		Laser01(GetX,GetY,4,rand(200,300),96,8,231,0);
		Laser01(GetX,GetY,4,rand(240,340),96,8,225,0);
		wait(3);
	}
}


task downLaser1
{
let speed=5;
let waittime=60;
	loop
	{
		ascent(let i in -5..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(30);
	}
}

task downLaser2
{
let speed=5;
let waittime=60;
	loop
	{
		ascent(let i in -4..5)
		{
		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(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;
	}
	loop(240)
	{
		Obj_SetPosition(obj,x+r*cos(angle),y+r*sin(angle));
		r+=speed;
		yield;
	}
	Obj_Delete(obj);
}

}
/////////////////////////////////////////////////////////////////
task shotA
{
//wait(30);
SetAction(ACT_SHOT_A, 6000);
let dir=rand_int(0,1)*2-1;
let time=90;
loop
{
let angle=rand(0,360);
ascent(i in 0..24)
{
Bullet1(GetX,GetY,10,angle+i*15,225,5,3*dir);
}
dir=dir*-1;
wait(time);
if(time>60)
{
time-=2;
}
}
	//shot;

task Bullet1(x,y,speed,angle,color,delay,spin)
{
		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);
		LaserShot;
		loop(45)
		{
			Obj_SetAngle(obj,angle);
			angle+=+spin;
			wait(1);
		}
		Obj_Delete(obj);


	task LaserShot
	{
	wait(3);
	let waittime=45;
		loop(13)
		{
			SpinShot(Obj_GetX(obj),Obj_GetY(obj),Obj_GetAngle(obj)+spin,waittime);
			wait(3);
			waittime-=3;
		}
	}

	task SpinShot(x,y,angle,Time)
	{
		if(spin>0)
		{
		CreateShot02(x,y,0,angle,0.01,3,9,Time);
		}
		else
		{
		CreateShot02(x,y,0,angle,0.01,3,14,Time);
		}
	}

/*
		wait(30);
		CreateShot01(Obj_GetX(obj),Obj_GetY(obj),speed,angle+60,10-spin,0);
		CreateShot01(Obj_GetX(obj),Obj_GetY(obj),speed,angle-60,9,0);
*/
}

task Snake(x,y,v,angle,length,width,color,delay,spin)
{
         let snake = Obj_Create(OBJ_SINUATE_LASER);
         Obj_SetX(snake,x);
         Obj_SetY(snake,y);
         Obj_SetSpeed(snake,v);
         Obj_SetAngle(snake,angle-spin*spin*2);
         ObjShot_SetBombResist(snake,true);
         ObjShot_SetDelay(snake,delay);
         ObjShot_SetGraphic(snake,168);
         ObjSinuateLaser_SetLength(snake,length);
         ObjSinuateLaser_SetWidth(snake,width);
	Angle;
	LaserShot;
        task Angle
	{
		loop(90)
		{
			Obj_SetAngle(snake,angle);
			angle+=+spin;
			wait(1);
		}
		Obj_Delete(snake);
	}

	task LaserShot
	{
	wait(18);
	let waittime=75;
		loop(30)
		{
			SpinShot(Obj_GetX(snake),Obj_GetY(snake),Obj_GetAngle(snake)+spin,waittime);
			wait(3);
			waittime-=3;
		}
	}

	task SpinShot(x,y,angle,Time)
	{
		wait(Time);
		CreateShot02(x,y,0,angle-60*spin,0.01,3,12,5);
	//	CreateShot02(x,y,0,angle-90,0.01,3,12,1);
	}

	task SnakeShot
	{
		loop
		{		
			SnakeShotBullet(Obj_GetX(snake),Obj_GetY(snake),Obj_GetAngle(snake)+180);
			wait(2);
		}
	}

	task SnakeShotBullet(x,y, angle)
	{
	wait(30);
	CreateShot02(x,y,0,angle,0.01,3,12,5);
	}

}

}

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"
