void createTile(int tileX, int tileZ, Vector3 newPosition) { // Debug.Log ("Creating tile at: " + tileX + ", " + tileZ); // get number of tiles adjacent to new tile that open onto new tile // get each of the adjacent tiles Tile.Path[] openings = new Tile.Path[4]; // NORTH OPENING Tile north = getFromQuadrant (Q1, tileX, tileZ + 1); if (north != null) openings [(int)Tile.Compass.NORTH] = north.opening (Tile.Compass.SOUTH); else openings [(int)Tile.Compass.NORTH] = Tile.Path.EMPTY; // EAST OPENING Tile east = getFromQuadrant (Q1, tileX + 1, tileZ); if (east != null) openings [(int)Tile.Compass.EAST] = east.opening (Tile.Compass.WEST); else openings [(int)Tile.Compass.EAST] = Tile.Path.EMPTY; // SOUTH OPENING Tile south = getFromQuadrant (Q1, tileX, tileZ - 1); if (south != null) openings [(int)Tile.Compass.SOUTH] = south.opening (Tile.Compass.NORTH); else openings [(int)Tile.Compass.SOUTH] = Tile.Path.EMPTY; // WEST OPENING Tile west = getFromQuadrant (Q1, tileX - 1, tileZ); if (west != null) openings [(int)Tile.Compass.WEST] = west.opening (Tile.Compass.EAST); else openings [(int)Tile.Compass.WEST] = Tile.Path.EMPTY; // use Tile.RandomValidType() to get a random type // for the new tile int newType = (int)Tile.RandomValidType (openings); // check against invalid tile position (surrounded by walls) if ((Tile.Shape)newType == Tile.Shape.INVALID) return; Vector3 orientation = Tile.CorrectOrientation ((Tile.Shape)newType, openings); Transform newTrans = Instantiate (prefabs [newType], newPosition, Quaternion.Euler(orientation)) as Transform; Tile newTile = new Tile (Tile.Shape.CROSS, newTrans); Q1 [tileX - 1] [tileZ - 1] = newTile; }
/** * @brief A method to spawn the next appropriate tile. * @details [long description] * * @param tileX [description] * @param tileZ [description] * @param newPosition [description] */ void createTile(int tileX, int tileZ, Vector3 newPosition) { // Debug.Log ("Creating tile at: " + tileX + ", " + tileZ); // get number of tiles adjacent to new tile that open onto new tile // get each of the adjacent tiles Tile.Path[] openings = new Tile.Path[4]; // SOUTH OPENING Tile south = getFromQuadrant (Q1, tileX, tileZ - 1); if (south != null) openings [(int)Tile.Compass.SOUTH] = south.opening (Tile.Compass.NORTH); else openings [(int)Tile.Compass.SOUTH] = Tile.Path.EMPTY; // WEST OPENING Tile west = getFromQuadrant (Q1, tileX - 1, tileZ); if (west != null) openings [(int)Tile.Compass.WEST] = west.opening (Tile.Compass.EAST); else openings [(int)Tile.Compass.WEST] = Tile.Path.EMPTY; // NORTH OPENING Tile north = getFromQuadrant (Q1, tileX, tileZ + 1); if (north != null) openings [(int)Tile.Compass.NORTH] = north.opening (Tile.Compass.SOUTH); else openings [(int)Tile.Compass.NORTH] = Tile.Path.EMPTY; // EAST OPENING Tile east = getFromQuadrant (Q1, tileX + 1, tileZ); if (east != null) openings [(int)Tile.Compass.EAST] = east.opening (Tile.Compass.WEST); else openings [(int)Tile.Compass.EAST] = Tile.Path.EMPTY; // print out tile surroundings Debug.Log("Tile (" + tileX + ",\t" + tileZ + "\t)"); for (int i = 0; i < 4; i++) { // determine direction Tile t = null; switch ((Tile.Compass) i) { case Tile.Compass.SOUTH: t = south; break; case Tile.Compass.WEST: t = west; break; case Tile.Compass.NORTH: t = north; break; case Tile.Compass.EAST: t = east; break; } // print shit out if (t != null) Debug.Log((Tile.Compass) i + ":\t" + openings[i] + ",\t" + t.type); else Debug.Log((Tile.Compass) i + ":\t" + openings[i] + ",\tNULL"); } // use Tile.RandomValidType() to get a random type for the new tile Tile.Shape newShape = Tile.RandomValidShape(openings); // check against invalid tile position (surrounded by walls) if (newShape == Tile.Shape.INVALID) return; // call helper method to get a random, valid orientation Vector3 orientation = Tile.RandomValidOrientation(newShape, openings); // instantiate the new tile Transform newTrans = Instantiate (prefabs [(int)newShape], newPosition, Quaternion.Euler(orientation)) as Transform; Tile newTile = new Tile (newShape, newTrans); Q1 [tileX - 1] [tileZ - 1] = newTile; }