
#Title[大妖精通常]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "大妖精";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_mokou.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let Step2=false;
	let wIni=60;
let TimeCounter=56*60;
let StandardTimeCounter=TimeCounter;
let VanishLife=1000;
    @Initialize {
	SetCommonData("STAGE1BOSS",true);
	SetShotAutoDeleteClip(32,32,32,32);
        SetTimer(TimeCounter/60);
        SetLife(1900);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
	InitializeAction();
	SetEnemyMarker(true);
        TMainGrobal;
    }

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

    @DrawLoop {
	if(TimeCounter<StandardTimeCounter-210)
	{
	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",15000);
    }

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

sub standBy//初期位置へ
{
	SetX(GetClipMinX-256);
	SetY(GetPlayerY);
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
		exclamation(GetPlayerY);
		exclamation(GetPlayerY+55);
		exclamation(GetPlayerY-55);
	}
	case("Extream")
	{
		exclamation(GetPlayerY);
		exclamation(GetPlayerY+55);
		exclamation(GetPlayerY-55);
		exclamation(GetPlayerY+110);
		exclamation(GetPlayerY-110);
	}
	case("Apocalypse")
	{
		exclamation(GetPlayerY);
		exclamation(GetPlayerY+55);
		exclamation(GetPlayerY-55);
		exclamation(GetPlayerY+110);
		exclamation(GetPlayerY-110);
		exclamation(GetPlayerY+165);
		exclamation(GetPlayerY-165);
	}
	wait(120);
	SetAngle(0);
	SetSpeed(14);
	Lissajous(255,100,0);
	BossShadowAnimation(imgBoss,0,255,100,0);
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
		wait(60);
	}
	case("Extream")
	{
		let angle=rand(0,360);
		loop(12)
		{
			ascent(let i in 0..36)
			{
				CreateShot01(GetX,GetY,3,angle+i*10,9,10);
			}
			wait(5);
		}
	}
	case("Apocalypse")
	{
		let angle=GetAngleToPlayer;
		loop(10)
		{
			ascent(let i in 0..36)
			{
				CreateShot01(GetX,GetY,3.5,angle+i*10,9,10);
				CreateShot01(GetX,GetY,3.25,angle+i*10,9,10);
				CreateShot01(GetX,GetY,3.0,angle+i*10,9,10);
			}
			wait(6);
		}
	}

	SetAction(ACT_MOVE, 120);
	SetMovePosition03(xIni, yIni, 20,5);
	SetInvincibility(wIni);
	wait(120);
	Concentration01(30);
}

task Collision
{
	wait(120);
	loop(90)
	{
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			MSDSetCollisionB(GetX, GetY, 75);
		}
		case("Extream")
		{
			MSDSetCollisionB(GetX, GetY, 125);
		}
		case("Apocalypse")
		{
			MSDSetCollisionB(GetX, GetY, 175);
		}
		yield;
	}
	wait(90);
	loop
	{
        SetCollisionA(GetX, GetY, 48);
        MSDSetCollisionB(GetX, GetY, 8);
	yield;
	}

}


task TMove
{
loop
{
//	SetMovePosition03(GetX+rand(-10,10), GetY+rand(-10,10), 20,5);
	wait(60);
}
}


