script_enemy_main{

let playedse1=0;
let playedse2=0;

let radius=0;
let ypos=0;
let size=0;

let bursttime=0;
let absorb=0;
let oldabsorb=0;
let oldlife=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 SEreflect1=("\script\SoundEffects\reflect1.wav");
let SEreflect2=("\script\SoundEffects\reflect2.wav");
let SEmagicb2=("\script\SoundEffects\magicb2.wav");

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

@Initialize{
	LoadSE("\script\SoundEffects\reflect1.wav");
	LoadSE("\script\SoundEffects\reflect2.wav");
	LoadSE("\script\SoundEffects\magicb2.wav");

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

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

if(bursttime==0){
	SetCollisionA(GetX,GetY,60);
	SetCollisionB(GetX,GetY,16);
}
if(bursttime>0){ bursttime--; }

SetX(cx+radius*cos(time));
SetY((miny+80+ypos)+20*sin(time*1.23));

if(radius<100){ radius+=0.3; }
if(ypos<130){ ypos+=0.6; }
if(size<1){ size+=0.01; }

absorb=GetCommonDataDefault("Absorb",0);
if(absorb>oldabsorb){
	SetColor(70,35,0);
	Concentration01(30);
	SetColor(255,255,255);
if(playedse1==0 && absorb<180 && bursttime==0){ PlaySE(SEreflect2); playedse1=rand_int(6,9); }
if(playedse2==0 && absorb>=180 && bursttime==0){ PlaySE(SEreflect1); playedse2=rand_int(6,9); }
}
if(oldlife>GetLife){
	SetColor(70,35,0);
	Concentration01(30);
	SetColor(255,255,255);
SetCommonData("Absorb",GetCommonDataDefault("Absorb",0)+0.8);
if(playedse1==0 && absorb<180 && bursttime==0){ PlaySE(SEreflect2); playedse1=rand_int(6,9); }
if(playedse2==0 && absorb>=180 && bursttime==0){ PlaySE(SEreflect1); playedse2=rand_int(6,9); }
}
if(playedse1>0){ playedse1--; }
if(playedse2>0){ playedse2--; }

if(absorb>=255){
	SetCommonData("Absorb",0);
	SetCommonData("ResetAbsorb",1);
	Explosion01(GetX,GetY,10,0.3,20);
	PlaySE(SEmagicb2);
	bursttime=150;
	size=0;
}


oldlife=GetLife;
oldabsorb=GetCommonDataDefault("Absorb",0);

SetCommonData("EnemyX",GetX);
SetCommonData("EnemyY",GetY);


time++;
frame++;

}

@DrawLoop{
	SetGraphicScale(0.5*size,0.5*size);
	SetTexture(GRfamiliar);
	SetGraphicAngle(0,0,time*2);
	SetColor(255,128+(absorb/2),absorb);
	SetRenderState(ADD);
	SetAlpha(100);
	SetGraphicRect(0,0,200,200);
	DrawGraphic(GetX,GetY);
}

@Finalize{
}

}