// Fills a space with tiles of "tileType" private void FillRectangleWithTiles(Map homeMap, Coords topLeft, Coords bottomRight, TileGenerator tileType) { Coords difference = bottomRight - topLeft; if (!(difference.X > -1 && difference.Y > -1)) { return; } // There should be a more elegant way of dealing with the "Is it passable or impassable?" problem. if (tileType.passable) { for (int i = 0; i < difference.X + 1; ++i) { for (int j = 0; j < difference.Y + 1; ++j) { Coords currentCoords = new Coords(CoordsType.Tile, topLeft.X + i, topLeft.Y + j); homeMap.SetTile(currentCoords, new TilePassable(homeMap, currentCoords, tileType)); } } } else { for (int i = 0; i < difference.X + 1; ++i) { for (int j = 0; j < difference.Y + 1; ++j) { Coords currentCoords = new Coords(CoordsType.Tile, topLeft.X + i, topLeft.Y + j); homeMap.SetTile(currentCoords, new TileImpassable(homeMap, currentCoords, tileType)); } } } }
// Generates a rectangular room private void GenerateRectangularRoom(Map homeMap, Coords topLeft, Coords bottomRight) { Coords difference = bottomRight - topLeft; if (!(difference.X > 1 && difference.Y > 1)) { return; } // Walls FillRectangleWithTiles(homeMap, topLeft, new Coords(CoordsType.Tile, topLeft.X, bottomRight.Y), Constants.TileGeneratorWallStone); FillRectangleWithTiles(homeMap, topLeft, new Coords(CoordsType.Tile, bottomRight.X, topLeft.Y), Constants.TileGeneratorWallStone); FillRectangleWithTiles(homeMap, new Coords(CoordsType.Tile, topLeft.X, bottomRight.Y), bottomRight, Constants.TileGeneratorWallStone); FillRectangleWithTiles(homeMap, new Coords(CoordsType.Tile, bottomRight.X, topLeft.Y), bottomRight, Constants.TileGeneratorWallStone); // Floor this.FillRectangleWithTiles(homeMap, new Coords(CoordsType.Tile, topLeft.X + 1, topLeft.Y + 1), new Coords(CoordsType.Tile, bottomRight.X - 1, bottomRight.Y - 1), Constants.TileGeneratorFloorDirt); // Open door. For now by default door is in the top-left corner. Coords doorSpot = new Coords(CoordsType.Tile, topLeft.X + 1, topLeft.Y); homeMap.SetTile(doorSpot, new TilePassable(homeMap, doorSpot, Constants.TileGeneratorFloorDirt)); }