script_enemy_main
{
        let csd     = GetCurrentScriptDirectory;
	let speed = GetSpeed;
	let angle = GetAngle;
	let num = GetArgument;

	let r=0;
	let angle1=60;
	let angle2=180;
	let angle3=300;



	let dir;
	if(num==1)
	{
		dir=1;
	}
	if(num==2)
	{
		dir=-1;
	}
	let imgEnemy;
	if(num==1)
	{
		imgEnemy=csd~"..\lib\fairy_red.png";
	}
	if(num==2)
	{
		imgEnemy=csd~"..\lib\fairy_blue.png";
	}
    let imgFam  = csd ~ "..\img\familiar.png";
	let SelectedDifficult=GetCommonDataDefault("SELECTEDDIFFICULT","Normal");

	if(SelectedDifficult=="Extra")
	{
	angle1-=60;
	angle2-=60;
	angle3-=60;
	}

    @Initialize {
        SetLife(1500);
        SetDamageRate(100,100);
	SetTexture(imgEnemy);
	SetTexture(imgFam);
	Initialize_Fairy(7);
	Tmain;
	}

    @MainLoop {
	if(GetLife>1000)
	{
	SetCollisionA(GetX(),GetY(),64);
        SetCollisionB(GetX(),GetY(),8);
	}

	angle1++;
	angle2++;
	angle3++;
	yield;
    }

        @DrawLoop {
	if(GetLife>1000)
	{
		DrawFairy(imgEnemy);
	if(r!=0)
	{
	SetTexture(imgFam);
	setGraphic;
        DrawGraphic(GetX+r*cos(angle1),GetY+r*sin(angle1));
	SetTexture(imgFam);
	setGraphic;
        DrawGraphic(GetX+r*cos(angle2),GetY+r*sin(angle2));
	SetTexture(imgFam);
	setGraphic;
        DrawGraphic(GetX+r*cos(angle3),GetY+r*sin(angle3));
	}
	}
	}

        @Finalize
        {
		if(!BeVanished)
		{
			loop(12)
			{
				ItemSet(GetX+rand(-30,30),GetY+rand(-30,30),2);
			}
		}
        } 

task Tmain
{
yield;
GetDamege;
move;
summon;
shot;
rangechange;
eraze;
AutoErazeTime(3600);
Explode(2);
ItemDrop;
}

task ItemDrop
{
	while(GetLife>1000)
	{
		yield;
	}
		if(!BeVanished)
		{
			loop(12)
			{
				ItemSet(GetX+rand(-30,30),GetY+rand(-30,30),2);
			}
			loop(6)
			{
				ItemSet(GetX+rand(-30,30),GetY+rand(-30,30),1);
			}
		}
}

task GetDamege
{
loop
{
	if(GetHitCount!=0)
	{
		SetColor(150,150,255);
		wait(10);
	}
	else
	{
		SetColor(255,255,255);
		if(GetLife<1125)
		{
			SetColor(255,150,150);
		}
	}
yield;
}
}

task rangechange
{
loop(60)
{
	r++;
	yield;
}
wait(300);
loop(60)
{
	r--;
	yield;
}
}

task summon
{
//	CreateEnemyFromScript("Familiar", GetX, GetY,2, 0, 1);
//	CreateEnemyFromScript("Familiar", GetX, GetY,2, 120, 1);
//	CreateEnemyFromScript("Familiar", GetX, GetY,2, 240, 1);
alternative(SelectedDifficult)
case("Easy")
{
	wait(120);
	loop(10)
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer,RED01,5);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer, 5, RED01);
		CreateShot01ToItem(GetX+r*cos(angle1),GetY+r*sin(angle1),2,atan2(GetPlayerY-GetY-r*sin(angle1),GetPlayerX-GetX-r*cos(angle1)),RED01,5);
		CreateShot01ToItem(GetX+r*cos(angle2),GetY+r*sin(angle2),2,atan2(GetPlayerY-GetY-r*sin(angle2),GetPlayerX-GetX-r*cos(angle2)),RED01,5);
		CreateShot01ToItem(GetX+r*cos(angle3),GetY+r*sin(angle3),2,atan2(GetPlayerY-GetY-r*sin(angle3),GetPlayerX-GetX-r*cos(angle3)),RED01,5);
		wait(30);
	}
}
case("Normal")
{
	wait(120);
	loop(15)
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,2.5,GetAngleToPlayer,RED01,5);
	//	CreateShotFromScript( "shot1",GetX, GetY, 2.5, GetAngleToPlayer, 5, RED01);
		CreateShot01ToItem(GetX+r*cos(angle1),GetY+r*sin(angle1),2.5,atan2(GetPlayerY-GetY-r*sin(angle1),GetPlayerX-GetX-r*cos(angle1)),RED01,5);
		CreateShot01ToItem(GetX+r*cos(angle2),GetY+r*sin(angle2),2.5,atan2(GetPlayerY-GetY-r*sin(angle2),GetPlayerX-GetX-r*cos(angle2)),RED01,5);
		CreateShot01ToItem(GetX+r*cos(angle3),GetY+r*sin(angle3),2.5,atan2(GetPlayerY-GetY-r*sin(angle3),GetPlayerX-GetX-r*cos(angle3)),RED01,5);
		wait(20);
	}
}
case("Hard")
{
	wait(120);
	loop(20)
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,3,GetAngleToPlayer,RED01,5);
	//	CreateShotFromScript( "shot1",GetX, GetY, 3, GetAngleToPlayer, 5, RED01);
		CreateShot01ToItem(GetX+r*cos(angle1),GetY+r*sin(angle1),3,atan2(GetPlayerY-GetY-r*sin(angle1),GetPlayerX-GetX-r*cos(angle1)),RED01,5);
		CreateShot01ToItem(GetX+r*cos(angle2),GetY+r*sin(angle2),3,atan2(GetPlayerY-GetY-r*sin(angle2),GetPlayerX-GetX-r*cos(angle2)),RED01,5);
		CreateShot01ToItem(GetX+r*cos(angle3),GetY+r*sin(angle3),3,atan2(GetPlayerY-GetY-r*sin(angle3),GetPlayerX-GetX-r*cos(angle3)),RED01,5);
		wait(15);
	}
}
case("Lunatic")
{
	wait(120);
	loop(30)
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,3.5,GetAngleToPlayer,RED01,5);
	//	CreateShotFromScript( "shot1",GetX, GetY, 3.5, GetAngleToPlayer, 5, RED01);
		CreateShot01ToItem(GetX+r*cos(angle1),GetY+r*sin(angle1),3.5,atan2(GetPlayerY-GetY-r*sin(angle1),GetPlayerX-GetX-r*cos(angle1)),RED01,5);
		CreateShot01ToItem(GetX+r*cos(angle2),GetY+r*sin(angle2),3.5,atan2(GetPlayerY-GetY-r*sin(angle2),GetPlayerX-GetX-r*cos(angle2)),RED01,5);
		CreateShot01ToItem(GetX+r*cos(angle3),GetY+r*sin(angle3),3.5,atan2(GetPlayerY-GetY-r*sin(angle3),GetPlayerX-GetX-r*cos(angle3)),RED01,5);
		wait(10);
	}
}

