private void GenerateFireMap(EntityManager EntityManager, GameEngine engine) { // Fill the whole map with walls for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { Map[x, y] = TileFactory.CreateDungeonWall(engine); } } // Dig the rooms CreateRoomsAndHallways(engine, 5, 20, 5, 20, 30); // Clear the walls that serve no purpose (makes map look better) ClearWalls(); // Replace all of the generic dungeon walls with fire walls for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { if (Map[x, y].Name.Equals("Dungeon Wall")) { Map[x, y] = TileFactory.CreateFireDungeonWall(engine); } } } // Add entities to the dungeon Populate(EntityManager, engine); }
/// <summary> /// Dig into the map to form rooms. The algorithm works by building an intial room, deciding where /// doors can be plced (pretty much on every wall of the room except the corners) and then building /// a random sized hallway from a random point. The hallway is then expanded to form a room. Repeat /// until the maximum number of rooms or the maximum number of attempts are reached /// </summary> /// <param name="random"></param> private void CreateRoomsAndHallways(GameEngine engine, int minWidth, int maxWidth, int minHeight, int maxHeight, int maxRooms) { // Room properties int maxAttempts = 600; // Generate Initial Room List <Point> possibleDoorways = new List <Point>(); int roomWidth = engine.GetRandomInt(minWidth, maxWidth); int roomHeight = engine.GetRandomInt(minHeight, maxHeight); int roomX = engine.GetRandomInt(1, Width - roomWidth - 1); int roomY = engine.GetRandomInt(1, Height - roomHeight - 1); DigRoom(roomX, roomY, roomWidth, roomHeight, possibleDoorways, engine); // Add other rooms int numRooms = 1; int numAttempts = 0; // Keep working until one of the limits set is reached while (numRooms < maxRooms && numAttempts < maxAttempts) { UpdatePossibleDoorways(possibleDoorways); // Choose a random doorway int index = engine.GetRandomInt(possibleDoorways.Count); Point door = possibleDoorways[index]; // Build a room out of that door if (GrowRoom(door, engine.GetRandomInt(minWidth, maxWidth), engine.GetRandomInt(minHeight, maxHeight), engine)) { numRooms++; } numAttempts++; } // Create a border for the map for (int x = 0; x < Width; x++) { Map[x, 0] = TileFactory.CreateDungeonWall(engine); Map[x, Height - 1] = TileFactory.CreateDungeonWall(engine); } for (int y = 0; y < Height; y++) { Map[0, y] = TileFactory.CreateDungeonWall(engine); Map[Width - 1, y] = TileFactory.CreateDungeonWall(engine); } }
/// <summary> /// Create a single generic level of the dungeon /// </summary> /// <param name="random"></param> private void GenerateGenericMap(EntityManager EntityManager, GameEngine engine) { // Fill the whole map with walls for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { Map[x, y] = TileFactory.CreateDungeonWall(engine); } } // Dig the rooms CreateRoomsAndHallways(engine, 10, 15, 10, 15, 30); // Clear the walls that serve no purpose (makes map look better) ClearWalls(); // Add entities to the dungeon Populate(EntityManager, engine); }