//Leaves behind a spellcircle when killed

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Ghosts.png");
let GRexplosion=("\script\Images\OtherEffects\EnemyDeath.png");

let SEshotb1=("script\SoundEffects\shotb1.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");

let dead=0;
let offscreen=0;

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=4;
let scale=1.5;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

if(startx<cx){ SetAngle(0+GetArgument); }
if(startx>cx){ SetAngle(180+GetArgument); }
SetSpeed(1.5);

@Initialize{
	LoadGraphic("\script\Images\Enemies\Ghosts.png");
	LoadGraphic("\script\Images\OtherEffects\EnemyDeath.png");
	
	LoadSE("script\SoundEffects\shotb1.wav");
	LoadSE("script\SoundEffects\enemydeath1.wav");

	SetInvincibility(20);
	SetLife(15);
	SetDamageRate(10,3); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

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

if((GetX>minx && GetX<maxx) && (GetY>miny && GetY<maxy)){
	SetCollisionA(GetX,GetY,32*scale);
	SetCollisionB(GetX,GetY,32*scale);
}

if(time%25==0 && time>=40){
let angle=rand(0,360);
	loop(5){
	CreateShot02(GetX,GetY,5,angle,-0.1,2.5,123,0);
	angle+=360/5;
	}
PlaySE(SEshotb1);
}


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=32; }
		SetGraphicRect(256+side,212,288+side,244);
	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);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"708a.txt",GetX,GetY,0,0,0);
	let angle=rand(0,360);
		loop(20){
		CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+70*cos(angle),GetY+70*sin(angle),0,0,0);
		angle+=360/20;
		}
	let angle=rand(0,360);
		loop(8){
		CreateEnemyFromFile("script\Functions\itempower.txt",GetX+40*cos(angle),GetY+40*sin(angle),0,0,0);
		angle+=360/8;
		}
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}