case("Extra")
{
	wait(60);
	loop(30)
	{
	if(GetLife<=1000)
	{
		break;
	}
	//	CreateShot01(GetX,GetY,3.5,GetAngleToPlayer,RED01,5);
	//	CreateShotFromScript( "shot1",GetX, GetY, 3.5, GetAngleToPlayer, 5, RED01);
		ascent(let i in -1..2)
		{
		CreateShot01ToItem(GetX+r*cos(angle1),GetY+r*sin(angle1),4.0,atan2(GetPlayerY-GetY-r*sin(angle1),GetPlayerX-GetX-r*cos(angle1))+i*10,RED01,5);
		CreateShot01ToItem(GetX+r*cos(angle2),GetY+r*sin(angle2),4.0,atan2(GetPlayerY-GetY-r*sin(angle2),GetPlayerX-GetX-r*cos(angle2))+i*10,RED01,5);
		CreateShot01ToItem(GetX+r*cos(angle3),GetY+r*sin(angle3),4.0,atan2(GetPlayerY-GetY-r*sin(angle3),GetPlayerX-GetX-r*cos(angle3))+i*10,RED01,5);
		}
		wait(10);
	}
}

}

task move
{
	SetMovePosition03(GetX,GetCenterY-60,20,5);
	wait(480);
	SetSpeed(3);
	SetAngle(270);
}

