public bool withinBounds(iCollidable obj) { Vector2 objPosition = obj.Position(); return(objPosition.X >= Bounds.X && objPosition.X <= Bounds.X + Bounds.Width && objPosition.Y >= Bounds.Y && objPosition.Y <= Bounds.Y + Bounds.Height); }
public Cell[] getNearCells(iCollidable obj) { List <Cell> nearCells = new List <Cell>(); for (int i = 0; i < cells.GetLength(0); i++) { for (int j = 0; j < cells.GetLength(1); j++) { if (cells[i, j].withinBounds(obj)) { nearCells.Add(cells[i, j]); if (i > 0) { nearCells.Add(cells[i - 1, j]); if (j > 0) { nearCells.Add(cells[i, j - 1]); nearCells.Add(cells[i - 1, j - 1]); } if (j < cells.GetLength(1) - 1) { nearCells.Add(cells[i, j + 1]); nearCells.Add(cells[i - 1, j + 1]); } } if (i < cells.GetLength(0) - 1) { nearCells.Add(cells[i + 1, j]); if (j > 0) { nearCells.Add(cells[i + 1, j - 1]); } if (j < cells.GetLength(1) - 1) { nearCells.Add(cells[i + 1, j + 1]); } } } } } return(nearCells.ToArray()); }