//Uses 5 elements

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Fairy3-15.png");
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.75;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

let deathtime=0;
let dead=0;

let angle=rand(0,360);
SetAngle(90);
SetSpeed(4);

@Initialize{
	LoadGraphic("\script\Images\Enemies\Fairy3-15.png");
	LoadSE("script\SoundEffects\fire1.wav");
	LoadSE("script\SoundEffects\laserm2.wav");
	LoadSE("script\SoundEffects\shotm7.wav");
	LoadSE("script\SoundEffects\shotb7.wav");
	LoadSE("script\SoundEffects\shots6.wav");

	SetInvincibility(120);
	SetLife(280);
	SetDamageRate(10,3); 
	SetScore(100000);
	SetShotColor(255,255,255);

SetCommonData("IncreasePhase",0);
SetCommonData("EnemyDead",0);
}

@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)){
	if(GetLife>=100 && dead==0){
		SetCollisionA(GetX,GetY,32*scale);
		SetCollisionB(GetX,GetY,32*scale);
	}
} //Onscreen

if(time==135){
let color=0;
let angle=rand(0,360);
	loop(5){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"810a.txt",GetX,GetY,0,0,[color,angle]);
	color++;
	angle+=360/5;
	}
}


if(time<90){ SetSpeed(GetSpeed-(4/90)); }
if(time==45){ SetColor(255,255,128); Concentration01(90); SetColor(255,255,255); }
if(time>=1500){ SetSpeed(GetSpeed-(4/90)); SetCommonData("EnemyDead",1); }
if(time==1650 && dead==0){ VanishEnemy; }


if(GetLife<100 && deathtime<25){
if(deathtime==0){ PlaySE(SEdeath); }
	loop(4){
	let itemradius=rand(deathtime*0.1,deathtime*5);
	let itemangle=rand(0,360);
	CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+itemradius*cos(itemangle),GetY+itemradius*sin(itemangle),0,0,0);
	itemangle+=360/100;
	}
}
if(deathtime==25){
let itemangle=rand(0,360);
	loop(5){
	CreateEnemyFromFile("script\Functions\itembigpower.txt",GetX+40*cos(itemangle),GetY+40*sin(itemangle),0,0,0); itemangle+=360/3;
	}
CreateEnemyFromFile("script\Functions\itemlife.txt",GetX,GetY,0,0,0);
}

if(GetLife<100){ dead=1; deathtime++; SetCommonData("EnemyDead",1); }

if(deathtime==300){ VanishEnemy; }


SetCommonData("Boss1X",GetX);
SetCommonData("Boss1Y",GetY);

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

}

@DrawLoop{
if(GetLife>100 && dead==0){
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);
} //Alive
}

@Finalize{
SetCommonData("IncreasePhase",1);
SetCommonData("NightmareSpellcards",1);
}

}