//Shoots a flower.

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Fairy3-15.png");
let SEshotb6=("script\SoundEffects\shotb6.wav");
let SEshots3=("script\SoundEffects\shots3.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=6;
let scale=0.75;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

let angle2=rand(0,360);
SetSpeed(GetArgument[0]);
SetAngle(90);

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

	SetInvincibility(40);
	SetLife(50);
	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);

SetShotAutoDeleteClip(300,300,300,10);

if(GetCommonData("Difficulty")==1){
	if(time==60){
	let shot1=0;
	let angle=GetAngleToPlayer;
	let speed=5;
		loop(4){
			loop(10){
			CreateShotA(shot1,GetX,GetY,0);
			SetShotDataA(shot1,0,speed,angle,0,-speed/60,0,75);
			SetShotDataA(shot1,60,NULL,GetAngleToPlayer,0,0.01,2,75);
			FireShot(shot1);
			angle+=360/10;
			}
		speed-=1;
		angle+=360/20;
		}
	PlaySE(SEshotb6);
	}

	if(time>=120 && time%8==0 && shots<12){
	let shot1=0;
		loop(4){
		if(GetArgument[1]==0){ CreateShot02(GetX,GetY,5,angle2,-0.08,1,85,0); }
		if(GetArgument[1]==1){ CreateShot02(GetX,GetY,5,angle2,-0.08,1,92,0); }
		angle2+=360/4;
		}
	if(GetArgument[1]==0){ angle2-=22; }
	if(GetArgument[1]==1){ angle2+=22; }
	PlaySE(SEshots3);
	shots++;
	}
} //Easy

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

if(GetCommonData("Difficulty")==2){
	if(time==60){
	let shot1=0;
	let angle=GetAngleToPlayer;
	let speed=6;
		loop(5){
			loop(12){
			CreateShotA(shot1,GetX,GetY,0);
			SetShotDataA(shot1,0,speed,angle,0,-speed/60,0,75);
			SetShotDataA(shot1,60,NULL,GetAngleToPlayer,0,0.01,2,75);
			FireShot(shot1);
			angle+=360/12;
			}
		speed-=1;
		angle+=360/24;
		}
	CreateShotA(shot1,GetX,GetY,0);
	SetShotDataA(shot1,0,0,GetAngleToPlayer,0,0,0,98);
	SetShotDataA(shot1,60,NULL,GetAngleToPlayer,0,0.01,2,98);
	FireShot(shot1);
	PlaySE(SEshotb6);
	}

	if(time>=120 && time%5==0 && shots<16){
	let shot1=0;
		loop(4){
		if(GetArgument[1]==0){ CreateShot02(GetX,GetY,5,angle2,-0.08,1,85,0); }
		if(GetArgument[1]==1){ CreateShot02(GetX,GetY,5,angle2,-0.08,1,92,0); }
		angle2+=360/4;
		}
	if(GetArgument[1]==0){ angle2+=19; }
	if(GetArgument[1]==1){ angle2-=19; }
	PlaySE(SEshots3);
	shots++;
	}
} //Normal

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

if(GetCommonData("Difficulty")==3){
	if(time==60){
	let shot1=0;
	let angle=GetAngleToPlayer;
	let speed=7;
		loop(6){
			loop(14){
			CreateShotA(shot1,GetX,GetY,0);
			SetShotDataA(shot1,0,speed,angle,0,-speed/60,0,75);
			SetShotDataA(shot1,60,NULL,GetAngleToPlayer,0,0.01,2,75);
			FireShot(shot1);
			angle+=360/14;
			}
		speed-=1;
		angle+=360/28;
		}
	CreateShotA(shot1,GetX,GetY,0);
	SetShotDataA(shot1,0,0,GetAngleToPlayer,0,0,0,98);
	SetShotDataA(shot1,60,NULL,GetAngleToPlayer,0,0.01,2,98);
	FireShot(shot1);
	PlaySE(SEshotb6);
	}

	if(time>=120 && time%5==0 && shots<20){
	let shot1=0;
		loop(5){
		if(GetArgument[1]==0){ CreateShot02(GetX,GetY,5,angle2,-0.08,1,85,0); }
		if(GetArgument[1]==1){ CreateShot02(GetX,GetY,5,angle2,-0.08,1,92,0); }
		angle2+=360/5;
		}
	if(GetArgument[1]==0){ angle2-=16; }
	if(GetArgument[1]==1){ angle2+=16; }
	PlaySE(SEshots3);
	shots++;
	}
} //Hard

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

if(GetCommonData("Difficulty")==4){
	if(time==60){
	let shot1=0;
	let angle=GetAngleToPlayer;
	let speed=9;
		loop(9){
			loop(16){
			CreateShotA(shot1,GetX,GetY,0);
			SetShotDataA(shot1,0,speed,angle,0,-speed/60,0,75);
			SetShotDataA(shot1,60,NULL,GetAngleToPlayer,0,0.01,2,75);
			FireShot(shot1);
			angle+=360/16;
			}
		speed-=0.8;
		angle+=360/32;
		}
	CreateShotA(shot1,GetX,GetY,0);
	SetShotDataA(shot1,0,0,GetAngleToPlayer,0,0,0,98);
	SetShotDataA(shot1,60,NULL,GetAngleToPlayer,0,0.01,2,98);
	FireShot(shot1);
	PlaySE(SEshotb6);
	}

	if(time>=120 && time%5==0 && shots<24){
	let shot1=0;
		loop(6){
		if(GetArgument[1]==0){ CreateShot02(GetX,GetY,5,angle2,-0.08,1,85,0); }
		if(GetArgument[1]==1){ CreateShot02(GetX,GetY,5,angle2,-0.08,1,92,0); }
		angle2+=360/6;
		}
	if(GetArgument[1]==0){ angle2+=13; }
	if(GetArgument[1]==1){ angle2-=13; }
	PlaySE(SEshots3);
	shots++;
	}
} //Lunatic
} //Onscreen


if(time<60){ SetSpeed(GetSpeed-GetArgument[0]/60); }
if(time>=180){ SetSpeed(GetSpeed-(GetArgument[0]/2)/60); }



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

}