//V-Shaped

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Birds1.png");
let SEshotm1=("script\SoundEffects\shotm1.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,10); let time=0; let animation=0;
let ani=4; let color=2;
let scale=1;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

SetSpeed(4);
if(startx<cx){ SetAngle(45); }
if(startx>cx){ SetAngle(135); }

@Initialize{
	LoadGraphic("\script\Images\Enemies\Birds1.png");
	LoadSE("script\SoundEffects\shotm1.wav");
	LoadSE("script\SoundEffects\enemydeath1.wav");
	
	SetInvincibility(25);
	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(frame%30==0 && time>=10 && shots<3){
let angle1=GetAngleToPlayer;
let speed1=5;
let shotcolor=12;
	loop(2){
		loop(8){
		let angle2=0;
		let speed2=speed1;
		CreateShot01(GetX,GetY,speed2,angle1,96+shotcolor,0);
			loop(3){
			angle2+=3;
			speed2-=(speed1/10);
			CreateShot01(GetX,GetY,speed2,angle1+angle2,96+shotcolor,0);
			CreateShot01(GetX,GetY,speed2,angle1-angle2,96+shotcolor,0);
			}
		angle1+=360/8;
		}
	speed1=2;
	shotcolor+=11;
	}
PlaySE(SEshotm1);
shots++;
}



if(startx<cx){ SetAngle(GetAngle-0.6); }
if(startx>cx){ SetAngle(GetAngle+0.6); }


oldX=GetX;
oldY=GetY;
frame++;
time++;
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(0,color,80,80+color); }
		if(animation>=ani*1 && animation<ani*2){ SetGraphicRect(80,color,160,80+color); }
		if(animation>=ani*2 && animation<ani*3){ SetGraphicRect(160,color,240,80+color); }
		if(animation>=ani*3 && animation<ani*4){ SetGraphicRect(80,color,160,80+color); }
	SetGraphicAngle(0,0,GetAngle+180);
	if(oldX<GetX){ SetGraphicAngle(180,0,-GetAngle); }
	SetGraphicScale(scale,scale);
	SetColor(255-invincible,255-invincible,255);
	DrawGraphic(GetX,GetY);
}

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

}