task shotM
{
let looptime=0;
let r=50;
wait(30);
loop
{
	let waittime=30;
	let speed=2.5;
	SetAction(ACT_SHOT_A,240);
	loop(6)
	{
	let angle=rand(0,360);
	let X=rand(GetCenterX-80,GetCenterX);
	let Y=rand(GetClipMinY+16,GetClipMinY+64);
	let angle=atan2(GetPlayerY-Y,GetPlayerX-X);
		ascent(let i in 0..floor(360/(8-looptime)))
		{
			CreateShot01(X,Y,speed,angle+i*(8-looptime),89,5);
		}
	wait(waittime);
	let angle=rand(0,360);
	let X=rand(GetCenterX,GetCenterX+80);
	let Y=rand(GetClipMinY+16,GetClipMinY+64);
	let angle=atan2(GetPlayerY-Y,GetPlayerX-X)+(8-looptime)/2;
		ascent(let i in 0..floor(360/(8-looptime)))
		{
			CreateShot01(X,Y,speed,angle+i*(8-looptime),95,5);
		}
	wait(waittime);
	waittime-=5;
	speed+=0.3;
	}
	wait(60);
	SetAction(ACT_SHOT_B,60);
	summon;
	loop(750)
	{
		if(GetEnemyNum==1){break;}
		yield;
	}
	if(looptime<4)
	{
	looptime+=2;
	}
}


task Phoenix(x,y,speed,angle)
{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		Obj_SetAutoDelete(obj,false);
		ObjShot_SetGraphic(obj, 25);
		ObjShot_SetDelay(obj, 5);
	//	Obj_SetAlpha(obj, 5);

			PhoenixBullet(obj,0,12,angle);
			PhoenixBullet(obj,0,24,angle);
			PhoenixBullet(obj,0,-12,angle);
			PhoenixBullet(obj,0,-24,angle);

		ascent(let i in 0..4)
		{
			PhoenixBullet(obj,15+15*i,-7.5*i,angle);
			PhoenixBullet(obj,-15-15*i,-7.5*i,angle);
		}

		ascent(let i in 0..4)
		{
			PhoenixBullet(obj,30+15*i,-20-10*i,angle);
			PhoenixBullet(obj,-30-15*i,-20-10*i,angle);
		}

		ascent(let i in 0..4)
		{
			PhoenixBullet(obj,40+15*i,-40-12.5*i,angle);
			PhoenixBullet(obj,-40-15*i,-40-12.5*i,angle);
		}
		wait(600);
		Obj_Delete(obj);
}

task PhoenixBullet(Cobj,x,y,angle)
{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, Obj_GetX(Cobj)+x*cos(angle-90)+y*cos(angle),Obj_GetY(Cobj)+x*sin(angle-90)+y*sin(angle));
		ObjShot_SetGraphic(obj, 162);
		ObjShot_SetDelay(obj, 5);
		Obj_SetAngle(obj, angle);
		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj, Obj_GetX(Cobj)+x*cos(angle-90)+y*cos(angle),Obj_GetY(Cobj)+x*sin(angle-90)+y*sin(angle));
			yield;
		}
}

task PhoenixWingEffect(Cobj,x,y,angle)
{
	while(!Obj_BeDeleted(Cobj))
	{
		PhoenixEffect(Obj_GetX(Cobj)+x*cos(angle-90)+y*cos(angle),Obj_GetY(Cobj)+x*sin(angle-90)+y*sin(angle));
		yield;
	}
}

