script_enemy_main{

let shot1=0;
let bullet1=[];
let timer1=[];
let phase1=[];
let bounce1=[];
let direction1=[];

let type=GetArgument[0];
let color=GetArgument[1];

let realityfield=GetCommonData("RealityField");
let fade=1;

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

SetSpeed(GetArgument[2]);
SetAngle(GetArgument[3]);

let GRfamiliar=("\script\Images\OtherEffects\SpellCircle1b.png");

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

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

if(GetSpeed>0){ SetSpeed(GetSpeed-0.05); }
if(GetSpeed<0){ SetSpeed(0); }


if(time==90){
let angle=rand(0,360);
		loop(50){
		shot1=(Obj_Create(OBJ_SHOT));
		Obj_SetPosition(shot1,GetX,GetY);
		Obj_SetAngle(shot1,angle);
		Obj_SetSpeed(shot1,0.8);
		ObjShot_SetBombResist(shot1,true);
		ObjShot_SetGraphic(shot1,color);
		bullet1=bullet1~[shot1];
		timer1=timer1~[shot1];
		timer1[length(bullet1)-1]=0;
		phase1=phase1~[shot1];
		phase1[length(bullet1)-1]=type;
		angle+=360/50;
		}
}

realityfield=GetCommonData("RealityField");

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); phase1=erase(phase1,i);
	i--;
	}
	else{
		if((((GetPlayerX-Obj_GetX(bullet1[i]))^2+(GetPlayerY-Obj_GetY(bullet1[i]))^2)^0.5)<realityfield && phase1[i]%2!=0){
		Obj_SetAlpha(bullet1[i],100);
		Obj_SetCollisionToPlayer(bullet1[i],false);
		}
		else{
		Obj_SetAlpha(bullet1[i],255);
		Obj_SetCollisionToPlayer(bullet1[i],true);
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(time>=90 && fade>0){ fade-=0.01; }


time++;
frame++;
}

@DrawLoop{
	SetGraphicScale(0.2*fade,0.2*fade);
	SetTexture(GRfamiliar);
	SetGraphicAngle(0,0,time*2);
	if(color==109){ SetColor(255*fade,0,0); }
	if(color==113){ SetColor(0,255*fade,0); }
	if(color==116){ SetColor(0,0,255*fade); }
	SetRenderState(ADD);
	SetAlpha(100);
	SetGraphicRect(0,0,200,200);
	DrawGraphic(GetX,GetY);
}

@Finalize{
}

}