script_enemy_main{

let speed=3;
let spin=0;
let itemradius=GetCommonData("ItemRadius");
let homing=0;
let GRitem=("\script\Images\OtherEffects\Items.png");
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let time=0;

let SEextralife=("script\SoundEffects\extralife.wav");

@Initialize{
	SetLife(1);
	SetScore(1);
	
	LoadSE("script\SoundEffects\extralife.wav");
}

@MainLoop{

if(speed>-2.5){ speed-=0.07; }
if(GetY>=500){ VanishEnemy; }

if(OnBomb==false && homing==0){ SetAngle(-90); SetSpeed(speed); }
if(OnBomb==true || GetPlayerY<=GetCommonDataDefault("ItemCollectLine",160) || homing==1){ SetAngle(GetAngleToPlayer); SetSpeed(8); speed=-3; homing=1; }

if(GetCommonData("ItemCollect")==1 || (GetPlayerX>GetX-(itemradius*2) && GetPlayerX<GetX+(itemradius*2) && GetPlayerY>GetY-(itemradius*2) && GetPlayerY<GetY+(itemradius*2) && OnPlayerMissed==false)){
homing=1;
}

if(OnPlayerMissed==true && homing==1){ VanishEnemy; }

if(GetPlayerX>GetX-itemradius && GetPlayerX<GetX+itemradius && GetPlayerY>GetY-itemradius && GetPlayerY<GetY+itemradius && OnPlayerMissed==false){
	ExtendPlayer(1);
	VanishEnemy;
	PlaySE(SEextralife);
}

if(time<45){ spin+=24; }

time++;

}

@DrawLoop{
	SetTexture(GRitem);
	SetGraphicRect(18,43,34,59);
	SetColor(128+127*sin((time*6)+0),128+127*sin((time*6)+120),128+127*sin((time*6)+240));
	SetGraphicAngle(0,0,-spin);
	if(homing==1){ SetGraphicAngle(0,0,GetAngleToPlayer-90); }
	DrawGraphic(GetX,GetY);
}

@Finalize{
}

}