script_enemy_main{

let SEfire1=("script\SoundEffects\fire1.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");

let frame=rand_int(0,360); let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

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

let radius=0;

let grow=0;
let direction=rand_int(1,2);

SetAngle(GetArgument[0]);
let angle=GetAngle;
let type=GetArgument[1];

@Initialize{
	LoadSE("script\SoundEffects\enemydeath1.wav");
	LoadSE("script\SoundEffects\fire15.wav");

	SetScore(100);
	if(GetCommonData("Difficulty")==1){ SetLife(8); }
	else{ SetLife(15); }
	SetDamageRate(10,10); 
	MagicCircle(false);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,radius/1.3);


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


if(GetCommonData("Difficulty")==1){

SetSpeed(2.25);
if(type==3 && time==0){ SetAngle(GetAngleToPlayer+angle); }

if(time==0){
let angle=rand(0,360);
	loop(5){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	if(type==1){ ObjShot_SetGraphic(shot1,140); }
	if(type==2){ ObjShot_SetGraphic(shot1,137); }
	if(type==3){ ObjShot_SetGraphic(shot1,133); }
	bullet1=bullet1~[shot1];
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/5;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	Obj_SetPosition(bullet1[i],GetX+(radius*grow)*cos(angle1[i]),GetY+(radius*grow)*sin(angle1[i]));
	if(direction==1){ Obj_SetAngle(bullet1[i],angle1[i]+90); }
	if(direction==2){ Obj_SetAngle(bullet1[i],angle1[i]-90); }

	if(time%35==0 && time>=10 && Obj_GetX(bullet1[i])<maxx && Obj_GetX(bullet1[i])>minx && Obj_GetY(bullet1[i])<maxy && Obj_GetY(bullet1[i])>miny){
if(type==1){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-3,3),0.0125,1.5,126,10); }
if(type==2){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-3,3),0.0125,1.5,124,10); }
if(type==3){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-3,3),0.0125,1.5,122,10); }
	}
	if(time%10==0 && time>=10){ PlaySE(SEfire1); }

	if(direction==1){ angle1[i]=angle1[i]+5; }
	if(direction==2){ angle1[i]=angle1[i]-5; }
	
	if(time>=30){ ObjShot_SetBombResist(bullet1[i],false); }
	}
i++;
}
if(length(bullet1)==0){ VanishEnemy; }

if(type==1 || type==3){ radius=20+6*cos(frame*3); }
if(type==2){ radius+=0.25; }
if(grow<1){ grow+=0.1; }

} //Easy

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

if(GetCommonData("Difficulty")==2){

SetSpeed(2.5);
if(type==3 && time==0){ SetAngle(GetAngleToPlayer+angle); }

if(time==0){
let angle=rand(0,360);
	loop(5){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	if(type==1){ ObjShot_SetGraphic(shot1,140); }
	if(type==2){ ObjShot_SetGraphic(shot1,137); }
	if(type==3){ ObjShot_SetGraphic(shot1,133); }
	bullet1=bullet1~[shot1];
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/5;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	Obj_SetPosition(bullet1[i],GetX+(radius*grow)*cos(angle1[i]),GetY+(radius*grow)*sin(angle1[i]));
	if(direction==1){ Obj_SetAngle(bullet1[i],angle1[i]+90); }
	if(direction==2){ Obj_SetAngle(bullet1[i],angle1[i]-90); }

	if(time%25==0 && time>=10 && Obj_GetX(bullet1[i])<maxx && Obj_GetX(bullet1[i])>minx && Obj_GetY(bullet1[i])<maxy && Obj_GetY(bullet1[i])>miny){
if(type==1){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-3,3),0.016,1.7,126,10); }
if(type==2){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-3,3),0.016,1.7,124,10); }
if(type==3){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-3,3),0.016,1.7,122,10); }
	}
	if(time%10==0 && time>=10){ PlaySE(SEfire1); }

	if(direction==1){ angle1[i]=angle1[i]+6; }
	if(direction==2){ angle1[i]=angle1[i]-6; }
	
	if(time>=30){ ObjShot_SetBombResist(bullet1[i],false); }
	}
i++;
}
if(length(bullet1)==0){ VanishEnemy; }