task shot
{
alternative(SelectedDifficult)
case("Easy")
{
wait(120);
	loop
	{

	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in 0..8)
		{
		//	CreateShot01(GetX,GetY,2,GetAngleToPlayer+45*i+22.5,BLUE01,0);
		//	CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer+45*i+22.5, 0, BLUE01);
			CreateShot01ToItem(GetX,GetY,2,GetAngleToPlayer+45*i+22.5,BLUE01,0);
		}
		wait(60);
	}
}
case("Normal")
{
wait(120);
	loop
	{
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in 0..12)
		{
		//	CreateShot01(GetX,GetY,2.5,GetAngleToPlayer+30*i+15,BLUE01,0);
		//	CreateShotFromScript( "shot1",GetX, GetY, 2.5, GetAngleToPlayer+30*i+15, 0, BLUE01);
			CreateShot01ToItem(GetX,GetY,2.5,GetAngleToPlayer+30*i+15,BLUE01,0);
		}
		wait(60);
	}
}
case("Hard")
{
wait(120);
	loop
	{
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in 0..18)
		{
		//	CreateShot01(GetX,GetY,3,GetAngleToPlayer+20*i+10,BLUE01,0);
		//	CreateShotFromScript( "shot1",GetX, GetY, 3, GetAngleToPlayer+20*i+10, 0, BLUE01);
			CreateShot01ToItem(GetX,GetY,3,GetAngleToPlayer+20*i+10,BLUE01,0);
		}
		wait(30);
	}
}
case("Lunatic")
{
wait(120);
	loop
	{
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in 0..24)
		{
		//	CreateShot01(GetX,GetY,4,GetAngleToPlayer+15*i+7.5,BLUE01,0);
		//	CreateShotFromScript( "shot1",GetX, GetY, 4, GetAngleToPlayer+15*i+7.5, 0, BLUE01);
			CreateShot01ToItem(GetX,GetY,4,GetAngleToPlayer+15*i+7.5,BLUE01,0);
		}
		wait(20);
	}
}

case("Extra")
{
wait(60);
	loop
	{
	if(GetLife<=1000)
	{
		break;
	}
		ascent(let i in 0..36)
		{
		//	CreateShot01(GetX,GetY,4,GetAngleToPlayer+15*i+7.5,BLUE01,0);
		//	CreateShotFromScript( "shot1",GetX, GetY, 4.5, GetAngleToPlayer+10*i+5, 0, BLUE01);
			CreateShot01ToItem(GetX,GetY,4.5,GetAngleToPlayer+10*i+5,BLUE01,0);
		}
		wait(20);
	}
}

}

task eraze
{
while(!BeVanished)
{
        	if(GetX<GetClipMinX-64||GetX>GetClipMaxX+64||GetY<GetClipMinY-32||GetY>GetClipMaxY+32)
        	{
        		VanishEnemy();
        	}
yield;
}
}

sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }

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


script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
	let angle=GetAngle;
	let speed=GetSpeed;
	let X=GetX;
	let Y=GetY;
	let SelectedDifficult=GetCommonDataDefault("SELECTEDDIFFICULT","Normal");
    @Initialize {
        SetLife(2000);
        SetTexture(imgFam);
        setGraphic;
	SetSpeed(speed);
	SetAngle(angle);
	TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

        @Finalize
        {
		if(!BeVanished)
		{
			ItemSet(GetX,GetY,1);
		}
        } 

    task TMain {
        yield;
	move;
//	shot;
    }

task move
{
let r=0;
loop(60)
{
	SetX(X+r*cos(angle));
	SetY(Y+r*sin(angle));
	r+=1;
	angle+=1;
	yield;
}
loop(300)
{
	SetX(X+r*cos(angle));
	SetY(Y+r*sin(angle));
	angle+=1;
	yield;
}
loop(60)
{
	SetX(X+r*cos(angle));
	SetY(Y+r*sin(angle));
	r-=1;
	angle+=1;
	yield;
}
VanishEnemy;
}

task shot
{
wait(60);
alternative(SelectedDifficult)
case("Easy")
{
	loop
	{
	//	CreateShot01(GetX,GetY,2,GetAngleToPlayer,RED01,5);
		CreateShotFromScript( "shot1",GetX, GetY, 2, GetAngleToPlayer, 5, RED01);
		wait(30);
	}
}
case("Normal")
{
	loop
	{
	//	CreateShot01(GetX,GetY,2.5,GetAngleToPlayer,RED01,5);
		CreateShotFromScript( "shot1",GetX, GetY, 2.5, GetAngleToPlayer, 5, RED01);
		wait(20);
	}
}
case("Hard")
{
	loop
	{
	//	CreateShot01(GetX,GetY,3,GetAngleToPlayer,RED01,5);
		CreateShotFromScript( "shot1",GetX, GetY, 3, GetAngleToPlayer, 5, RED01);
		wait(15);
	}
}
case("Lunatic")
{
	loop
	{
	//	CreateShot01(GetX,GetY,3.5,GetAngleToPlayer,RED01,5);
		CreateShotFromScript( "shot1",GetX, GetY, 3.5, GetAngleToPlayer, 5, RED01);
		wait(10);
	}
}
}



    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#include_function ".\..\txt/StageEnemydata.txt"
}

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