task PhoenixEffect(x,y)
{
		let R=255;let G=0;let B=0;
		let randrect=3;
		let scax=0.3;
		let scay=0.3;
		let alpha=150;
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\CircleEffect.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -24+rand(-randrect,randrect), -24+rand(-randrect,randrect));
		ObjEffect_SetVertexXY(obj, 1,  24+rand(-randrect,randrect), -24+rand(-randrect,randrect));
		ObjEffect_SetVertexXY(obj, 2,  24+rand(-randrect,randrect),  24+rand(-randrect,randrect));
		ObjEffect_SetVertexXY(obj, 3, -24+rand(-randrect,randrect),  24+rand(-randrect,randrect));
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  48, 0);
		ObjEffect_SetVertexUV(obj, 2, 48,  48);
		ObjEffect_SetVertexUV(obj, 3, 0, 48);

		Obj_SetPosition(obj,x,y);
		ObjEffect_SetScale(obj, scax,scay);
		Obj_SetSpeed(obj,0.2);
		Obj_SetAngle(obj,-90);
		loop(5)
		{
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,alpha,R,G,B);
			}
			ObjEffect_SetScale(obj, scax,scay);
			alpha-=10;
			yield;
		}
		Obj_Delete(obj);
}

}
/////////////////////////////////////////////////////////////////////////////
task shotE
{
let looptime=0;
let r=50;
wait(30);
loop
{
	SetAction(ACT_SHOT_A,240);
	Shot1;
	Shot2;
	wait(270);
	SetAction(ACT_SHOT_B,60);
	summon;
	loop(750)
	{
		if(GetEnemyNum==1){break;}
		yield;
	}
	looptime+=1;
}
task Shot1
{
	let waittime=30;
	let speed=2.5;
	let angle=rand(0,360);
	loop(24)
	{
		ascent(let j in 0..4)
		{
		ascent(let i in 0..8+looptime)
		{
			CreateShot01(GetX,GetY,speed+0.25*i,angle-i*1.5+90*j,89,5);
		}
		}
		wait(10);
		angle+=15;
	}
}

task Shot2
{
	let waittime=30;
	let speed=1.5;
	let angle=rand(0,360);
	loop(24)
	{
		ascent(let j in 0..4)
		{
		ascent(let i in 0..6)
		{
			CreateShot01(GetX,GetY,speed+0.25*i,angle+i*3+90*j,94,5);
		}
		}
		wait(10);
		angle+=10;
	}
}

}
//////////////////////////////////////////////////////////////////////
task shotA
{
let looptime=0;
let r=50;
wait(30);
loop
{
	let waittime=30;
	let speed=5;
	SetAction(ACT_SHOT_A,240);
	loop(12)
	{
	let angle=rand(0,360);
	let X=rand(GetCenterX-100,GetCenterX);
	let Y=rand(GetClipMinY+16,GetClipMinY+64);
		ascent(let i in 0..360/(8-looptime))
		{
			CreateShot01(X,Y,speed,angle+i*(8-looptime),95,5);
		}
	wait(10);
	let angle=rand(0,360);
	let X=rand(GetCenterX,GetCenterX+100);
	let Y=rand(GetClipMinY+16,GetClipMinY+64);
		ascent(let i in 0..360/(8-looptime))
		{
			CreateShot01(X,Y,speed,angle+i*(8-looptime),95,5);
		}
	wait(10);
	}
	wait(30);
	SetAction(ACT_SHOT_B,60);
	summon;
	loop(780)
	{
		if(GetEnemyNum==1){break;}
		yield;
	}
	looptime+=1;
}

}
/////////////////////////////////////////////////////////////////////////
task summon
{
	ascent(let i in 0..4)
	{
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 90*i, 1);
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 90*i+45, -1);
	}
}

	task Wing{
		let lifetime=30;
		let speed=5.5;
		let angle=0;
		if(GetCommonDataDefault("LightMode",0)==1){lifetime=15;speed=11;}
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			lifetime=30;
		}
		case("Extream")
		{
			lifetime=45;
		}
		case("Apocalypse")
		{
			lifetime=60;
		}
		loop(2){
			ascent(j in 0..105){
				WingPart(GetX,GetY,angle+70+5*sin(3*j),lifetime,speed);
				WingPart(GetX,GetY,angle-70-5*sin(3*j),lifetime,speed);

				WingPart(GetX,GetY,angle+90+5*sin(3*j),lifetime*3/4,speed);
				WingPart(GetX,GetY,angle-90-5*sin(3*j),lifetime*3/4,speed);

				WingPart(GetX+20*cos(angle),GetY+20*sin(angle),angle+70+5*sin(3*j),lifetime*5/4,speed);
				WingPart(GetX+20*cos(angle),GetY+20*sin(angle),angle-70-5*sin(3*j),lifetime*5/4,speed);

				WingPart(GetX,GetY,angle+105+5*sin(3*j),lifetime/2,speed);
				WingPart(GetX,GetY,angle-105-5*sin(3*j),lifetime/2,speed);

				WingPart(GetX,GetY,angle+165-1*sin(6*j),lifetime*5/12,speed);
				WingPart(GetX,GetY,angle+180-1*sin(6*j),lifetime/2,speed);
				WingPart(GetX,GetY,angle-165-1*sin(6*j),lifetime*5/12,speed);

				yield;
				}
			}
		}

	task WingPart(let x,let y,let angle,let lifetime,let speed){
		function randrect
		{
			return(rand(-3,3));
		}
		let WingUV=[0,0,48,48];
		let WingXY=[-24+randrect,-24+randrect,24+randrect,24+randrect];
		let obj= Obj_Create(OBJ_EFFECT);
		let scale=0.5;
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			scale=0.5;
		}
		case("Extream")
		{
			scale=0.75;
		}
		case("Apocalypse")
		{
			scale=1.0;
		}
		let r=0;
		Obj_SetX(obj, x+r*cos(angle));
		Obj_SetY(obj, y+r*sin(angle));
        	ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\CircleEffect.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, scale,scale);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0,WingXY[0],WingXY[1]);
		ObjEffect_SetVertexXY(obj, 1,WingXY[0],WingXY[3]);
		ObjEffect_SetVertexXY(obj, 2,WingXY[2],WingXY[1]);
		ObjEffect_SetVertexXY(obj, 3,WingXY[2],WingXY[3]);
		
		ObjEffect_SetVertexUV(obj, 0, WingUV[0],WingUV[1]);
		ObjEffect_SetVertexUV(obj, 1, WingUV[0],WingUV[3]);
		ObjEffect_SetVertexUV(obj, 2, WingUV[2],WingUV[1]);
		ObjEffect_SetVertexUV(obj, 3, WingUV[2],WingUV[3]);

		let Alpha=255;

		ObjEffect_SetLayer(obj,1);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,angle);
		loop(lifetime){
			r+=speed;
			scale-=0.5/lifetime;
			Alpha-=255/lifetime;
			ObjEffect_SetScale(obj, scale,scale);		
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,0,0);
			}
   			yield;
			if(GetEnemyLife==0){break;}
			}
		Obj_Delete(obj);
		}

	task exclamation(let y,){
		let WingUV=[0,9,384,58];
		let WingXY=[-192,-25,192,25];
		let obj= Obj_Create(OBJ_EFFECT);
		let scale=1;
		let r=0;
		Obj_SetX(obj, GetCenterX);
		Obj_SetY(obj, y);
        	ObjEffect_SetTexture(obj,GetCurrentScriptDirectory~"..\img\!.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, 1,scale);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0,WingXY[0],WingXY[1]);
		ObjEffect_SetVertexXY(obj, 1,WingXY[0],WingXY[3]);
		ObjEffect_SetVertexXY(obj, 2,WingXY[2],WingXY[1]);
		ObjEffect_SetVertexXY(obj, 3,WingXY[2],WingXY[3]);
		
		ObjEffect_SetVertexUV(obj, 0, WingUV[0],WingUV[1]);
		ObjEffect_SetVertexUV(obj, 1, WingUV[0],WingUV[3]);
		ObjEffect_SetVertexUV(obj, 2, WingUV[2],WingUV[1]);
		ObjEffect_SetVertexUV(obj, 3, WingUV[2],WingUV[3]);

		let Alpha=255;

		ObjEffect_SetLayer(obj,3);

		loop(120){	
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,255,255);
			}
   			yield;
			}
		Obj_Delete(obj);
		}

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

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
    @Initialize {
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(325);
        SetDamageRateEx(100,100,0,0);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

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

    @DrawLoop {
      //  DrawGraphic(GetX, GetY);
    }

        @Finalize
        {
	if(GetEnemyLife>0)
	{
		loop(5)
		{
		FinalizeItemSet(1);
		}
	}
        }

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	ZakoEnemyLifeDisplay;
	move;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}
	ZakoEffect(255,0,0);
    }

