//Shoots a circle of flames

script_enemy_main{

let angle=rand(0,360);

let GRenemy=("\script\Images\Enemies\Fairy2-10.png");
let SEshotm1=("script\SoundEffects\shotm1.wav");

let SEdeath=("script\SoundEffects\enemydeath1.wav");
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let startx=GetX; let starty=GetY;
let frame=0; let time=0; let animation=0;
let ani=6;
let scale=0;
let shots=0;
let shotcolor=3; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

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

@Initialize{
	LoadGraphic("\script\Images\Enemies\Fairy2-10.png");
	LoadSE("script\SoundEffects\shotm1.wav");

	SetInvincibility(60);
	SetLife(17);
	SetDamageRate(10,3); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

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

if((GetX>minx && GetX<maxx) && (GetY>miny && GetY<maxy)){

SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);



if(shots<6 && time%5==0 && time>=60){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"603a.txt",GetX,GetY,0,0,[angle,type]);
	angle+=360/6;
	shots++;
}


} //Onscreen


if(scale<0.75){ scale+=0.75/45; }
if(time>=150){ SetAngle(270); SetSpeed(1); }


oldX=GetX;
oldY=GetY;
frame++;
time++;
animation++;
if(animation>=ani*6){ animation=0; }
if(GetTimeOfInvincibility<25 && invincible>0){ invincible=GetTimeOfInvincibility*5; }

}

@DrawLoop{
let side=0;
	SetTexture(GRenemy);
		if(oldX<GetX || oldX>GetX){ side=128; }
		if(animation>=ani*0 && animation<ani*1){ SetGraphicRect(1,side,256,128+side); }
		if(animation>=ani*1 && animation<ani*2){ SetGraphicRect(257,side,512,128+side); }
		if(animation>=ani*2 && animation<ani*3){ SetGraphicRect(513,side,768,128+side); }
		if(animation>=ani*3 && animation<ani*4){ SetGraphicRect(769,side,1024,128+side); }
		if(animation>=ani*4 && animation<ani*5){ SetGraphicRect(513,side,768,128+side); }
		if(animation>=ani*5 && animation<ani*6){ SetGraphicRect(257,side,512,128+side); }
	SetGraphicAngle(0,0,0);
	if(oldX<GetX){ SetGraphicAngle(180,0,0); }
	SetGraphicScale(scale,scale);
	SetColor(255-invincible,255-invincible,255);
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
	loop(3){ CreateEnemyFromFile("script\Functions\itemscore.txt",GetX+rand(-40,40),GetY+rand(-50,50),0,0,0); }
	loop(5){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-50,50),0,0,0); }
	loop(2){ CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-40,40),GetY+rand(-50,50),0,0,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
DeleteEnemyShotInCircle(SHOT,GetX,GetY,50);
}
}

}