示例#1
0
 public void Generate(int level, out Map map, Game game)
 {
     map = new Map(game);
     TCODBsp root = new TCODBsp(1, 1, Map.MAP_WIDTH - 2, Map.MAP_HEIGHT - 2);
     root.splitRecursive(_rand, level, 3, 3, 1.5f, 1.5f);
     //map = new Map(80, 50, new TCODConsole(5, 5));
     GenRoom(root, ref map);
     int x;
     int y;
     FindOpenSpot(out x, out y, map);
     map.SetStartPos(x, y);
     FindOpenSpot(out x, out y, map);
     map.Stair = new Stairs(x, y);
     for (int i = 0; i < 20; i++)
     {
         PlaceRandomItem(map);
     }
 }
示例#2
0
        public void Generate(int level, out Map map, Game game)
        {
            map = new Map(game);
            TCODBsp root = new TCODBsp(1, 1, Map.MAP_WIDTH - 2, Map.MAP_HEIGHT - 2);

            root.splitRecursive(_rand, level, 3, 3, 1.5f, 1.5f);
            //map = new Map(80, 50, new TCODConsole(5, 5));
            GenRoom(root, ref map);
            int x;
            int y;

            FindOpenSpot(out x, out y, map);
            map.SetStartPos(x, y);
            FindOpenSpot(out x, out y, map);
            map.Stair = new Stairs(x, y);
            for (int i = 0; i < 20; i++)
            {
                PlaceRandomItem(map);
            }
        }
示例#3
0
        public override void GenerateMap(AreaMap.Tile[] tiles, int width, int height)
        {
            this.width  = width;
            this.height = height;

            objectSpawns = new List <ObjectSpawn>();

            // generate a binary tree of rooms that subdivides the space, suignthe TCODBsp module
            TCODBsp       bsp           = new TCODBsp(0, 0, width, height);
            RoomGenerator roomGenerator = new RoomGenerator(rng);

            bsp.splitRecursive(rng, NUM_SUBDIVISIONS, MAX_ROOM_SIZE, MAX_ROOM_SIZE, MAX_SIDE_RATIO, MAX_SIDE_RATIO);
            bsp.traverseInvertedLevelOrder(roomGenerator);

            // dig out the generated rooms
            foreach (DungeonRoom room in roomGenerator.rooms)
            {
                DigArea(tiles, room.data.x, room.data.y, room.data.x + room.data.w - 1, room.data.y + room.data.h - 1);
            }

            // generate a sparsely connected graph of the created rooms, so that all rooms are connected
            CreateSparseRoomGraph(roomGenerator.rooms);

            // follow the connections in the graph and generate a tunnel b/w the rooms that are connected
            foreach (DungeonRoom room in roomGenerator.rooms)
            {
                // dig a hallway to each neighboring room
                foreach (DungeonRoom neighbor in room.neighbors)
                {
                    Rect roomData = room.data;
                    Rect nextData = neighbor.data;

                    ConnectRooms(tiles, roomData, nextData);
                }
            }

            // decide where the player should spawn
            int         playerRoomIdx = rng.getInt(0, roomGenerator.rooms.Count - 1);
            DungeonRoom playerRoom    = roomGenerator.rooms[playerRoomIdx];

            Vector2 playerLoc = RandomSpawnInRoom(playerRoom);

            objectSpawns.Add(new ObjectSpawn(playerLoc, ENTRANCE_ENTITY));
            objectSpawns.Add(new ObjectSpawn(playerLoc, "Player"));

            // place doors between rooms where appropriate, and spawn other entities and obejcts as well
            int numChests = 0;

            foreach (DungeonRoom room in roomGenerator.rooms)
            {
                GetDoors(tiles, room.data);

                // decide if any mobs should go in this room: defs not if its the start room
                if (room == playerRoom)
                {
                    continue;
                }

                SpawnContainers(room, mapInfo, ref numChests);
                SpawnMobs(room, mapInfo);
            }

            // spawn a key for each chest
            for (int i = 0; i < numChests; i++)
            {
                Vector2 loc = RandomSpawn(roomGenerator.rooms);
                objectSpawns.Add(new ObjectSpawn(loc, KEY_ENTITY));
            }

            // and add exit somewhere else
            Vector2 exitLoc = RandomSpawn(roomGenerator.rooms);

            objectSpawns.Add(new ObjectSpawn(exitLoc, EXIT_ENTITY));
        }