task DrawEnemy(id, num){
let x=0; let y=num; let move="none";
ObjPrim_SetTexture(id, GetCurrentScriptDirectory~"/img/enemy.png");
CheckMovement;
	task CheckMovement{
	let t=0; let startmove=0;
	while(!Obj_IsDeleted(id)){
	ObjSprite2D_SetSourceRect(id, x*32, y*32, x*32+32, y*32+32);
	ObjSprite2D_SetDestCenter(id);
	t++; if (t%3==0){
	if (move=="none"){if (startmove==1){x--; if (x<0||x==3){startmove=0; x=0; y=num;}}
	x++; if (x>2){x=0;}}
	if (move=="left"){if (startmove==0){x=0; startmove=1;} y=num+1; x++; if (x>3){x=3;}}
	if (move=="right"){if (startmove==0){x=4; startmove=1;} y=num+1; x++; if (x>7){x=7;}}
	}
	if (ObjMove_GetSpeed(id)>0&&ObjMove_GetAngle(id)>-90&&ObjMove_GetAngle(id)<90){move="right";}
	if (ObjMove_GetSpeed(id)>0&&ObjMove_GetAngle(id)>90&&ObjMove_GetAngle(id)<270){move="left";}
	if (ObjMove_GetSpeed(id)==0||ObjMove_GetAngle(id)==90||ObjMove_GetAngle(id)==-90){move="none";}
	yield;}
	}
}