task move
{
	let angle=GetAngle;
	let r=90-40*num;
	let rs=r;
	SetMovePosition02(r*cos(angle), r*sin(angle), 30);
	wait(30);
	loop(660)
	{
	SetX(r*cos(angle));
	SetY(r*sin(angle));
	angle+=1*num;
	yield;
	}
	loop(60)
	{
	r-=rs/60;
	SetX(r*cos(angle));
	SetY(r*sin(angle));
	angle+=1*num;
	yield;
	}
	VanishEnemy;

}

task shotM
{
wait(30);
loop(3)
{
let angle=GetAngleToPlayer;
ascent(let i in -1..2)
{
CreateShot01(GetX,GetY,3,angle+i*2,9,5);
}
wait(60);
}
wait(30);

let angle=atan2(GetEnemyY-GetY,GetEnemyX-GetX);
angle=atan2(GetPlayerY-GetEnemyY,GetPlayerX-GetEnemyX);
loop(30)
{
	angle=180+atan2(GetEnemyY-GetY,GetEnemyX-GetX);
	CreateShot01(GetX,GetY,3,angle,9,5);	
	wait(4);
}
wait(60);
loop(10)
{
	angle=atan2(GetPlayerY-GetEnemyY,GetPlayerX-GetEnemyX);
	CreateShot01(GetX,GetY,3,angle,9,5);	
	wait(15);
}
wait(60);
angle=rand(0,360);
ascent(let i in 0..45)
{
	CreateShot01(GetX,GetY,3,angle+i*8,9,5);
}

}
/////////////////////////////////////////////////////////
task shotE
{
wait(60);
loop(4)
{
let angle=GetAngleToPlayer;
loop(5)
{
	angle=GetAngleToPlayer;
	ascent(let i in -2..3)
	{
	CreateShot01(GetX,GetY,4,angle+i*2.0,9,5);
	}
	wait(3);
}
wait(30);
}
wait(60);
let angle=0;
loop(15)
{
	angle=atan2(GetPlayerY-GetEnemyY,GetPlayerX-GetEnemyX);
	CreateShot01(GetX,GetY,rand(1.5,2),angle+rand(-30,30),9,5);
	wait(12);
}
wait(60);
loop(60)
{
	angle=180+atan2(GetEnemyY-GetY,GetEnemyX-GetX);
	CreateShot01(GetX,GetY,4,angle,9,5);
	wait(3);
}


}
////////////////////////////////////////////////////////////
task shotA
{
wait(30);
loop(4)
{
	let angle=180+atan2(GetEnemyY-GetY,GetEnemyX-GetX);
	ascent(let j in 0..3)
	{
		ascent(let i in 0..12)
		{
			CreateShot01(GetX,GetY,2.5,angle+i*30+j*2.5,9,5);
		}
	}
wait(60);
}
wait(60);

loop(60)
{
	let angle=180+atan2(GetEnemyY-GetY,GetEnemyX-GetX);
	CreateShot01(GetX,GetY,4,angle+90,9,5);
	CreateShot01(GetX,GetY,4,angle-90,9,5);
	wait(3);
}

wait(60);
let angle=rand(0,360);
ascent(let i in 0..48)
{
	ascent(let j in 0..4)
	{
	CreateShot01(GetX,GetY,2.5-0.20*j,angle+i*7.5,9,5);
	}
}
}
    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#include_function ".\..\txt/StageEnemydata.txt"
}

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