script_enemy_main
{
        let csd     = GetCurrentScriptDirectory;
	let speed = GetSpeed;
	let angle = GetAngle;
	let num = GetArgument;
	let imgEnemy;
	imgEnemy=csd~"..\lib\fairy_red.png";
	let SelectedDifficult=GetCommonDataDefault("SELECTEDDIFFICULT","Normal");
	let GateX=[0,0,0,0];
	let GateY=[0,0,0,0];
	let GateAngle=[0,90,180,270];
	let LaserLength=0;
    @Initialize {
        SetLife(1000);
        SetDamageRate(100,100);
	SetTexture(imgEnemy);
	Initialize_Fairy(7);
	Tmain;
	}

    @MainLoop {
	BulletNum=GetEnemyShotCount;
	ascent(i in -1..2)
	{
	SetSkyCollision(GetX+i*16,GetY,32);
	}
	yield;
    }

        @DrawLoop {
		SetColor(ZakoColor[0],ZakoColor[1],ZakoColor[2]);
		DrawFairy(imgEnemy);
		DrawMagicCircle("BLUE",0.50);
	}

        @Finalize
        {
		MagicCircleBreak(GetX,GetY,1,0.5);
		FinalizeItemAndShotnumWithDeleteChild(10);
        } 

task Tmain
{
yield;
OutDamageRateZero;
AutoErazeTime(1200);
GetDamege;
move;
summon;

alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
case("Moderate")
{
shotM;
}
case("Extream")
{
shotM;
}
case("Apocalypse")
{
shotM;
}

}


task move
{
	SetSpeed(GetSpeed);
	SetAngle(GetAngle);

loop
{
	let R1=0;
	let R2=30;

	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,GetX);
	Obj_SetY(obj,GetY);
	ObjShot_SetGraphic(obj, 241);
	ObjShot_SetDelay(obj, 5);
	//ObjShot_SetBombResist(obj,true);
	ObjShot_ToItem(obj,false);
	Obj_SetAlpha(obj,0);
	//loop
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetX(obj,GetX);
		Obj_SetY(obj,GetY);
		ascent(i in 0..4)
		{
		GateX[i]=GetX+R1*cos(GateAngle[i]);
		GateY[i]=GetY+R2*sin(GateAngle[i]);
		}
		ascent(i in 0..4)
		{
		GateAngle[i]=GateAngle[i]+5;
		}
		if(R2<30)
		{
			R2+=1;
		}
		angle+=5;
		yield;
	}
yield;
}

}

let ShotRadius=72;

