//Shoots at the wall and then bounce off

script_enemy_main{

let shot1=0;
let bullet1=[];
let timer1=[];

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

SetAngle(90);
SetSpeed(3);

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

	SetInvincibility(30);
	SetLife(15);
	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>=40 && time%10==0 && shots<6){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
		if(GetX<cx){ Obj_SetAngle(shot1,120+rand(-10,10)); }
		if(GetX>cx){ Obj_SetAngle(shot1,60+rand(-10,10)); }
		if(GetX==cx){
		let random=rand_int(0,1);
			if(random==0){ Obj_SetAngle(shot1,120+rand(-10,10)); }
			if(random==1){ Obj_SetAngle(shot1,60+rand(-10,10)); }
		}
	Obj_SetSpeed(shot1,4);
	ObjShot_SetGraphic(shot1,108);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	shots++;
	}
	if(time>=40 && time%10==0 && shots<6){ PlaySE(SEshot1); }

	let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i);
		i--;
		}
		else{
			if(Obj_GetX(bullet1[i])<cx && timer1[i]<50 && Obj_GetY(bullet1[i])>=GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])+1); }
			if(Obj_GetX(bullet1[i])>cx && timer1[i]<50 && Obj_GetY(bullet1[i])>=GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])-1); }
			if(Obj_GetX(bullet1[i])<=minx || Obj_GetX(bullet1[i])>=maxx){
			SetShotDirectionType(PLAYER);
			CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,rand(-35,35),0.02,1.5,12,0);
			SetShotDirectionType(ABSOLUTE);
			Obj_Delete(bullet1[i]);
			}
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
} //Easy

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

if(GetCommonData("Difficulty")==2){
	if(time>=40 && time%8==0 && shots<10){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
		if(GetX<cx){ Obj_SetAngle(shot1,120+rand(-20,20)); }
		if(GetX>cx){ Obj_SetAngle(shot1,60+rand(-20,20)); }
		if(GetX==cx){
		let random=rand_int(0,1);
			if(random==0){ Obj_SetAngle(shot1,120+rand(-20,20)); }
			if(random==1){ Obj_SetAngle(shot1,60+rand(-20,20)); }
		}
	Obj_SetSpeed(shot1,4);
	ObjShot_SetGraphic(shot1,108);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	shots++;
	}
	if(time>=40 && time%10==0 && shots<10){ PlaySE(SEshot1); }

	let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i);
		i--;
		}
		else{
			if(Obj_GetX(bullet1[i])<cx && timer1[i]<50 && Obj_GetY(bullet1[i])>=GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])+1); }
			if(Obj_GetX(bullet1[i])>cx && timer1[i]<50 && Obj_GetY(bullet1[i])>=GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])-1); }
			if(Obj_GetX(bullet1[i])<=minx || Obj_GetX(bullet1[i])>=maxx){
			SetShotDirectionType(PLAYER);
			CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,rand(-30,30),0.02,1.5,12,0);
			SetShotDirectionType(ABSOLUTE);
			Obj_Delete(bullet1[i]);
			}
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
} // Normal

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