if(type==1 || type==3){ radius=30+8*cos(frame*3); }
if(type==2){ radius+=0.4; }
if(grow<1){ grow+=0.1; }

} //Normal

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

if(GetCommonData("Difficulty")==3){

SetSpeed(2.75);
if(type==3 && time==0){ SetAngle(GetAngleToPlayer+angle); }

if(time==0){
let angle=rand(0,360);
	loop(5){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	if(type==1){ ObjShot_SetGraphic(shot1,140); }
	if(type==2){ ObjShot_SetGraphic(shot1,137); }
	if(type==3){ ObjShot_SetGraphic(shot1,133); }
	bullet1=bullet1~[shot1];
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/5;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	Obj_SetPosition(bullet1[i],GetX+(radius*grow)*cos(angle1[i]),GetY+(radius*grow)*sin(angle1[i]));
	if(direction==1){ Obj_SetAngle(bullet1[i],angle1[i]+90); }
	if(direction==2){ Obj_SetAngle(bullet1[i],angle1[i]-90); }

	if(time%18==0 && time>=10 && Obj_GetX(bullet1[i])<maxx && Obj_GetX(bullet1[i])>minx && Obj_GetY(bullet1[i])<maxy && Obj_GetY(bullet1[i])>miny){
if(type==1){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-5,5),0.018,1.85,126,10); }
if(type==2){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-5,5),0.018,1.85,124,10); }
if(type==3){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-5,5),0.018,1.85,122,10); }
	}
	if(time%5==0 && time>=10){ PlaySE(SEfire1); }

	if(direction==1){ angle1[i]=angle1[i]+8; }
	if(direction==2){ angle1[i]=angle1[i]-8; }
	
	if(time>=30){ ObjShot_SetBombResist(bullet1[i],false); }
	}
i++;
}
if(length(bullet1)==0){ VanishEnemy; }

if(type==1 || type==3){ radius=35+10*cos(frame*3); }
if(type==2){ radius+=0.5; }
if(grow<1){ grow+=0.1; }

} //Hard

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

if(GetCommonData("Difficulty")==4){

SetSpeed(3);
if(type==3 && time==0){ SetAngle(GetAngleToPlayer+angle); }

if(time==0){
let angle=rand(0,360);
	loop(5){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	ObjShot_SetBombResist(shot1,true);
	if(type==1){ ObjShot_SetGraphic(shot1,140); }
	if(type==2){ ObjShot_SetGraphic(shot1,137); }
	if(type==3){ ObjShot_SetGraphic(shot1,133); }
	bullet1=bullet1~[shot1];
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/5;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	Obj_SetPosition(bullet1[i],GetX+(radius*grow)*cos(angle1[i]),GetY+(radius*grow)*sin(angle1[i]));
	if(direction==1){ Obj_SetAngle(bullet1[i],angle1[i]+90); }
	if(direction==2){ Obj_SetAngle(bullet1[i],angle1[i]-90); }

	if(time%12==0 && time>=10 && Obj_GetX(bullet1[i])<maxx && Obj_GetX(bullet1[i])>minx && Obj_GetY(bullet1[i])<maxy && Obj_GetY(bullet1[i])>miny){
if(type==1){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-5,5),0.02,2,126,10); }
if(type==2){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-5,5),0.02,2,124,10); }
if(type==3){ CreateShot02(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0,Obj_GetAngle(bullet1[i])+rand(-5,5),0.02,2,122,10); }
	}
	if(time%5==0 && time>=10){ PlaySE(SEfire1); }

	if(direction==1){ angle1[i]=angle1[i]+10; }
	if(direction==2){ angle1[i]=angle1[i]-10; }
	
	if(time>=30){ ObjShot_SetBombResist(bullet1[i],false); }
	}
i++;
}
if(length(bullet1)==0){ VanishEnemy; }

if(type==1 || type==3){ radius=40+15*cos(frame*3); }
if(type==2){ radius+=0.6; }
if(grow<1){ grow+=0.1; }

} //Lunatic


time++;
frame++;

}

@DrawLoop{
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
	loop(2){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-25,25),GetY+rand(-50,50),0,0,0); }
}
	let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); angle1=erase(angle1,i);
		i--;
		}
		else{
		Obj_Delete(bullet1[i]);
		}
	i++;
	}
}

}