//Flies down and shoots circles

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Birds2.png");
let SEshotb5=("script\SoundEffects\shotb5.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 ani=6; let color=3;
let scale=1.5;
let shots=0;
let shotcolor=3; let shotspeed=0;
let oldX=0; let oldY=0;
color=(color-1)*80;
let invincible=125;

SetSpeed(GetArgument[0]);
SetAngle(90);

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

	SetInvincibility(50);
	SetLife(85);
	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,16*scale);
SetCollisionB(GetX,GetY,16*scale);


if(GetCommonData("Difficulty")==1){
	if(GetSpeed<0.5 && time%120==0){
	let angle=rand(0,360);
	let shot1=0;
		loop(22){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,2.25,angle,1,-0.01,1.5,24);
		SetShotDataA(shot1,75,NULL,NULL,0,-0.01,1.5,24);
		FireShot(shot1);
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,2.25,angle,-1,-0.01,2,35);
		SetShotDataA(shot1,75,NULL,NULL,0,-0.01,2,35);
		FireShot(shot1);
		angle+=360/22;
		}
	PlaySE(SEshotb5);
	}
} //Easy

if(GetCommonData("Difficulty")==2){
	if(GetSpeed<0.5 && time%100==0){
	let angle=rand(0,360);
	let shot1=0;
		loop(28){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,2.5,angle,1,-0.01,2,24);
		SetShotDataA(shot1,75,NULL,NULL,0,-0.01,2,24);
		FireShot(shot1);
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,2.5,angle,-1,-0.01,2,35);
		SetShotDataA(shot1,75,NULL,NULL,0,-0.01,2,35);
		FireShot(shot1);
		angle+=360/28;
		}
	PlaySE(SEshotb5);
	}
} //Normal

if(GetCommonData("Difficulty")==3){
	if(GetSpeed<0.5 && time%80==0){
	let angle=rand(0,360);
	let shot1=0;
		loop(36){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,2.75,angle,1,-0.01,1.7,24);
		SetShotDataA(shot1,75,NULL,NULL,0,-0.01,1.7,24);
		FireShot(shot1);
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,2.75,angle,-1,-0.01,2.2,35);
		SetShotDataA(shot1,75,NULL,NULL,0,-0.01,2.2,35);
		FireShot(shot1);
		angle+=360/36;
		}
	PlaySE(SEshotb5);
	}
} //Hard

if(GetCommonData("Difficulty")==4){
	if(GetSpeed<0.5 && time%60==0){
	let angle=rand(0,360);
	let shot1=0;
		loop(44){
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,3,angle,1,-0.01,2.2,24);
		SetShotDataA(shot1,75,NULL,NULL,0,-0.01,2.2,24);
		FireShot(shot1);
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,3,angle,-1,-0.01,2.2,35);
		SetShotDataA(shot1,75,NULL,NULL,0,-0.01,2.2,35);
		FireShot(shot1);
		angle+=360/44;
		}
	PlaySE(SEshotb5);
	}
} //Lunatic
} //Onscreen

if(GetSpeed>0 && time<90){ SetSpeed(GetSpeed-(GetArgument[0]/80)); }
if(GetSpeed<0 && time<600){ SetSpeed(0); }
if(time>=600){ 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);
	if(GetArgument[1]==0){
	CreateEnemyFromFile("script\Functions\itembigpower.txt",GetX+rand(-25,25),GetY+rand(-25,25),0,0,0);
	loop(5){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
	}
	if(GetArgument[1]==1){
	CreateEnemyFromFile("script\Functions\itembomb.txt",GetX,GetY,0,0,0);
	}
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}