function findCloestFood(x, y){
  var distance=1000000, xDiff, yDiff, x ,y, ind=0, result;
  for(i=0; i<foodArray.length;i++){
    xDiff = x - foodArray[i][0];
    yDiff = y - foodArray[i][1];
    temp = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
    if (temp < distance){
      distance = temp;
      ind = i;
    }
  }
  result = [foodArray[ind][0], foodArray[ind][1], ind];
  return result;
}
/*------------------------------------
      Find the closest food fod bug.
--------------------------------------*/
Find the closest food fod bug.
Find the closest food fod bug .
function findCloestFood(x, y){
  var distance=1000000, xDiff, yDiff, x ,y, ind=0, result;
  for(i=0; i<foodArray.length;i++){
    xDiff = x - foodArray[i][0];
    yDiff = y - foodArray[i][1];
    temp = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
    if (temp < distance){
      distance = temp;
      ind = i;
    }
  }
  result = [foodArray[ind][0], foodArray[ind][1], ind];
  return result;
}
function findCloestFood ( x , y ) { var distance = 1000000 , xDiff , yDiff , x , y , ind = 0 , result ; for ( i = 0 ; i < foodArray . length ; i ++ ) { xDiff = x - foodArray [ i ] [ 0 ] ; yDiff = y - foodArray [ i ] [ 1 ] ; temp = Math . sqrt ( xDiff * xDiff + yDiff * yDiff ) ; if ( temp < distance ) { distance = temp ; ind = i ; } } result = [ foodArray [ ind ] [ 0 ] , foodArray [ ind ] [ 1 ] , ind ] ; return result ; }
Find the closest food fod bug.
Find the closest food fod bug .