
#Title[妹紅２]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_mokou.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let Step2=false;
	let wIni=60;
let TimeCounter=60*60;
let StandardTimeCounter=TimeCounter;
let ColorRed=255;
let ColorGreen=0;
let ColorBlue=0;
    @Initialize {
	SetX(GetCommonDataDefault("BossX",0));
	SetY(GetCommonDataDefault("BossY",0));
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
	SetCommonData("BossLastAttackColor",[255,100,0]);
	SetCommonData("BossLastAttack",true);
	SetShotAutoDeleteClip(4,4,4,4);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetLife(4600);
 LoadGraphic(GetCurrentScriptDirectory~"..\img\CircleEffect.png");
	InitializeAction();
	SetEnemyMarker(true);
        TMainGrobal;
    }

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

    @DrawLoop {
	DrawBoss( imgBoss );
    }

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

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

task Collision
{
	wait(90);
	let CR=48;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Extream")
	{
	CR=52;
	}
	case("Apocalypse")
	{
	CR=56;
	}
	loop
	{
        SetCollisionA(GetX, GetY, 48);
        SetCollisionA(GetX+88, GetY, CR);
        SetCollisionA(GetX-88, GetY, CR);
        MSDSetCollisionB(GetX, GetY, 16);
	yield;
	}

}

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

