//Dives by and shoots up/down

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Birds1.png");
let SEshot=("script\SoundEffects\shots5.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=8; let color=2;
let scale=1;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
color=(color-1)*80;

let dive=0;

let invincible=125;
SetSpeed(6);

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

	SetInvincibility(10);
	SetLife(2);
	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(time%20==0){
		CreateShot02(GetX,GetY,rand(3.5,4.5),90,-0.05,1.5,73,0);
		CreateShot02(GetX,GetY,rand(3.5,4.5),270,-0.05,1.5,74,0);
	shots+=1;
	}
	if(time%21==0){	PlaySE(SEshot); }
} //Easy

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

if(GetCommonData("Difficulty")==2){
	if(time%15==0){
		CreateShot02(GetX,GetY,rand(3.5,4.5),90,-0.05,2,73,0);
		CreateShot02(GetX,GetY,rand(3.5,4.5),270,-0.05,2,74,0);
	shots+=1;
	}
	if(time%14==0){	PlaySE(SEshot); }
} // Normal

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

if(GetCommonData("Difficulty")==3){
	if(time%12==0){
	let speed=0;
	let color=80;
	SetShotColor(255,255,255);
		loop(3){
		SetShotColor(255-color,255-color,255-color);
		CreateShot02(GetX,GetY,speed+rand(3.5,4.5),90+rand(-3,3),-0.05,2+speed,73,0);
		CreateShot02(GetX,GetY,speed+rand(3.5,4.5),270+rand(-3,3),-0.05,2+speed,74,0);
		color-=40;
		speed+=0.5;
		}
	shots+=1;
	SetShotColor(255,255,255);
	}
	if(time%14==0){	PlaySE(SEshot); }
} // Hard

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

if(GetCommonData("Difficulty")==4){
	if(time%7==0){
	let speed=0;
	let color=80;
	SetShotColor(255,255,255);
		loop(3){
		SetShotColor(255-color,255-color,255-color);
		CreateShot02(GetX,GetY,speed+rand(3.5,4.5),90+rand(-5,5),-0.05,2+speed,73,0);
		CreateShot02(GetX,GetY,speed+rand(3.5,4.5),270+rand(-5,5),-0.05,2+speed,74,0);
		color-=40;
		speed+=1;
		}
	shots+=1;
	SetShotColor(255,255,255);
	PlaySE(SEshot);
	}
} // Lunatic
} // Onscreen


if(startx<cx){ SetAngle(40-dive); }
if(startx>cx){ SetAngle(140+dive); }
if(dive<40){ dive+=1; }
if(GetSpeed>2){ SetSpeed(GetSpeed-0.03); }


oldX=GetX;
oldY=GetY;
frame++;
time++;
//animation++;
if(animation>=ani*4){ 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(80,color,160,80+color); }
	SetGraphicAngle(0,0,GetAngle+180);
	if(oldX<GetX){ SetGraphicAngle(180,0,-GetAngle); }
	SetGraphicScale(scale,scale);
	SetColor(255-invincible,255-invincible,255);
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
let random=rand_int(0,1);
	if(random==0){ CreateEnemyFromFile("script\Functions\itemscore.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0); }
	if(random==1){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}