script_enemy_main{

let SEshotm6=("script\SoundEffects\shotm6.wav");
let SEshotb1=("script\SoundEffects\shotb1.wav");

let speed=GetArgument[0];
let randomangle=GetArgument[1];
let color=GetArgument[2];
color=(color-1)*40;
let grow=0;

let angle=0;
let radius=0;
let accel=0;

let usespell=0;
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 SEdeath=("script\SoundEffects\enemydeath1.wav");
let GRfamiliar=("\script\Images\OtherEffects\Chips.png");

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

	LoadSE("script\SoundEffects\enemydeath1.wav");
	LoadGraphic("\script\Images\OtherEffects\Chips.png");

	SetScore(100);
	SetLife(10);
	SetDamageRate(10,10);
	MagicCircle(false);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,grow*18);
SetCollisionB(GetX,GetY,grow*18);

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

let color=0;
if(GetArgument[2]==1){ color=13; }
if(GetArgument[2]==2){ color=14; }
if(GetArgument[2]==3){ color=15; }
if(GetArgument[2]==4){ color=17; }
if(GetArgument[2]==5){ color=20; }
if(GetArgument[2]==6){ color=21; }


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

if(time==0){
	angle=atan2(GetPlayerY-GetY,GetPlayerX-GetX);
	radius=(((GetPlayerX-GetX)^2+(GetPlayerY-GetY)^2)^0.5)/100*(pi/2)*speed;
	SetAngle(angle+rand(-randomangle,randomangle));
PlaySE(SEshotm6);
}
if(time<100){
	accel+=90/100;
	SetSpeed(radius*cos(accel));
}
if(time==100){
let angle1=GetAngleToPlayer;
	loop(18){
	CreateShot02(GetX+8*cos(angle1),GetY+8*sin(angle1),0,angle1,0.02,1.5,0+color,15);
	angle1+=360/18;
	}
PlaySE(SEshotb1);
VanishEnemy;
}

} //Easy

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

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

if(time==0){
	angle=atan2(GetPlayerY-GetY,GetPlayerX-GetX);
	radius=(((GetPlayerX-GetX)^2+(GetPlayerY-GetY)^2)^0.5)/100*(pi/2)*speed;
	SetAngle(angle+rand(-randomangle,randomangle));
PlaySE(SEshotm6);
}
if(time<100){
	accel+=90/100;
	SetSpeed(radius*cos(accel));
}
if(time==100){
let angle1=GetAngleToPlayer;
	loop(16){
	CreateShot02(GetX+8*cos(angle1),GetY+8*sin(angle1),0,angle1,0.02,1.5,0+color,15);
	angle1+=360/16;
	}
PlaySE(SEshotb1);
VanishEnemy;
}

} //Normal

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

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

if(time==0){
	angle=atan2(GetPlayerY-GetY,GetPlayerX-GetX);
	radius=(((GetPlayerX-GetX)^2+(GetPlayerY-GetY)^2)^0.5)/80*(pi/2)*speed;
	SetAngle(angle+rand(-randomangle,randomangle));
PlaySE(SEshotm6);
}
if(time<80){
	accel+=90/80;
	SetSpeed(radius*cos(accel));
}
if(time==80){
let angle1=GetAngleToPlayer;
	loop(24){
	CreateShot02(GetX+8*cos(angle1),GetY+8*sin(angle1),0,angle1,0.02,1.5,0+color,15);
	angle1+=360/24;
	}
PlaySE(SEshotb1);
VanishEnemy;
}

} //Hard

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

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

if(time==0){
	angle=atan2(GetPlayerY-GetY,GetPlayerX-GetX);
	radius=(((GetPlayerX-GetX)^2+(GetPlayerY-GetY)^2)^0.5)/80*(pi/2)*speed;
	SetAngle(angle+rand(-randomangle,randomangle));
PlaySE(SEshotm6);
}
if(time<80){
	accel+=90/80;
	SetSpeed(radius*cos(accel));
}
if(time==80){
let angle1=GetAngleToPlayer;
	loop(20){
	CreateShot02(GetX+8*cos(angle1),GetY+8*sin(angle1),0,angle1,0.02,1.5,0+color,15);
	angle1+=360/20;
	}
PlaySE(SEshotb1);
VanishEnemy;
}

} //Lunatic


if(grow<1){ grow+=0.1; }
if(grow>=1){ grow=1; }

time++;
frame++;

}

@DrawLoop{
	SetGraphicScale(grow,grow);
	SetTexture(GRfamiliar);
	SetGraphicAngle(0,0,time*5);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicRect(0+color,0,40+color,40);
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){ PlaySE(SEdeath); SetCommonData("FamiliarDestroyed",1); }
if(BeVanished==false){ PlaySE(SEdeath); DeleteEnemyShotInCircle(SHOT,GetX,GetY,30); }
}

}