//Aims at the player and changes shot speed either faster or slower

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Fairy1-07.png");
let SEshot1=("script\SoundEffects\shots6.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=4;
let scale=0.5;
let shots=0;
let oldX=0; let oldY=0;
let invincible=125;

let speed=0;
let angle=0;

if(startx<cx){ SetAngle(0+rand(0,20)); }
if(startx>cx){ SetAngle(180-rand(0,20)); }
SetSpeed(3);

@Initialize{
	LoadGraphic("\script\Images\Enemies\Fairy1-07.png");
	LoadSE("script\SoundEffects\shots6.wav");

	SetInvincibility(20);
	SetLife(8);
	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(GetCommonData("Difficulty")==1){
	if(shots==0){ speed=1.5; }
	if(time%25==0 && shots<10){
		if(GetArgument==1){
		CreateShot01(GetX,GetY,speed,GetAngleToPlayer,34,0);
		}
		if(GetArgument==2){
		CreateShot01(GetX,GetY,5-speed,GetAngleToPlayer,33,0);
		}
	if(speed>0.5){ speed-=0.04; }
	shots++;
	}
	if(time%25==0 && shots<10){ PlaySE(SEshot1); }
} //Easy

if(GetCommonData("Difficulty")==2){
	if(shots==0){ speed=2.5; }
	if(time%15==0 && shots<10){
		if(GetArgument==1){
		CreateShot01(GetX,GetY,speed,GetAngleToPlayer,34,0);
		}
		if(GetArgument==2){
		CreateShot01(GetX,GetY,5-speed,GetAngleToPlayer,33,0);
		}
	if(speed>0.5){ speed-=0.05; }
	shots++;
	}
	if(time%15==0 && shots<10){ PlaySE(SEshot1); }
} //Normal

if(GetCommonData("Difficulty")==3){
	if(shots==0){ speed=2.5; }
	if(time%10==0 && shots<24){
	let angle=GetAngleToPlayer-55;
		if(GetArgument==1){
			loop(3){
			CreateShot01(GetX,GetY,speed,angle+rand(-3,3),34,0);
			angle+=55;
			}
		CreateShot01(GetX,GetY,speed,angle+rand(-60,60),21,0);
		}
		if(GetArgument==2){
			loop(3){
			CreateShot01(GetX,GetY,5-speed,angle+rand(-3,3),33,0);
			angle+=55;
			}
		CreateShot01(GetX,GetY,5-speed,angle+rand(-60,60),22,0);
		}
	if(speed>0.5){ speed-=0.08; }
	shots++;
	}
	if(time%10==0 && shots<20){ PlaySE(SEshot1); }
} //Hard

if(GetCommonData("Difficulty")==4){
	if(shots==0){ speed=4; }
	if(time%5==0 && shots<40){
	let angle=GetAngleToPlayer-40;
		if(GetArgument==1){
			loop(3){
			CreateShot01(GetX,GetY,speed,angle+rand(-5,5),34,0);
			angle+=40;
			}
		CreateShot01(GetX,GetY,speed,angle+rand(-60,60),21,0);
		}
		if(GetArgument==2){
			loop(3){
			CreateShot01(GetX,GetY,5-speed,angle+rand(-5,5),33,0);

			angle+=40;
			}
		CreateShot01(GetX,GetY,5-speed,angle+rand(-60,60),22,0);
		}
	if(speed>0.5){ speed-=0.1; }
	shots++;
	}
	if(time%10==0 && shots<40){ PlaySE(SEshot1); }
} //Lunatic
} //Onscreen


if(time<90){ SetSpeed(GetSpeed-0.01); }
if(time>=90){ SetSpeed(GetSpeed+0.03); }
if(time>=90 && startx<cx){ SetAngle(GetAngle-1); }
if(time>=90 && startx>cx){ SetAngle(GetAngle+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);
	CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0);
	CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0);
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}