//Drops tunnels

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Ghosts.png");
let SEshotm6=("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=6;
let scale=0.75;
let shots=0;
let shotcolor=3; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

SetAngle(90+rand(-10,10));
SetSpeed(3);

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

	SetInvincibility(30);
	SetLife(15);
	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(time%15==0 && shots<12){
		CreateShot12(GetX,GetY,1,-2,-0.01,0.03,0,4,67,0);
		CreateShot12(GetX,GetY,-1,-2,0.01,0.03,0,4,67,0);
	shots+=1;
	}
if(time%20==0 && shots<12){ PlaySE(SEshotm6); }
} //Easy

if(GetCommonData("Difficulty")==2){
	if(time%12==0 && shots<15){
		CreateShot12(GetX,GetY,1,-2,-0.01,0.04,0,4,67,0);
		CreateShot12(GetX,GetY,-1,-2,0.01,0.04,0,4,67,0);
	shots+=1;
	}
if(time%10==0 && shots<15){ PlaySE(SEshotm6); }
} //Normal

if(GetCommonData("Difficulty")==3){
	if(time%10==0 && shots<18){
		CreateShot12(GetX,GetY,1,-2,-0.01,0.05,0,5,67,0);
		CreateShot12(GetX,GetY,-1,-2,0.01,0.05,0,5,67,0);
	shots+=1;
	}
if(time%10==0 && shots<18){ PlaySE(SEshotm6); }
} //Hard

if(GetCommonData("Difficulty")==4){
	if(time%8==0 && shots<22){
		CreateShot12(GetX,GetY,1,-2,-0.01,0.06,0,6,67,0);
		CreateShot12(GetX,GetY,-1,-2,0.01,0.06,0,6,67,0);
	shots+=1;
	}
if(time%10==0 && shots<22){ PlaySE(SEshotm6); }
} //Lunatic

} //Onscreen

if(GetSpeed>1){ SetSpeed(GetSpeed-0.01); }
if(time>=60 && time<120 && startx<cx){ SetAngle(GetAngle+1); }
if(time>=60 && time<120 && 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{
	SetTexture(GRenemy);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(1,1);
	SetGraphicRect(80,211,160,290);
	if(GetSpeed>-2.2 && GetSpeed<2.2){ SetGraphicRect(0,211,79,290);}
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
	CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0);
	loop(2){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}