task shotM
{
	SetAction(ACT_SHOT_B,30);
	shot;
	wait(60);
	SetAction(ACT_SHOT_A,90);
	shot4;
	wait(240);
	SpellDraw(7,6000);
	SetAction(ACT_SHOT_A,6000);
	shot2;
	wait(90);
	shot3;

task shot4
{
let X=GetClipMinX+8;
let Y=GetCenterY;
loop(3)
{
	loop(12)
	{
		FlameCreateShot01(X+rand(-8,8),Y+rand(-8,8),rand(1.5,3),90,9,10);
		FlameCreateShot01(GetCenterX*2-X,Y,rand(1.5,3),90,9,10);
	Y-=2*5/4;
	X+=26*5/4;
	wait(1);
	}
	wait(3);
	loop(12)
	{
		FlameCreateShot01(X+rand(-8,8),Y+rand(-8,8),rand(1.5,3),90,9,10);
		FlameCreateShot01(GetCenterX*2-X,Y,rand(1.5,3),90,9,10);
	Y-=2*5/4;
	X-=26*5/4;
	wait(1);
	}
	wait(3);
}


}

task shot3
{

loop
{
        CreateEnemyFromScript("Familiar3", GetX, GetY,
                              0, 0, 1);
	wait(300);
        CreateEnemyFromScript("Familiar3", GetX, GetY,
                              0, 0, -1);
	wait(300);
}

}

task shot2
{
let waittime=60;
let count=0;
loop
{
	ascent(let i in 0..20)
	{
	ascent(let j in 0..5)
	{
		CreateShot01(GetX,GetY,1.4+0.4*j,GetAngleToPlayer+18*i,41,15);
	}
	}
	wait(waittime);
/*
	if(count==5)
	{
	waittime=30;
	}
*/
	count+=1;
}

}

task shot
{
let X=GetX+75;
let X2=GetX-75;
let Y=GetY-20;
let angle1;
let angle2;
let anglecicle=0;
loop
{
	let SX=X+rand(-40,40);
	let SX2=X2+rand(-40,40);
	let SY=Y+rand(-40,5);
	angle1=atan2(GetPlayerY-SY,GetPlayerX-SX)+5*cos(anglecicle)+360;
	angle2=atan2(GetPlayerY-SY,GetPlayerX-SX2)+5*cos(180+anglecicle)+360;
	angle1=angle1%360;
	angle2=angle2%360;
	let Sangle1=rand(0,180);
	let Sangle2=rand(0,180);
	while(Sangle1<angle1+24 && Sangle1>angle1-24){Sangle1=rand(0,180);}
	while(Sangle2<angle2+24 && Sangle2>angle2-24){Sangle2=rand(0,180);}
	if(!OnBomb)
	{
		CreateShot01(SX,SY,7,Sangle1,225,5);
		CreateShot01(SX2,SY,7,Sangle2,225,5);
	}
	anglecicle+=12;
	wait(2);
}
loop
{
	angle1=atan2(GetPlayerY-Y,GetPlayerX-X)+5*cos(anglecicle);
	angle2=atan2(GetPlayerY-Y,GetPlayerX-X2)+5*cos(180+anglecicle);
	if(!OnBomb)
	{
	ascent(let i in -2..2)
	{
		CreateShot01(X,Y,10,angle1+i*72+36,46,5);
		CreateShot01(X2,Y,10,angle2+i*72+36,46,5);
	}
	}
	anglecicle+=12;
	wait(2);
}
}

task FlameCreateShot01(x,y,speed,angle,gra,delay)
{
	ShotEffect(x,y,delay,255,255,0,0);
	wait(delay);
	CreateShot01(x,y,speed,angle,gra,0);
}

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


}
///////////////////////////////////////////////////////
task shotE
{
let waittime=5;
	SetAction(ACT_SHOT_B,30);
	shot;
	wait(60);
	SetAction(ACT_SHOT_A,180);
	summon;
	wait(300);
	SpellDraw(8,6000);
	SetAction(ACT_SHOT_A,6000);
	shot3;

task shot
{
let X=GetX+80;
let X2=GetX-80;
let Y=GetY-20;
let angle1;
let angle2;
let anglecicle=0;
loop
{
	let SX=X+rand(-40,40);
	let SX2=X2+rand(-40,40);
	let SY=Y+rand(-40,5);
	angle1=atan2(GetPlayerY-SY,GetPlayerX-SX)+5*cos(anglecicle)+360;
	angle2=atan2(GetPlayerY-SY,GetPlayerX-SX2)+5*cos(180+anglecicle)+360;
	angle1=angle1%360;
	angle2=angle2%360;
	let Sangle1=rand(0,180);
	let Sangle2=rand(0,180);
	while(Sangle1<angle1+24 && Sangle1>angle1-24){Sangle1=rand(0,180);}
	while(Sangle2<angle2+24 && Sangle2>angle2-24){Sangle2=rand(0,180);}
	if(!OnBomb)
	{
		CreateShot01(SX,SY,7,Sangle1,225,5);
		CreateShot01(SX2,SY,7,Sangle2,225,5);
	}
	anglecicle+=12;
	wait(2);
}
loop
{
	angle1=atan2(GetPlayerY-Y,GetPlayerX-X)+5*cos(anglecicle);
	angle2=atan2(GetPlayerY-Y,GetPlayerX-X2)+5*cos(180+anglecicle);
	if(!OnBomb)
	{
	ascent(let i in 0..5)
	{
		CreateShot01(X,Y,10,angle1+i*72+36,46,5);
		CreateShot01(X2,Y,10,angle2+i*72+36,46,5);
	}
	}
	anglecicle+=12;
	wait(2);
}
}

task shot3
{
let angle=atan2(GetClipMaxY-GetY,GetClipMaxX-GetX);

loop
{
        CreateEnemyFromScript("Familiar4", GetX, GetY,
                              0, waittime, 1);

	wait(195);

        CreateEnemyFromScript("Familiar4", GetX, GetY,
                              0, waittime, -1);


	wait(195);
/*
	if(waittime>3)
	{
	waittime-=1;	
	}
*/
}

}

task shot2
{
let X=GetX+65;
let X2=GetX-65;
let Y=GetY-25;
let angle=GetAngleToPlayer+rand(-5,5);
	ascent(let i in -12..12)
	{
		ascent(let j in -6..6)
		{
			CreateShot01(X,Y,3+0.25*j,angle+i*5,9,5);
		}
	wait(1);
	}
	wait(30);
	angle=GetAngleToPlayer+rand(-5,5);
	ascent(let i in -12..12)
	{
		ascent(let j in -6..8)
		{
			CreateShot01(X2,Y,3+0.25*j,angle-i*5,9,5);
		}
	wait(1);
	}
	wait(30);
	angle=GetAngleToPlayer+rand(-5,5);
	ascent(let i in -12..12)
	{
		ascent(let j in -6..10)
		{
			CreateShot01(X,Y,3+0.25*j,angle+i*5,9,5);
		}
	wait(1);
	}
	wait(30);
	angle=GetAngleToPlayer+rand(-5,5);
	ascent(let i in -12..12)
	{
		ascent(let j in -6..15)
		{
			CreateShot01(X2,Y,3+0.25*j,angle-i*5,9,5);
		}
	wait(1);
	}
}

task summon
{
loop(3)
{
        CreateEnemyFromScript("Familiar", GetX+80*cos(GetAngleToPlayer+90), GetY+80*sin(GetAngleToPlayer+90),
                              0, GetAngleToPlayer, 1);
        CreateEnemyFromScript("Familiar", GetX-80*cos(GetAngleToPlayer+90), GetY-80*sin(GetAngleToPlayer+90),
                              0, GetAngleToPlayer, -1);

        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, GetAngleToPlayer, -1);
wait(60);
}
}

}
/////////////////////////////////////////////////////////////////
task shotA
{
	SetAction(ACT_SHOT_B,30);
	shot;
	wait(60);
	SetAction(ACT_SHOT_A,180);
	shot2;
	wait(180);
	SpellDraw(9,6000);
	SetAction(ACT_SHOT_A,6000);
	summon;
	wait(180);
	shot3;

task shot3
{
	shot4(1);
	wait(10);
	shot4(2);
	wait(10);
	shot4(3);
	wait(10);
	shot4(4);
	wait(10);
	shot4(5);
}

task shot4(num)
{
	loop
	{
		CreateShot01(rand(GetClipMinX+((GetClipMaxX-GetClipMinX)*(num-1))/5,GetClipMinX+(GetClipMaxX-GetClipMinX)*num/5),GetClipMinY,rand(1,2.5),rand(88,92),9,5);
		wait(5);
	}
}

task shot
{
let X=GetX+85;
let X2=GetX-85;
let Y=GetY-20;
let angle1;
let angle2;
let anglecicle=0;
loop
{
	let SX=X+rand(-40,40);
	let SX2=X2+rand(-40,40);
	let SY=Y+rand(-40,5);
	angle1=atan2(GetPlayerY-SY,GetPlayerX-SX)+5*cos(anglecicle)+360;
	angle2=atan2(GetPlayerY-SY,GetPlayerX-SX2)+5*cos(180+anglecicle)+360;
	angle1=angle1%360;
	angle2=angle2%360;
	let Sangle1=rand(0,180);
	let Sangle2=rand(0,180);
	while(Sangle1<angle1+24 && Sangle1>angle1-24){Sangle1=rand(0,180);}
	while(Sangle2<angle2+24 && Sangle2>angle2-24){Sangle2=rand(0,180);}
	if(!OnBomb)
	{
		CreateShot01(SX,SY,7,Sangle1,225,5);
		CreateShot01(SX2,SY,7,Sangle2,225,5);
	}
	anglecicle+=12;
	wait(2);
}
loop
{
	angle1=atan2(GetPlayerY-Y,GetPlayerX-X)+5*cos(anglecicle);
	angle2=atan2(GetPlayerY-Y,GetPlayerX-X2)+5*cos(180+anglecicle);
	if(!OnBomb)
	{
	ascent(let i in 0..5)
	{
		CreateShot01(X,Y,10,angle1+i*72+36,46,5);
		CreateShot01(X2,Y,10,angle2+i*72+36,46,5);
	}
	}
	anglecicle+=12;
	wait(2);
}
}

task shot2
{
let X=GetX+65;
let X2=GetX-65;
let Y=GetY-25;
	let angle=atan2(GetPlayerY-Y,GetPlayerX-X)+rand(-5,5);
	ascent(let i in -8..8)
	{
		ascent(let j in -3..6)
		{
			CreateShot01(X,Y,3+0.25*j,angle+i*5,9,5);
		}
	wait(1);
	}
	wait(30);
	angle=atan2(GetPlayerY-Y,GetPlayerX-X2)+rand(-5,5);
	ascent(let i in -8..8)
	{
		ascent(let j in -4..8)
		{
			CreateShot01(X2,Y,3+0.25*j,angle-i*5,9,5);
		}
	wait(1);
	}
	wait(30);
	angle=atan2(GetPlayerY-Y,GetPlayerX-X)+rand(-5,5);
	ascent(let i in -9..9)
	{
		ascent(let j in -5..10)
		{
			CreateShot01(X,Y,3+0.25*j,angle+i*5,9,5);
		}
	wait(1);
	}
	wait(30);
	angle=atan2(GetPlayerY-Y,GetPlayerX-X2)+rand(-5,5);
	ascent(let i in -10..10)
	{
		ascent(let j in -6..15)
		{
			CreateShot01(X2,Y,3+0.25*j,angle-i*5,9,5);
		}
	wait(1);
	}
}

task summon
{
loop
{
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, GetAngleToPlayer, 0);
	wait(10);
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, GetAngleToPlayer, 1);
	wait(10);
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, GetAngleToPlayer, 2);
	wait(10);
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, GetAngleToPlayer, 3);
	wait(10);
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, GetAngleToPlayer, 4);
wait(300);
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, GetAngleToPlayer, 0.5);
	wait(10);
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, GetAngleToPlayer, 1.5);
	wait(10);
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, GetAngleToPlayer, 2.5);
	wait(10);
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, GetAngleToPlayer, 3.5);
wait(300);
}
}

}



