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

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

    @DrawLoop {
	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",1500);
    }

    // メインタスク
task TMainGrobal
{
	yield;
	OutDamageRateZero;
	Collision;
	Lissajous(0,64,255);
	BossShadowAnimation(imgBoss,0,255,255,127);
	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);
        SetCollisionB(GetX, GetY, 8);
	yield;
	}

}

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

task shotM
{
	shot;
	shot2;

task shot2
{
wait(30);
let angle=-90;
let r=32;
loop
{
	loop(3)
	{
	SetShotColor(ColorRed,ColorGreen,ColorBlue);
	CreateShot01(GetX+r*cos(angle),GetY+r*sin(angle),3,angle,16,5);
	CreateShot01(GetX+r*cos(180-angle),GetY+r*sin(180-angle),3,180-angle,16,5);
	SetShotColor(255,255,255);
	angle+=1.27;
	yield;
	}
wait(1);
angle+=9.5;
	
}
}

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);
	let count=0;
	while(ObjLaser_GetEndY(obj)>=GetClipMinY-4 && count<90)
	{
		ObjLaser_SetLength(obj,length);
		ObjShot_SetDelay(obj,1);
		length+=6;
		count+=1;
		yield;
	}
	let LX=x-ObjLaser_GetEndX(obj);
	let LY=y-ObjLaser_GetEndY(obj);
	ascent(let i in 0..14)
	{
		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),5);
	}
	Obj_Delete(obj);
}

}
///////////////////////////////////////////////////////
task shotE
{
	shot2;

task shot2
{
wait(30);
let angle=rand(0,360);
let angleplus=0.5*5/6;
let r=0;
let t=0;
loop
{
loop(6)
{
	ascent(let i in 0..30)
	{
		CreateShot01(GetX+r*cos(angle+i*12),GetY+r*sin(angle+i*12),5,angle+i*12,9+t%7,5);
	}
	angle+=angleplus;
	wait(5);
}
angleplus+=0.25;
wait(15);
	t+=1;

loop(6)
{
	ascent(let i in 0..30)
	{
		CreateShot01(GetX+r*cos(angle+i*12),GetY+r*sin(angle+i*12),5,angle+i*12,9+t%7,5);
	}
	angle-=angleplus;
	wait(5);
}
angleplus+=0.25;
wait(15);
t+=1;

}
}

}
/////////////////////////////////////////////////////////////////
task shotA
{
	shot;

task shot
{
wait(30);
let angle=-90;
let dir=rand_int(0,1)*2-1;
let waittime=60;
let speed=2;
loop
{
let r=2.5;
angle=rand(0,360);
ascent(let j in 1..7)
{
ascent(let i in 0..36)
{
CreateShotA(0,GetX,GetY,0);
SetShotDataA(0,0,j,angle+i*10,r*dir,-j/60,0,8+j);
SetShotDataA(0,60,speed,NULL,0,0,5,8+j);
FireShot(0);

}
}
dir=dir*-1;
wait(waittime);
if(waittime>30)
{
waittime-=2;
speed+=1/15;
}

	
}
}

}

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"
