script_enemy_main{

let oldphase=0;
let newphase1=0;
let newphase2=0;
let phase=0;

let damagerate=10;
let radius=0;
let spin=GetArgument[1];
let nr=GetArgument[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=-60; let time=0; let animation=0;
let ani=4;
let scale=0.75;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=140;

let SEshotm1=("script\SoundEffects\shotm1.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");

let GRenemy=("\script\Images\Enemies\Fairy1-08.png");

@Initialize{
	LoadSE("script\SoundEffects\shotm1.wav");
	LoadSE("script\SoundEffects\charge1.wav");

	LoadGraphic("\script\Images\Enemies\Fairy1-08.png");

	SetInvincibility(9999);
	SetLife(80);
	SetDamageRate(damagerate,damagerate); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);
if(GetCommonData("BombOn")==0){ damagerate=10+GetCommonData("FamiliarsDead"); }
if(GetCommonData("BombOn")==1){ damagerate=10; }
SetDamageRate(damagerate,damagerate);

if(GetCommonData("ExtinctionPhase")>oldphase && newphase1==-1){ newphase1=90; }
if(newphase1>0){ newphase1--; }
if(newphase1==0){ oldphase=GetCommonData("ExtinctionPhase"); phase=GetCommonData("ExtinctionPhase"); newphase1=-1; }

if(nr==GetCommonData("ExtinctionPhase")){ SetLife(GetLife-1); }


if(GetCommonData("Difficulty")==1){

if(frame==40){
let size=10;
size+=(phase*3);
let angle=GetAngleToPlayer;
	loop(size){
	let speed=3;
		loop(1+phase){
		CreateShot02(GetX,GetY,speed,angle,0,0,227,0);
		speed+=0.15;
		}
	angle+=360/size;
	PlaySE(SEshotm1);
	}
}
if(frame==50){ frame=0; }

} //Easy

//=================================================

if(GetCommonData("Difficulty")==2){

if(frame==40){
let size=13;
size+=(phase*3);
let angle=GetAngleToPlayer;
	loop(size){
	let speed=3;
		loop(2+phase){
		CreateShot02(GetX,GetY,speed,angle,0,0,227,0);
		speed+=0.2;
		}
	angle+=360/size;
	PlaySE(SEshotm1);
	}
}
if(frame==50){ frame=0; }

} //Normal

//=================================================

if(GetCommonData("Difficulty")==3){

if(frame==40){
let size=17;
size+=(phase*3);
let angle=GetAngleToPlayer;
	loop(size){
	let speed=3;
		loop(3+phase){
		CreateShot02(GetX,GetY,speed,angle,0,0,227,0);
		speed+=0.25;
		}
	angle+=360/size;
	PlaySE(SEshotm1);
	}
}
if(frame==50){ frame=0; }

} //Hard

//=================================================

if(GetCommonData("Difficulty")==4){

if(frame==40){
let size=21;
size+=(phase*3);
let angle=GetAngleToPlayer;
	loop(size){
	let speed=3;
		loop(4+phase){
		CreateShot02(GetX,GetY,speed,angle,0,0,227,0);
		speed+=0.3;
		}
	angle+=360/size;
	PlaySE(SEshotm1);
	}
}
if(frame==50){ frame=0; }

} //Lunatic



oldX=GetX;
oldY=GetY;

if(radius<140){ radius++; }
SetX(cx+radius*cos(spin));
SetY((miny+100)-(radius/2)*sin(spin));
spin+=1+(phase*0.3);


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); }
	if(GetCommonData("Difficulty")==1){
	let angle1=rand(0,360);
		loop(10){
		let angle2=angle1+rand(-10,10);
		let speed=rand(0.8,2.2);
		SetShotColor(255,180,180);
		CreateShot12(GetX,GetY,(speed+(0.5*cos(angle2*2)))*cos(angle2),speed*sin(angle2),-speed/70*cos(angle2),rand(0.01,0.02),(speed/rand(10,40))*cos(angle2),rand(1.1,1.7),191,rand_int(5,15));
		SetShotColor(255,255,255);
		angle1+=360/10;
		}
	}
	if(GetCommonData("Difficulty")==2){
	let angle1=rand(0,360);
		loop(20){
		let angle2=angle1+rand(-10,10);
		let speed=rand(0.8,2.2);
		SetShotColor(255,180,180);
		CreateShot12(GetX,GetY,(speed+(0.5*cos(angle2*2)))*cos(angle2),speed*sin(angle2),-speed/70*cos(angle2),rand(0.01,0.02),(speed/rand(10,40))*cos(angle2),rand(1,1.6),191,rand_int(5,15));
		SetShotColor(255,255,255);
		angle1+=360/20;
		}
	}
	if(GetCommonData("Difficulty")==3){
	let angle1=rand(0,360);
		loop(30){
		let angle2=angle1+rand(-10,10);
		let speed=rand(0.8,2.2);
		SetShotColor(255,180,180);
		CreateShot12(GetX,GetY,(speed+(0.5*cos(angle2*2)))*cos(angle2),speed*sin(angle2),-speed/70*cos(angle2),rand(0.01,0.02),(speed/rand(10,40))*cos(angle2),rand(0.9,1.5),191,rand_int(5,15));
		SetShotColor(255,255,255);
		angle1+=360/30;
		}
	}
	if(GetCommonData("Difficulty")==4){
	let angle1=rand(0,360);
		loop(40){
		let angle2=angle1+rand(-10,10);
		let speed=rand(0.8,2.2);
		SetShotColor(255,180,180);
		CreateShot12(GetX,GetY,(speed+(0.5*cos(angle2*2)))*cos(angle2),speed*sin(angle2),-speed/70*cos(angle2),rand(0.01,0.02),(speed/rand(10,40))*cos(angle2),rand(0.8,1.4),191,rand_int(5,15));
		SetShotColor(255,255,255);
		angle1+=360/40;
		}
	}
}

}