/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	task Wing{

		let lifetime=26;
		let speed=5.5;
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Extream")
		{
			lifetime=28;
		}
		case("Apocalypse")
		{
			lifetime=30;
		}
		if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){lifetime/=2;speed*=2;}
		let angle=-90;
		loop{
			ascent(j in 0..120){
				WingPart(GetX,GetY,angle+75+5*sin(3*j),lifetime,speed);
				WingPart(GetX,GetY,angle-75-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,GetY-15,angle+70+5*sin(3*j),lifetime*5/4,speed);
				WingPart(GetX,GetY-15,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(-1,1));
		}
		let WingXY=[-12+randrect,-12+randrect,12+randrect,12+randrect];
		let obj= Obj_Create(OBJ_EFFECT);
		let scale=1.0;
		let r=11;
		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_TRIANGLEFAN);
		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[2],WingXY[1]);
		ObjEffect_SetVertexXY(obj, 2,WingXY[2],WingXY[3]);
		ObjEffect_SetVertexXY(obj, 3,WingXY[0],WingXY[3]);
		
		ObjEffect_SetVertexUV(obj, 0, 0,0);
		ObjEffect_SetVertexUV(obj, 1, 48,0);
		ObjEffect_SetVertexUV(obj, 2, 48,48);
		ObjEffect_SetVertexUV(obj, 3, 0,48);

		let Alpha=255;

		ObjEffect_SetLayer(obj,1);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,angle);
		loop(lifetime){
			scale-=0.75/lifetime;
			Alpha-=255/lifetime;
			ObjEffect_SetScale(obj, scale,scale);		
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,255,30,30);
			}
   			yield;
			if(GetCommonDataDefault("BossLife",0)==0){break;}
			}
		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(50000);
        SetDamageRateEx(0,0,0,0);
	DamageRate=0;
	BombDamageRate=0;
	TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 36);
        MSDSetCollisionB(GetX, GetY, 12);
        yield;
    }

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

        @Finalize
        {
	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(10)
		{
		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 speed=GetSpeed;

	SetAngle(angle);
	loop(180)
	{
	SetSpeed(speed);
	speed+=0.12;
	yield;
	}

	VanishEnemy;

}
/////////////////////////////////////////////////////////
task shotE
{
wait(5);
loop
{
	let angle=rand(0,360);
	CreateShotA(0,GetX,GetY,10);
	SetShotDataA(0,0,0,angle,0,0.01,2,9);
	FireShot(0);
	wait(3);
}
}
////////////////////////////////////////////////////////////

#include_function ".\..\txt/StageEnemydata.txt"
}


