script_enemy_main{

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

let fade=1;
let scale=0;
let maxscale=1;
let bullets=10;
let spinspeed=3;
let radius=60;
let speed=2;

let type=GetArgument[0];
let direction=GetArgument[1];
let color=GetArgument[3];
let circlecolor=GetArgument[4];
let scalespeed=GetArgument[5];
let shottype=GetArgument[6];
let deform=GetArgument[7];

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 SEmagics5=("\script\SoundEffects\magics5.wav");
let GRenemy=("\script\Images\OtherEffects\SpellCircle1b.png");

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

	LoadGraphic("\script\Images\OtherEffects\SpellCircle1b.png");

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

//type1 = medium size, don't bounce, average speed
//type2 = big size, bounce, slow
//type3 = small size, bounce, fast speed

if(type==1){ bullets=10; speed=2; maxscale=1; spinspeed=0.8; }
if(type==2){ bullets=20; speed=1.5; maxscale=2; spinspeed=0.5; }
if(type==3){ bullets=10; speed=3.5; maxscale=0.5; spinspeed=4; }


if(time==0){
	SetAngle(GetArgument[2]);
	SetSpeed(speed);
}

if(color>0){ SetShotColor((230+20*cos(color+0)*fade),(230+20*cos(color+120)*fade),(230+20*cos(color+240))*fade); }
if(color==0){ SetShotColor(255,255,255); }

if(time==0){
let angle=rand(0,360);
	loop(bullets){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
if(shottype==1){ ObjShot_SetGraphic(shot1,132); }
if(shottype==2){ ObjShot_SetGraphic(shot1,11); }
	ObjShot_SetBombResist(shot1,true);
	bullet1=bullet1~[shot1];
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/bullets;
	}
}

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*scale)*cos(angle1[i]+(deform*cos(frame*2))),GetY+(radius*scale)*sin(angle1[i]));
	Obj_SetAngle(bullet1[i],angle1[i]);
	if(direction==1){ angle1[i]=angle1[i]+spinspeed; }
	if(direction==2){ angle1[i]=angle1[i]-spinspeed; }
if(Obj_GetX(bullet1[i])>maxx+70){ Obj_Delete(bullet1[i]); } 
if(Obj_GetX(bullet1[i])<minx-70){ Obj_Delete(bullet1[i]); }
if(Obj_GetY(bullet1[i])>maxy+70){ Obj_Delete(bullet1[i]); }
if(Obj_GetY(bullet1[i])<miny-70){ Obj_Delete(bullet1[i]); }
	}
i++;
}


if(type==1 || type==3){
	if(GetX<=minx){
		SetAngle(180-GetAngle);
		SetX(GetX+GetSpeed);
		SetSpeed(0);
		PlaySE(SEmagics5);
	}
	if(GetX>=maxx){
		SetAngle(180-GetAngle);
		SetX(GetX-GetSpeed);
		SetSpeed(0);
		PlaySE(SEmagics5);
	}
	if(GetY<=miny){
		SetAngle(-GetAngle);
		SetY(GetY+GetSpeed);
		SetSpeed(0);
		PlaySE(SEmagics5);
	}
	if(GetY>=maxy){
		SetAngle(-GetAngle);
		SetY(GetY-GetSpeed);
		SetSpeed(0);
		PlaySE(SEmagics5);
	}
}

if(GetSpeed<speed){ SetSpeed(GetSpeed+0.075); }

	if(scale<maxscale && scalespeed==1){ scale+=1/15; }
	if(scale<maxscale && scalespeed==2){ scale+=1/120; }
	if(length(bullet1)<=0){ fade-=1/60; SetSpeed(0); }

if(fade<=0){
	while(length(bullet1)>0){
	Obj_Delete(bullet1[0]);
	bullet1=erase(bullet1,0);
	}
}


if(fade<=0){ VanishEnemy; }

SetShotColor(255,255,255);

time++;
frame++;
}

@DrawLoop{
	if(fade>0){
	SetGraphicScale(0.6*scale,0.6*scale);
	SetTexture(GRenemy);
	if(direction==1){ SetGraphicAngle(0,0,time*spinspeed); }
	if(direction==2){ SetGraphicAngle(0,0,-(time*spinspeed)); }
	if(circlecolor==1){ SetColor(80*fade,130*fade,30*fade); }
	if(circlecolor==2){ SetColor((100+30*cos((frame/2)+0)*fade),(100+30*cos((frame/2)+120)*fade),(100+30*cos((frame/2)+240))*fade); }
	SetRenderState(ADD);
	SetAlpha(255*fade);
	SetGraphicRect(0,0,200,200);
	DrawGraphic(GetX,GetY);
	}
}

@Finalize{
}

}