protected void makeEmptyRoom() { // First thing to do is create wall tiles around the border for (int i = 0; i < Globals.ROOM_WIDTH; i++) { // Make a wall along the horizontal edges GameObject wallObj = GameObject.Instantiate(PlayState.instance.wallPrefab) as GameObject; wallObj.transform.parent = PlayState.instance.transform; GridPiece wallPiece = wallObj.GetComponent <GridPiece>(); wallPiece.x = Globals.CELL_SIZE * i + Globals.CELL_SIZE / 2; wallPiece.y = Globals.CELL_SIZE / 2; wallPiece.init(); _gridPieces.Add(wallPiece); wallObj = GameObject.Instantiate(PlayState.instance.wallPrefab) as GameObject; wallObj.transform.parent = PlayState.instance.transform; wallPiece = wallObj.GetComponent <GridPiece>(); wallPiece.x = Globals.CELL_SIZE * i + Globals.CELL_SIZE / 2; wallPiece.y = Globals.CELL_SIZE * (Globals.ROOM_HEIGHT - 1) + Globals.CELL_SIZE / 2; wallPiece.init(); _gridPieces.Add(wallPiece); } for (int i = 1; i < Globals.ROOM_HEIGHT - 1; i++) { // Make a wall along the horizontal edges GameObject wallObj = GameObject.Instantiate(PlayState.instance.wallPrefab) as GameObject; wallObj.transform.parent = PlayState.instance.transform; GridPiece wallPiece = wallObj.GetComponent <GridPiece>(); wallPiece.y = Globals.CELL_SIZE * i + Globals.CELL_SIZE / 2; wallPiece.x = Globals.CELL_SIZE / 2; wallPiece.init(); _gridPieces.Add(wallPiece); wallObj = GameObject.Instantiate(PlayState.instance.wallPrefab) as GameObject; wallObj.transform.parent = PlayState.instance.transform; wallPiece = wallObj.GetComponent <GridPiece>(); wallPiece.y = Globals.CELL_SIZE * i + Globals.CELL_SIZE / 2; wallPiece.x = Globals.CELL_SIZE * (Globals.ROOM_WIDTH - 1) + Globals.CELL_SIZE / 2; wallPiece.init(); _gridPieces.Add(wallPiece); } }
public void addPiece(GridPiece piece, Vector2 gridPos) { Vector2 actualPos = PlayState.instance.toActualCoordinates(gridPos); piece.transform.parent = PlayState.instance.transform; piece.x = actualPos.x; piece.y = actualPos.y; piece.init(); _gridPieces.Add(piece); }
public void addPiece(GridPiece piece) { piece.init(); uint[,] typeGrid = new uint[Globals.ROOM_WIDTH, Globals.ROOM_HEIGHT]; for (int i = 0; i < Globals.ROOM_WIDTH; i++) { for (int j = 0; j < Globals.ROOM_HEIGHT; j++) { typeGrid[i, j] = 0; } } foreach (GridPiece existingPiece in _gridPieces) { typeGrid[(int)existingPiece.gridPos.x, (int)existingPiece.gridPos.y] = existingPiece.type; } // If the piece is not a wall, can insert it in any spot. if (!piece.hasType(GridPiece.WALL_TYPE)) { List <Vector2> emptyTiles = getEmptyTiles(typeGrid); if (emptyTiles.Count == 0) { throw new UnityException("Overflow in room!"); } Vector2 tile = Globals.getRandom(emptyTiles); Vector2 actualPos = PlayState.instance.toActualCoordinates(tile); piece.transform.parent = PlayState.instance.transform; piece.x = actualPos.x; piece.y = actualPos.y; _gridPieces.Add(piece); } // Otherwise, have to make sure it's not next to a wall or edge. else { List <Vector2> spaciousTiles = getSpaciousTiles(typeGrid); if (spaciousTiles.Count == 0) { throw new UnityException("Overflow in room!"); } Vector2 tile = Globals.getRandom(spaciousTiles); Vector2 actualPos = PlayState.instance.toActualCoordinates(tile); piece.transform.parent = PlayState.instance.transform; piece.x = actualPos.x; piece.y = actualPos.y; _gridPieces.Add(piece); } piece.resetGridPos(); }
public void addPiece(GridPiece piece) { piece.init(); uint[,] typeGrid = new uint[Globals.ROOM_WIDTH, Globals.ROOM_HEIGHT]; for (int i = 0; i < Globals.ROOM_WIDTH; i++) { for (int j = 0; j < Globals.ROOM_HEIGHT; j++) { typeGrid[i, j] = 0; } } foreach (GridPiece existingPiece in _gridPieces) { typeGrid[(int)existingPiece.gridPos.x, (int)existingPiece.gridPos.y] = existingPiece.type; } // If the piece is not a wall, can insert it in any spot. if (!piece.hasType(GridPiece.WALL_TYPE)) { List<Vector2> emptyTiles = getEmptyTiles(typeGrid); if (emptyTiles.Count == 0) throw new UnityException("Overflow in room!"); Vector2 tile = Globals.getRandom(emptyTiles); Vector2 actualPos = PlayState.instance.toActualCoordinates(tile); piece.transform.parent = PlayState.instance.transform; piece.x = actualPos.x; piece.y = actualPos.y; _gridPieces.Add(piece); } // Otherwise, have to make sure it's not next to a wall or edge. else { List<Vector2> spaciousTiles = getSpaciousTiles(typeGrid); if (spaciousTiles.Count == 0) throw new UnityException("Overflow in room!"); Vector2 tile = Globals.getRandom(spaciousTiles); Vector2 actualPos = PlayState.instance.toActualCoordinates(tile); piece.transform.parent = PlayState.instance.transform; piece.x = actualPos.x; piece.y = actualPos.y; _gridPieces.Add(piece); } piece.resetGridPos(); }