script_enemy Familiar2 {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
    @Initialize {
	//SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(50000);
        SetDamageRateEx(0,0,0,0);
	DamageRate=0;
	BombDamageRate=0;
	TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 36);
        MSDSetCollisionB(GetX, GetY, 12);
        yield;
    }

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

        @Finalize
        {
	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(10)
		{
		FinalizeItemSet(1);
		}
	}
        }

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

task move
{
	let X=GetClipMinX+16+(GetClipMaxX+48-GetClipMinX)*num/5;
	let Y=GetClipMaxY+32;

	SetMovePosition03(X, Y,15,6);
	wait(270);
	VanishEnemy;

}

/////////////////////////////////////////////////////////
task shotA
{
wait(90);
Laser;
wait(30);
LaserShot;
}

task LaserShot
{
	loop(12)
	{
	WaveShot(GetX,GetY-32,8,-90,25,10,0,225,5);
	WaveShot(GetX,GetY-32,8,-90,25,10,180,225,5);
	wait(5);
	}
}

task WaveShot(let x, let y, let speed, let angle,
            let amp, let om, let arg, let graphic, let delay) {
    
    let t = 0;
    let px = speed*t;
    let py = amp*sin(om*t + arg);
    let a = amp*om*3.1415926/(180*speed);
    
    //オブジェクト弾の作成
    let obj = Obj_Create(OBJ_SHOT);
    
    //パラメータの設定
    Obj_SetPosition(obj, x + px*cos(angle) - py*sin(angle),
                             y + px*sin(angle) + py*cos(angle));
    Obj_SetSpeed(obj, 0);
    Obj_SetAngle(obj, angle + atan(a*cos(om*t + arg)));
    ObjShot_SetGraphic(obj, graphic);
    ObjShot_SetDelay(obj, delay);
	ObjShot_SetBombResist(obj, true);
    loop(delay){ yield; }
	
    while(!Obj_BeDeleted(obj))
    {
        //(px,py)座標での弾の位置を計算
        px=speed*t;
        py=amp*sin(om*t + arg);
        //回転・平行移動して実際の位置に
        Obj_SetPosition(obj, x + px*cos(angle) - py*sin(angle),
                                 y + px*sin(angle) + py*cos(angle));
        //弾の方向にもangleを足す
        Obj_SetAngle(obj, angle + atan(a*cos(om*t + arg)));
        
        t++;
        yield;
    }
}   

