//Shoots vertically

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Ghosts.png");
let SEshots6=("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=rand_int(0,30); let time=0; let animation=0;
let ani=4;
let scale=1;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

let angle=0;
let type=GetArgument;
if(type==1){ scale=1; }
if(type==2){ scale=1.25; }

if(GetX<cx){ SetAngle(0); }
if(GetX>cx){ SetAngle(180); }
SetSpeed(3);

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

	SetInvincibility(30);
	if(type==1){ SetLife(7); }
	if(type==2){ SetLife(9); }
	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(frame%40==0 && (angle<60 || angle>120)){
	CreateShot02(GetX,GetY,1,90+rand(-3,3),0.05,2.5,106,0);
	CreateShot02(GetX,GetY,1,270+rand(-3,3),0.05,2.5,105,0);
	}
	if(time%15==0){ PlaySE(SEshots6); }
} //Easy

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

if(GetCommonData("Difficulty")==2){
	if(frame%30==0 && (angle<60 || angle>120)){
	CreateShot02(GetX,GetY,1,90+rand(-3,3),0.05,3.5,106,0);
	CreateShot02(GetX,GetY,1,270+rand(-3,3),0.05,3.5,105,0);
	}
	if(time%15==0){ PlaySE(SEshots6); }
} //Normal

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

if(GetCommonData("Difficulty")==3){
	if(frame%25==0 && (angle<60 || angle>120)){
	CreateShot02(GetX,GetY,1,90+rand(-3,3),0.1,4.25,106,0);
	CreateShot02(GetX,GetY,1,270+rand(-3,3),0.1,4.25,105,0);
	}
	if(time%15==0){ PlaySE(SEshots6); }
} //Hard

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

if(GetCommonData("Difficulty")==4){
	if(frame%20==0 && (angle<60 || angle>120)){
	CreateShot02(GetX,GetY,1,90+rand(-3,3),0.1,5,106,0);
	CreateShot02(GetX,GetY,1,270+rand(-3,3),0.1,5,105,0);
	}
	if(time%15==0){ PlaySE(SEshots6); }
} //Lunatic
} //Onscreen

if(type==2){
	if(startx<cx && GetX>=cx+100 && angle<90){ angle+=2; SetAngle(0+angle); }
	if(startx>cx && GetX<=cx-100 && angle<90){ angle+=2; SetAngle(180-angle); }

	if(startx<cx && GetX>=cx+100 && GetY>cy+80 && angle<180){ angle+=2;SetAngle(0+angle); }
	if(startx>cx && GetX<=cx-100 && GetY>cy+80 && angle<180){ angle+=2; SetAngle(180-angle); }
}


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=32; }
		SetGraphicRect(256+side,212,288+side,244);
	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(type==1){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
	if(type==2){ loop(2){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); } }
	CreateEnemyFromFile("script\Functions\itemscore.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0);
	CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0);
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}