if(GetCommonData("Difficulty")==3){
	if(time>=40 && time%6==0 && shots<24){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
		if(GetX<cx){ Obj_SetAngle(shot1,120+rand(-20,20)); }
		if(GetX>cx){ Obj_SetAngle(shot1,60+rand(-20,20)); }
		if(GetX==cx){
		let random=rand_int(0,1);
			if(random==0){ Obj_SetAngle(shot1,120+rand(-20,20)); }
			if(random==1){ Obj_SetAngle(shot1,60+rand(-20,20)); }
		}
	Obj_SetSpeed(shot1,4);
	ObjShot_SetGraphic(shot1,108);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;

	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
		if(GetX<cx){ Obj_SetAngle(shot1,240+rand(-10,10)); }
		if(GetX>cx){ Obj_SetAngle(shot1,300+rand(-10,10)); }
		if(GetX==cx){
		let random=rand_int(0,1);
			if(random==0){ Obj_SetAngle(shot1,240+rand(-10,10)); }
			if(random==1){ Obj_SetAngle(shot1,300+rand(-10,10)); }
		}
	Obj_SetSpeed(shot1,4);
	ObjShot_SetGraphic(shot1,108);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	shots++;
	}
	if(time>=40 && time%10==0 && shots<24){ PlaySE(SEshot1); }

	let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i);
		i--;
		}
		else{
			if(Obj_GetX(bullet1[i])<cx && timer1[i]<50 && Obj_GetY(bullet1[i])>=GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])+1); }
			if(Obj_GetX(bullet1[i])>cx && timer1[i]<50 && Obj_GetY(bullet1[i])>=GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])-1); }
			if(Obj_GetX(bullet1[i])<cx && timer1[i]<50 && Obj_GetY(bullet1[i])<GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])-1); }
			if(Obj_GetX(bullet1[i])>cx && timer1[i]<50 && Obj_GetY(bullet1[i])<GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])+1); }
			if(Obj_GetX(bullet1[i])<=minx || Obj_GetX(bullet1[i])>=maxx){
			SetShotDirectionType(PLAYER);
			CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,rand(-25,25),0.02,1.5,12,0);
			SetShotDirectionType(ABSOLUTE);
			Obj_Delete(bullet1[i]);
			}
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
} // Hard

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

if(GetCommonData("Difficulty")==4){
	if(time>=40 && time%5==0 && shots<30){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
		if(GetX<cx){ Obj_SetAngle(shot1,120+rand(-20,20)); }
		if(GetX>cx){ Obj_SetAngle(shot1,60+rand(-20,20)); }
		if(GetX==cx){
		let random=rand_int(0,1);
			if(random==0){ Obj_SetAngle(shot1,120+rand(-20,20)); }
			if(random==1){ Obj_SetAngle(shot1,60+rand(-20,20)); }
		}
	Obj_SetSpeed(shot1,4);
	ObjShot_SetGraphic(shot1,108);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;

	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
		if(GetX<cx){ Obj_SetAngle(shot1,240+rand(-20,20)); }
		if(GetX>cx){ Obj_SetAngle(shot1,300+rand(-20,20)); }
		if(GetX==cx){
		let random=rand_int(0,1);
			if(random==0){ Obj_SetAngle(shot1,240+rand(-20,20)); }
			if(random==1){ Obj_SetAngle(shot1,300+rand(-20,20)); }
		}
	Obj_SetSpeed(shot1,4);
	ObjShot_SetGraphic(shot1,108);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	shots++;
	}
	if(time>=40 && time%10==0 && shots<30){ PlaySE(SEshot1); }

	let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); timer1=erase(timer1,i);
		i--;
		}
		else{
			if(Obj_GetX(bullet1[i])<cx && timer1[i]<50 && Obj_GetY(bullet1[i])>=GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])+1); }
			if(Obj_GetX(bullet1[i])>cx && timer1[i]<50 && Obj_GetY(bullet1[i])>=GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])-1); }
			if(Obj_GetX(bullet1[i])<cx && timer1[i]<50 && Obj_GetY(bullet1[i])<GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])-1); }
			if(Obj_GetX(bullet1[i])>cx && timer1[i]<50 && Obj_GetY(bullet1[i])<GetY){ Obj_SetAngle(bullet1[i],Obj_GetAngle(bullet1[i])+1); }
			if(Obj_GetX(bullet1[i])<=minx || Obj_GetX(bullet1[i])>=maxx){
			SetShotDirectionType(PLAYER);
			CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,rand(-20,20),0.02,1.5,12,0);
			SetShotDirectionType(ABSOLUTE);
			Obj_Delete(bullet1[i]);
			}
		timer1[i]=timer1[i]+1;
		}
	i++;
	}
} // Lunatic
} // OnScreen



if(GetSpeed>0 && time<300){ SetSpeed(GetSpeed-0.02); }
if(time>=300){ SetSpeed(GetSpeed-0.02); animation++; }

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==0){
	loop(3){ CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0); }
	loop(2){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0); }
	}
	if(GetArgument==1){ CreateEnemyFromFile("script\Functions\itembigpower.txt",GetX+rand(-20,20),GetY+rand(-20,20),0,0,0); }
	if(GetArgument==2){ CreateEnemyFromFile("script\Functions\itemlife.txt",GetX,GetY,0,0,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}