task Laser
{
	let length=500;
	let width=0;
	let angle=-90;
        let obj = Obj_Create(OBJ_LASER);
      	ObjLaser_SetSource(obj, false);
        Obj_SetPosition(obj, GetX, GetY);
        ObjLaser_SetLength(obj, length);
        ObjLaser_SetWidth(obj, width);
        Obj_SetAngle(obj,angle);
        ObjShot_SetBombResist(obj, true);
        ObjShot_SetGraphic(obj,153);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetDelay(obj, 0);
	loop(30)
	{
		ObjLaser_SetWidth(obj, width*rand(0.90,1));
		width+=80/30;
		Obj_SetPosition(obj, GetX, GetY);
		yield;
	}
	loop(120)
	{
		ObjLaser_SetWidth(obj, width*rand(0.90,1));
		yield;
	}
	loop(30)
	{
		ObjLaser_SetWidth(obj, width*rand(0.90,1));
		width-=80/30;
		yield;
	}
	Obj_Delete(obj);
}

task FamiliarEffect(R,G,B,frame)
{
	//FamiliarEffect0(R,G,B);
loop(frame)
{
	FamiliarEffect1(R,G,B);
yield;
}
}

task FamiliarEffect0(R,G,B)
{
		let scax=1.0;
		let scay=1.0;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
		let alpha=100;
  		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, -24);
		ObjEffect_SetVertexXY(obj, 1,  24, -24);
		ObjEffect_SetVertexXY(obj, 2,  24,  24);
		ObjEffect_SetVertexXY(obj, 3, -24,  24);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  48, 0);
		ObjEffect_SetVertexUV(obj, 2, 48,  48);
		ObjEffect_SetVertexUV(obj, 3, 0, 48);

			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,alpha,R,G,B);
			}

		ObjEffect_SetScale(obj, scax,scay);
		loop
		{
		Obj_SetPosition(obj,GetX,GetY);
			yield;
		}
}


task FamiliarEffect1(R,G,B)
{
		let randrect=5;
		let scax=1.0;
		let scay=1.0;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
		let alpha=50;
  		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,GetX,GetY);
		ObjEffect_SetScale(obj, scax,scay);
		Obj_SetSpeed(obj,1);
		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);
			scax+=0.3/10;
			scay+=0.3/10;
			alpha-=50/10;
			yield;
		}
		Obj_Delete(obj);
}
////////////////////////////////////////////////////////////

#include_function ".\..\txt/StageEnemydata.txt"
}


