PlacementGrid.Closed C# (CSharp) Method

Closed() public method

public Closed ( int r, int c ) : bool
r int
c int
return bool
	public bool Closed(int r, int c) {
		if (r >= 0 && r < height && c >= 0 && c < width)
			return internalCells [CellIndex(r,c)].Closed;
		throw new UnityException ("Cell access out of range.");
	}

Usage Example

コード例 #1
0
	/*
	 * This method returns if the obstacle can be placed at the given cell in the gameworld.
	 * Params - obstacleGrid: the PlacementGrid of the obstacle you are testing
	 * 			cell: the cell to test placement on
	 */
	bool CanPlaceObject(PlacementGrid obstacleGrid, PGridCell cell) {
		// False if grid bounding box goes outside bounds of level
		if (obstacleGrid.Height + cell.Row > levelPGrid.Height
			|| obstacleGrid.Width + cell.Col > levelPGrid.Width)
			return false;
		
		// Go through obstacle's placement grid and make sure that each spot
		// it needs is available, starting at cell
		for (int r = 0; r < obstacleGrid.Height; r++) {
			for (int c = 0; c < obstacleGrid.Width; c++) {
				// If a cell is closed on the obstacle then it is occupied
				// If a cell is closed on the main grid, it is occpupied or adjacent to an occupied spot
				if (obstacleGrid.Closed(r, c)
					&& levelPGrid.Closed(cell.Row + r, cell.Col + c)) {
					return false;
				}
			}
		 }
		return true;
	}