//Shoots a bullet in multiple directons that leaves a trail.

script_enemy_main{

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

let curvedirection=GetArgument[2];
let shoottime=GetArgument[3];

if(GetX>minx && GetX<maxx){
	SetSpeed(2);
	SetAngle(90);
}
if(GetX<minx){
	SetSpeed(1.5);
	SetAngle(0);
}
if(GetX>maxx){
	SetSpeed(1.5);
	SetAngle(180);
}

@Initialize{
	LoadGraphic("\script\Images\Enemies\Fairy3-15.png");
	LoadSE("script\SoundEffects\shotm3.wav");

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

@MainLoop{

SetShotAutoDeleteClip(32,32,32,32);

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(time==shoottime){
	let angle=atan2(GetArgument[1]-GetY,GetArgument[0]-GetX);
		loop(2){
		let shot1=0;
		let shot2=1;
		let delay=1;
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,2,angle,0,0,0,48+GetArgument[4]);
		let angle2=angle;
			loop(20){
			SetShotColor(255-shots,255-shots,255-shots);
			CreateShotA(shot2,0,0,15);
			SetShotDataA(shot2,0,0,angle2,0,0,0,48+GetArgument[4]);
			SetShotDataA(shot2,60,0,angle2,0,0.015,1,48+GetArgument[4]);
			AddShot(delay,shot1,shot2,0);
			delay+=12;
			shots+=2;
			if(curvedirection==0){ angle2+=24; }
			if(curvedirection==1){ angle2-=24; }
			}
		SetShotColor(255,255,255);
		shots=0;
		angle+=360/2;
		FireShot(shot1);
		}
	PlaySE(SEshotm3);
	}
} //Easy

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

if(GetCommonData("Difficulty")==2){
	if(time==shoottime){
	let angle=atan2(GetArgument[1]-GetY,GetArgument[0]-GetX);
		loop(2){
		let shot1=0;
		let shot2=1;
		let delay=1;
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,3,angle,0,0,0,48+GetArgument[4]);
		let angle2=angle;
			loop(24){
			SetShotColor(255-shots,255-shots,255-shots);
			CreateShotA(shot2,0,0,15);
			SetShotDataA(shot2,0,0,angle2,0,0,0,48+GetArgument[4]);
			SetShotDataA(shot2,60,0,angle2,0,0.015,1.25,48+GetArgument[4]);
			AddShot(delay,shot1,shot2,0);
			delay+=9;
			shots+=2;
			if(curvedirection==0){ angle2+=24; }
			if(curvedirection==1){ angle2-=24; }
			}
		SetShotColor(255,255,255);
		shots=0;
		angle+=360/2;
		FireShot(shot1);
		}
	PlaySE(SEshotm3);
	}
} // Normal

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

if(GetCommonData("Difficulty")==3){
	if(time==shoottime){
	let angle=atan2(GetArgument[1]-GetY,GetArgument[0]-GetX);
		loop(4){
		let shot1=0;
		let shot2=1;
		let delay=1;
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,3,angle,0,0,0,48+GetArgument[4]);
		let angle2=angle;
			loop(45){
			SetShotColor(255-shots,255-shots,255-shots);
			CreateShotA(shot2,0,0,15);
			SetShotDataA(shot2,0,0,angle2,0,0,0,48+GetArgument[4]);
			SetShotDataA(shot2,60,0,angle2,0,0.015,1.25,48+GetArgument[4]);
			AddShot(delay,shot1,shot2,0);
			delay+=5;
			shots+=2;
			if(curvedirection==0){ angle2+=24; }
			if(curvedirection==1){ angle2-=24; }
			}
		SetShotColor(255,255,255);
		shots=0;
		angle+=360/4;
		FireShot(shot1);
		}
	PlaySE(SEshotm3);
	}
} // Hard

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

if(GetCommonData("Difficulty")==4){
	if(time==shoottime){
	let angle=atan2(GetArgument[1]-GetY,GetArgument[0]-GetX);
		loop(4){
		let shot1=0;
		let shot2=1;
		let delay=1;
		CreateShotA(shot1,GetX,GetY,0);
		SetShotDataA(shot1,0,3.5,angle,0,0,0,48+GetArgument[4]);
		let angle2=angle;
			loop(60){
			SetShotColor(255-shots,255-shots,255-shots);
			CreateShotA(shot2,0,0,15);
			SetShotDataA(shot2,0,0,angle2,0,0,0,48+GetArgument[4]);
			SetShotDataA(shot2,60,0,angle2,0,0.015,1.5,48+GetArgument[4]);
			AddShot(delay,shot1,shot2,0);
			delay+=3;
			shots+=2;
			if(curvedirection==0){ angle2+=24; }
			if(curvedirection==1){ angle2-=24; }
			}
		SetShotColor(255,255,255);
		shots=0;
		angle+=360/4;
		FireShot(shot1);
		}
	PlaySE(SEshotm3);
	}
} // Lunatic
} // OnScreen

if(startx<cx && time>=60){ SetAngle(GetAngle+1.5); }
if(startx>=cx && time>=60){ SetAngle(GetAngle-1.5); }
if(time>=60 && startx>minx && startx<maxx){ SetSpeed(GetSpeed+0.02); }
if(time>=60 && (startx<minx || startx>maxx)){ SetSpeed(GetSpeed+0.01); }


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\itempower.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
	loop(4){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
	loop(3){ CreateEnemyFromFile("script\Functions\itemscore.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
DeleteEnemyShot(CHILD);
}
}

}