/* * Returns all of the Bubbles which are in the immediate neighborhoud of a given location, including the bubble * in that particular location * Returns null if there is no bubble in the current location * @param {Vector2} location. Location of the matrix that we want to obtain the neighbours of */ public ArrayList neighbours(Vector2 location){ int row = (int)location.x; int column = (int)location.y; ArrayList _neigbours = new ArrayList(); if (row < 0 || row > this._rows -1 || column < 0 || column > this._columns -1) throw new System.ArgumentException("Looking for neighbors of an invalid location"); if (this._bubbleMatrix[row, column] != null){ _neigbours.AddNotNull(this._bubbleMatrix[row,column]); // Left and right neighbours if (column > 0) _neigbours.AddNotNull(this._bubbleMatrix[row,column -1]); if (column < this._columns-1) _neigbours.AddNotNull(this._bubbleMatrix[row,column+1]); // higher and lower neighbours bool isRowEven = row % 2 == 0; if ((isBaselineAlignedLeft && isRowEven) || (!isBaselineAlignedLeft && !isRowEven) ){ if (row > 0){ if (column > 0) _neigbours.AddNotNull(this._bubbleMatrix[row-1, column-1]); _neigbours.AddNotNull(this._bubbleMatrix[row-1, column]); } if (row < this._rows -1){ if (column > 0) _neigbours.AddNotNull(this._bubbleMatrix[row+1, column-1]); _neigbours.AddNotNull(this._bubbleMatrix[row +1, column]); } } else{ if (row > 0){ _neigbours.AddNotNull(this._bubbleMatrix[row-1, column]); if (column < this._columns - 1) _neigbours.AddNotNull(this._bubbleMatrix[row-1, column+1]); } if (row < this._rows - 1){ _neigbours.AddNotNull(this._bubbleMatrix[row+1, column]); if (column < this._columns - 1) _neigbours.AddNotNull(this._bubbleMatrix[row+1, column+1]); } } return _neigbours; } return null; }