script_enemy_main{

let angle2=GetArgument[0];
let spindirection=GetArgument[1];
if(spindirection%2==0){ spindirection=-0.5; }
else{ spindirection=0.5; }
let spinspeed=2;
let shoot=0;
let stopped=0;

let delete=0;
let shots=0;

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

let shot2=0;
let bullet2=[];

let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SElaserm4=("script\SoundEffects\laserm4.wav");

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

	SetScore(100);
	SetLife(1);
}
	
@MainLoop{

if(time==0){
let radius=10;
let angle=45;
	loop(4){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+radius*cos(angle),GetY+(radius*2.25)*sin(angle));
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,0);
	ObjShot_SetGraphic(shot1,35);
	ObjShot_SetBombResist(shot1,true);
	Obj_SetAutoDelete(shot1,false);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=atan2(GetY-Obj_GetY(shot1),GetX-Obj_GetX(shot1))+GetArgument[0];
	radius1=radius1~[shot1];
	radius1[length(bullet1)-1]=(((GetX-Obj_GetX(shot1))^2+(GetY-Obj_GetY(shot1))^2)^0.5);
	angle+=360/4;
	}
	loop(4){
	shot2=(Obj_Create(OBJ_LASER));
	Obj_SetPosition(shot2,GetX+radius*cos(angle),GetY+(radius*2.25)*sin(angle));
	Obj_SetAngle(shot2,angle);
	Obj_SetSpeed(shot2,0);
	ObjLaser_SetLength(shot2,10);
	ObjLaser_SetWidth(shot2,15);
	ObjLaser_SetSource(shot2,false);
	ObjShot_SetGraphic(shot2,11);
	Obj_SetAutoDelete(shot2,false);
	bullet2=bullet2~[shot2];
	angle+=360/4;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i); radius1=erase(radius1,i);
	bullet2=erase(bullet2,i);
	i--;
	}
	else{
	Obj_SetPosition(bullet1[i],GetX+radius1[i]*cos(angle1[i]),GetY+radius1[i]*sin(angle1[i]));
	Obj_SetAngle(bullet1[i],angle1[i]);
	
	if(shots>=5){ Obj_Delete(bullet1[i]); Obj_Delete(bullet2[i]); }

	if(shoot!=1){ radius1[i]=radius1[i]+(0.75*spinspeed); angle1[i]=angle1[i]+(spindirection*spinspeed/2); }
	}
if(shots>=5){ VanishEnemy; }
i++;

let a=0;
let b=1;
	loop(4){
	Obj_SetPosition(bullet2[a],Obj_GetX(bullet1[a]),Obj_GetY(bullet1[a]));
	Obj_SetAngle(bullet2[a],atan2(Obj_GetY(bullet1[a])-Obj_GetY(bullet1[b]),Obj_GetX(bullet1[a])-Obj_GetX(bullet1[b]))+180);
	ObjLaser_SetLength(bullet2[a],(((Obj_GetX(bullet1[a])-Obj_GetX(bullet1[b]))^2+(Obj_GetY(bullet1[a])-Obj_GetY(bullet1[b]))^2)^0.5));

	if(shoot==1){ Obj_SetAlpha(bullet2[a],100); Obj_SetCollisionToPlayer(bullet2[a],false); }
	if(shoot==0 || shoot==2){ Obj_SetAlpha(bullet2[a],255); Obj_SetCollisionToPlayer(bullet2[a],true); }

	a++;
	b++;
	if(b>3){ b-=4; }
	}
}


if(shoot==0 && spinspeed>0){ spinspeed-=0.015; }
if(shoot==0 && spinspeed<=0){ shoot=1; frame=0; PlaySE(SElaserm4); }
if(shoot==1 && frame==120){ shoot=2; stopped++; }
if(shoot==2){ spinspeed+=0.01; }
if(spinspeed>1){ shoot=0; }
if(stopped==4 && frame==121){ delete=1; }

if(shoot==1 && frame==0){
	let a=0;
	let b=1;
	let expand=1;
	loop(4){
	if(a%2!=0){ expand=2.25; }
	else{ expand=1; }
	let shotx=0;
	let size=(((Obj_GetX(bullet1[a])-Obj_GetX(bullet1[b]))^2+(Obj_GetY(bullet1[a])-Obj_GetY(bullet1[b]))^2)^0.5)/25;
	let radiusgrow=(((Obj_GetX(bullet1[a])-Obj_GetX(bullet1[b]))^2+(Obj_GetY(bullet1[a])-Obj_GetY(bullet1[b]))^2)^0.5)/size;
	let radius=radiusgrow;
	let angle=atan2(Obj_GetY(bullet1[a])-Obj_GetY(bullet1[b]),Obj_GetX(bullet1[a])-Obj_GetX(bullet1[b]))+180;
		loop(size-1){
		CreateShotA(shotx,Obj_GetX(bullet1[a])+radius*cos(angle),Obj_GetY(bullet1[a])+radius*sin(angle),0);
		SetShotDataA(shotx,0,0,0,0,0,0,35);
		SetShotKillTime(shotx,120);
		FireShot(shotx);
		radius+=radiusgrow;
		}
	a++;
	b++;
	if(b>3){ b-=4; }
	}
}


SetY(GetY+(spinspeed*0.7));
SetX(GetX+spinspeed*cos(angle2));


if(GetX>maxx+300 || GetX<minx-300 || GetY>maxy+300 || GetY<miny-300 || delete==1){
DeleteEnemyShot(CHILD);
VanishEnemy;
}


time++;
frame++;

}

@DrawLoop{
}

@Finalize{
}

}