//Flies down and shoots a circle that homes on the player.

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Birds2.png");
let SEshotm8=("script\SoundEffects\shotm8.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let startx=GetX; let starty=GetY;
let frame=0; let time=0; let animation=0;
let color=80;
let ani=4;
let scale=1;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

SetSpeed(GetArgument);
SetAngle(90);

@Initialize{
	LoadGraphic("\script\Images\Enemies\Birds2.png");
	LoadSE("script\SoundEffects\shotm8.wav");

	SetInvincibility(40);
	SetLife(10);
	SetDamageRate(10,3); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

if(GetX<=minx-32 || GetX>=maxx+32 || GetY<=miny-32 || GetY>=maxy+32 && frame>=60){ VanishEnemy; }

if((GetX>minx && GetX<maxx) && (GetY>miny && GetY<maxy)){
SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);


if(GetCommonData("Difficulty")==1){
	if(shots==0 && GetSpeed<=0){
	let shot1=0;
	let angle=rand(0,360);
		loop(15){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,2.5,angle,0,-0.06,0,58);
		SetShotDirectionType(PLAYER);
		SetShotDataA(shot1,60,0,0,0,0.06,2.5,58);
		SetShotDirectionType(ABSOLUTE);
		FireShot(shot1);
		angle+=360/15;
		}
	PlaySE(SEshotm8);
	shots++;
	}
} //Easy

//=========================================================================================================

if(GetCommonData("Difficulty")==2){
	if(shots==0 && GetSpeed<=0){
	let shot1=0;
	let angle=rand(0,360);
		loop(20){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,2.5,angle,0,-0.05,0,58);
		SetShotDirectionType(PLAYER);
		SetShotDataA(shot1,60,0,0,0,0.06,3,58);
		SetShotDirectionType(ABSOLUTE);
		FireShot(shot1);
		angle+=360/20;
		}
	PlaySE(SEshotm8);
	shots++;
	}
} // Normal

//=========================================================================================================

if(GetCommonData("Difficulty")==3){
	if(shots==0 && GetSpeed<=0){
	let shot1=0;
	let angle=rand(0,360);
		loop(20){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,3.5,angle,0,-0.05,0,58);
		SetShotDirectionType(PLAYER);
		SetShotDataA(shot1,60,0,0,0,0.06,4,58);
		SetShotDirectionType(ABSOLUTE);
		FireShot(shot1);
		angle+=360/20;
		}
	PlaySE(SEshotm8);
	shots++;
	}
} // Hard

//=========================================================================================================

if(GetCommonData("Difficulty")==4){
SetShotColor(255-(shots*100),255-(shots*100),255-(shots*100));
	if(shots<2 && GetSpeed<=0 && time%30==0){
	let shot1=0;
	let angle=rand(0,360);
		loop(20){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,4-(shots/2),angle,0,-0.05,0,58);
		SetShotDirectionType(PLAYER);
		SetShotDataA(shot1,60,0,0,0,0.06,4.5,58);
		SetShotDirectionType(ABSOLUTE);
		FireShot(shot1);
		angle+=360/20;
		}
	PlaySE(SEshotm8);
	shots++;
	}
SetShotColor(255,255,255);
} // Lunatic
} // OnScreen

if(time>=20 && GetSpeed>0){ SetSpeed(GetSpeed-0.08); }
if(time<130 && GetSpeed<0){ SetSpeed(0); }
if(time>=130){ SetSpeed(GetSpeed-0.08); }


oldX=GetX;
oldY=GetY;
frame++;
time++;
animation++;
if(animation>=ani*6){ animation=0; }
if(GetTimeOfInvincibility<25 && invincible>0){ invincible=GetTimeOfInvincibility*5; }

}

@DrawLoop{
let side=0;
	SetTexture(GRenemy);
		if(oldX<GetX || oldX>GetX){ side=128; }
		if(animation>=ani*0 && animation<ani*1){ SetGraphicRect(0,color,80,80+color); }
		if(animation>=ani*1 && animation<ani*2){ SetGraphicRect(80,color,160,80+color); }
		if(animation>=ani*2 && animation<ani*3){ SetGraphicRect(160,color,240,80+color); }
		if(animation>=ani*3 && animation<ani*4){ SetGraphicRect(240,color,320,80+color); }
		if(animation>=ani*4 && animation<ani*5){ SetGraphicRect(160,color,240,80+color); }
		if(animation>=ani*5 && animation<ani*6){ SetGraphicRect(80,color,160,80+color); }
	SetGraphicAngle(0,0,0);
	if(oldX<GetX){ SetGraphicAngle(180,0,0); }
	SetGraphicScale(scale,scale);
	SetColor(255-invincible,255-invincible,255);
	DrawGraphic(GetX,GetY+3*sin(time*2));
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
	loop(2){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-25,25),0,0,0); }
	loop(2){ CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-25,25),GetY+rand(-25,25),0,0,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}