task shotM
{
	ascent(i in 0..4)
	{
		SparkLaser(GetX,GetY,3,90+90*num,150,18,146,0,i);
	//	GatlingShot(10,angle,i);
	}
SparkLaserCollision(90+90*num);
loop(1000)
{
	let angle=90+90*GetArgument;
	GatlingShot(0,angle);
	wait(1);
}



task GatlingShot(let speed,let angle)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,GetX);
	Obj_SetY(obj,GetY);
	ObjShot_SetGraphic(obj, 241);
	ObjShot_SetDelay(obj, 0);
	Obj_SetAlpha(obj,0);
	ObjShot_ToItem(obj,false);
	//ObjShot_SetBombResist(obj,true);
	wait(5);
	while(!Obj_BeDeleted(obj))
	{
		if(speed<4)
		{
		speed+=0.1;
		}
		Obj_SetX(obj,Obj_GetX(obj)+speed*cos(angle));
		Obj_SetY(obj,GetY-30);
	//	Obj_SetY(obj,GateY[ShotNumber]);
	//	Obj_SetAlpha(obj,200+55*cos(GateAngle[ShotNumber]));
		if(LaserLength<=absolute(Obj_GetX(obj)-GetX))
		{
		LaserLength=absolute(Obj_GetX(obj)-GetX);
		}
		if(Obj_GetX(obj)>GetClipMaxX || Obj_GetX(obj)<GetClipMinX){break;}
		yield;
    	}
	Obj_Delete(obj);
	LaserLength=0;
}

}
/////////////////////////////////////////////
task shotE
{
wait(120);
loop(10)
{
let angle=GetAngleToPlayer;
ascent(let i in 0..24)
{
	GroundCreateShot01(GetX+ShotRadius*cos(angle+i*15),GetY+ShotRadius*sin(angle+i*15),3.5,angle+i*15,9,5);
	GroundCreateShot01(GetX+ShotRadius*cos(angle+i*15),GetY+ShotRadius*sin(angle+i*15),3.75,angle+i*15,9,5);
	GroundCreateShot01(GetX+ShotRadius*cos(angle+i*15),GetY+ShotRadius*sin(angle+i*15),4.0,angle+i*15,9,5);
}
wait(20);
}
}
////////////////////////////////////////////////
task shotA
{
wait(120);
loop(6)
{
let angle=GetAngleToPlayer;
ascent(let j in 0..15)
{
ascent(let i in 0..36)
{
	GroundCreateShot01(GetX+ShotRadius*cos(angle+i*10),GetY+ShotRadius*sin(angle+i*10),4.0+0.5*j,angle+i*10,9,5);
}
wait(2);
}
wait(30);
}

}

		task SparkLaser(x,y,Lspeed,Langle,Slength,width,graphic,delay,ShotNumber)
		{
	let angle=Langle;
	let distance=0;
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj, csd~"..\img\Thunder.png");
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	Obj_SetPosition(obj,x,y);
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetRenderState(obj,ADD);
	ObjEffect_SetLayer(obj,2);
	
	ObjEffect_SetVertexXY(obj, 0, -24, -0);
	ObjEffect_SetVertexXY(obj, 1, 24, -0);
	ObjEffect_SetVertexXY(obj, 2, 24, distance);
	ObjEffect_SetVertexXY(obj, 3, -24, distance);

	let randrect=rand(0,256);
	ObjEffect_SetVertexUV(obj, 0, 0, 0);
	ObjEffect_SetVertexUV(obj, 1, 48, 0);
	ObjEffect_SetVertexUV(obj, 2, 48, randrect);
	ObjEffect_SetVertexUV(obj, 3, 0, randrect);

	ObjEffect_SetScale(obj,1,1);
	ObjEffect_SetAngle(obj,0,0,angle-90);

	let R=255;
	let G=50;
	let B=255;
	let r=0;

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

			loop
			{
				ShotEffect(GateX[ShotNumber]+cos(Langle)*distance,GateY[ShotNumber],5,150,R,G,B);
				Obj_SetPosition(obj,GateX[ShotNumber],GateY[ShotNumber]);
				distance=LaserLength;
				r+=Lspeed;
				ObjEffect_SetVertexXY(obj, 0, -24, -0);
				ObjEffect_SetVertexXY(obj, 1, 24, -0);
				ObjEffect_SetVertexXY(obj, 2, 24, distance);
				ObjEffect_SetVertexXY(obj, 3, -24, distance);
				let randrect=rand(0,256);
				ObjEffect_SetVertexUV(obj, 0, 0, 0+randrect);
				ObjEffect_SetVertexUV(obj, 1, 48, 0+randrect);
				ObjEffect_SetVertexUV(obj, 2, 48, 256+randrect);
				ObjEffect_SetVertexUV(obj, 3, 0, 256+randrect);
				yield;
			}
		}

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 SparkLaserCollision(angle)
		{
			loop
			{
				if(GetPlayerY<=GetY+30 && GetPlayerY>=GetY-30 && GetTimeOfPlayerInvincibility==0)
				{
					if(angle==0)
					{
						if(GetPlayerX>GetX && GetPlayerX<=GetX+LaserLength)
						{
							ShootDownPlayer;
						}
					}
					if(angle==180)
					{
						if(GetPlayerX<GetX && GetPlayerX>=GetX-LaserLength)
						{
							ShootDownPlayer;
						}
					}
				}
				yield;
			}
		}

task summon
{
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 0, 1);
}

#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;
    @Initialize {
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(50000);
        SetDamageRateEx(100,0,50,0);
	TMain;
    }

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

    @DrawLoop {
       // DrawGraphic(GetX, GetY);
    }
        @Finalize
        {
		FinalizeItemAndShotnum(15);
        } 
    task TMain {
        yield;
AutoErazeTime(1190);
	move;
    }

task move
{
	loop
	{
	SetX(0);
	SetY(0);
	yield;
	}
}

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


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