script_enemy Familiar3 {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
    @Initialize {
	//SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(50000);
        SetDamageRateEx(0,0,0,0);
	DamageRate=0;
	BombDamageRate=0;
	TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 36);
        MSDSetCollisionB(GetX, GetY, 12);
        yield;
    }

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

        @Finalize
        {
	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(10)
		{
		FinalizeItemSet(1);
		}
	}
        }

    task TMain {
        yield;
	GetDamege;
	//OutDamageRateZero;
	//ZakoEnemyLifeDisplay;
	move;
	shotM;
	ZakoEffect(255,0,0);
    }

task move
{
	let X=GetClipMaxX;
	let Y=GetClipMaxY;
	if(num>0)
	{
		X=GetClipMaxX;
	}
	else
	{
		X=GetClipMinX;
	}
	SetMovePosition02(X,Y,59);
	wait(60);
	SetSpeed(8);
	SetAngle(270);
	wait(120);
	VanishEnemy;

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

#include_function ".\..\txt/StageEnemydata.txt"
}

script_enemy Familiar4 {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
	let waittime=GetAngle;
    @Initialize {
	//SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(50000);
        SetDamageRateEx(0,0,0,0);
	DamageRate=0;
	BombDamageRate=0;
	TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 36);
        MSDSetCollisionB(GetX, GetY, 12);
        yield;
    }

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

        @Finalize
        {
	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(10)
		{
		FinalizeItemSet(1);
		}
	}
        }

    task TMain {
        yield;
	GetDamege;
	//OutDamageRateZero;
	//ZakoEnemyLifeDisplay;
	move;
	shotM;
	ZakoEffect(255,0,0);
    }

task move
{
	let X=GetClipMaxX;
	let Y=GetClipMaxY;
	if(num>0)
	{
		X=GetClipMaxX;
	}
	else
	{
		X=GetClipMinX;
	}
	SetMovePosition02(X,Y,60);
	wait(60);
	if(num==1)
	{
	SetMovePosition02(GetClipMaxX,GetClipMinY,60);
	}
	else
	{
	SetMovePosition02(GetClipMinX,GetClipMinY,60);
	}
	wait(60);
	if(num==1)
	{
	SetMovePosition02(GetClipMinX,GetClipMinY,60);
	}
	else
	{
	SetMovePosition02(GetClipMaxX,GetClipMinY,60);
	}
	wait(60);
	if(num==1)
	{
	SetMovePosition02(GetClipMinX,GetClipMaxY,60);
	}
	else
	{
	SetMovePosition02(GetClipMaxX,GetClipMaxY,60);
	}
	wait(61);
	SetSpeed(8);
	SetAngle(90);
	wait(15);
	VanishEnemy;

}
/////////////////////////////////////////////////////////
task shotM
{
wait(60);
	let dir=1;
	let X=GetClipMaxX;
	if(num>0)
	{
		X=GetClipMaxX;
	}
	else
	{
		X=GetClipMinX;
	}
	if(X==GetClipMinX)
	{
		dir=-1;
	}
	let Y=GetClipMaxY;
	let angle=atan2(GetPlayerY-Y,GetPlayerX-X);
	loop(60/waittime)
	{
		angle=GetAngleToPlayer;
		ascent(let i in 0..12)
		{
			CreateShot01(GetX,GetY,3,angle+i*30,9,5);
		}
		CreateShot01(GetX,GetY,rand(1,1.5),rand(175,185),33,5);
		CreateShot01(GetX,GetY+20,rand(1,1.5),rand(170,190),33,5);
		wait(waittime);
	}
	loop(60/waittime)
	{
		angle=GetAngleToPlayer;
		ascent(let i in 0..12)
		{
			CreateShot01(GetX,GetY,3,angle+i*30,9,5);
		}
		CreateShot01(GetX,GetY,rand(1,1.5),rand(85,95),33,5);
		CreateShot01(GetX+20,GetY,rand(1,1.5),rand(80,100),33,5);
		wait(waittime);
	}
	loop(60/waittime)
	{
		angle=GetAngleToPlayer;
		ascent(let i in 0..12)
		{
			CreateShot01(GetX,GetY,3,angle+i*30,9,5);
		}
		CreateShot01(GetX,GetY,rand(1,1.5),rand(-5,5),33,5);
		CreateShot01(GetX,GetY+20,rand(1,1.5),rand(-10,10),33,5);
		wait(waittime);
	}
}
////////////////////////////////////////////////////////////

#include_function ".\..\txt/StageEnemydata.txt"
}
#include_script ".\..\txt/EnemyShotData.txt"
