Exemplo n.º 1
0
        private MapRoom[,] generateRoomConnections(int columns, int rows)
        {
            // http://kuoi.com/~kamikaze/GameDesign/art07_rogue_dungeon.php

            MapRoom[,] rooms = new MapRoom[columns, rows];
            List <MapRoom> disconnectedRooms = new List <MapRoom>(columns * rows);

            for (int x = 0; x < columns; ++x)
            {
                for (int y = 0; y < rows; ++y)
                {
                    rooms[x, y] = new MapRoom(new Point(x, y));
                    disconnectedRooms.Add(rooms[x, y]);
                }
            }

            MapRoom currentRoom = disconnectedRooms.Sample();
            MapRoom nextRoom;

            while ((nextRoom = currentRoom.GetNeighborWhere(rooms, columns, rows, room => !room.Connected)) != null)
            {
                disconnectedRooms.Remove(currentRoom);
                disconnectedRooms.Remove(nextRoom);
                currentRoom.ConnectTo(nextRoom);
                currentRoom = nextRoom;
            }

            while (disconnectedRooms.Count > 0)
            {
                currentRoom = disconnectedRooms.Sample();
                nextRoom    = currentRoom.GetNeighborWhere(rooms, columns, rows, room => room.Connected);

                if (nextRoom != null)
                {
                    disconnectedRooms.Remove(currentRoom);
                    disconnectedRooms.Remove(nextRoom);
                    currentRoom.ConnectTo(nextRoom);
                }
            }

            return(rooms);
        }
Exemplo n.º 2
0
        public MapRoom GetNeighborWhere(MapRoom[,] rooms, int columns, int rows, Func<MapRoom, bool> predicate)
        {
            List<MapRoom> neighbors = new List<MapRoom>();

            for (int x = Position.X - 1; x <= Position.X + 1; ++x)
            {
                if (x < 0 || x >= columns)
                    continue;

                for (int y = Position.Y - 1; y <= Position.Y + 1; ++y)
                {
                    if (y < 0 || y >= rows)
                        continue;
                    if (Position.X == x && Position.Y == y)
                        continue;

                    if (predicate(rooms[x, y]))
                        neighbors.Add(rooms[x, y]);
                }
            }

            if (neighbors.Count > 0)
                return neighbors.Sample();
            else
                return null;
        }
Exemplo n.º 3
0
 public void ConnectTo(MapRoom room)
 {
     ConnectedRooms.Add(room);
     room.ConnectedRooms.Add(this);
 }
Exemplo n.º 4
0
        private MapRoom[,] generateRoomConnections(int columns, int rows)
        {
            // http://kuoi.com/~kamikaze/GameDesign/art07_rogue_dungeon.php

            MapRoom[,] rooms = new MapRoom[columns, rows];
            List<MapRoom> disconnectedRooms = new List<MapRoom>(columns * rows);
            for (int x = 0; x < columns; ++x)
            {
                for (int y = 0; y < rows; ++y)
                {
                    rooms[x, y] = new MapRoom(new Point(x, y));
                    disconnectedRooms.Add(rooms[x, y]);
                }
            }

            MapRoom currentRoom = disconnectedRooms.Sample();
            MapRoom nextRoom;
            while ((nextRoom = currentRoom.GetNeighborWhere(rooms, columns, rows, room => !room.Connected)) != null)
            {
                disconnectedRooms.Remove(currentRoom);
                disconnectedRooms.Remove(nextRoom);
                currentRoom.ConnectTo(nextRoom);
                currentRoom = nextRoom;
            }

            while (disconnectedRooms.Count > 0)
            {
                currentRoom = disconnectedRooms.Sample();
                nextRoom = currentRoom.GetNeighborWhere(rooms, columns, rows, room => room.Connected);

                if (nextRoom != null)
                {
                    disconnectedRooms.Remove(currentRoom);
                    disconnectedRooms.Remove(nextRoom);
                    currentRoom.ConnectTo(nextRoom);
                }
            }

            return rooms;
        }
Exemplo n.º 5
0
        private void generateCollisionMapFromRooms(MapRoom[,] rooms, int columns, int rows)
        {
            int roomWidth = TileWidth / columns;
            int roomHeight = TileHeight / rows;

            for (int x = 0; x < columns; ++x)
            {
                for (int y = 0; y < rows; ++y)
                {
                    if (rooms[x, y].IsCorridor)
                        fillInRoom(x, y, roomWidth, roomHeight);
                    else
                        wallOffRoom(x, y, roomWidth, roomHeight);
                }
            }

            for (int x = 0; x < columns; ++x)
            {
                for (int y = 0; y < rows; ++y)
                {
                    foreach (MapRoom room in rooms[x, y].ConnectedRooms)
                        digCorridor(rooms[x, y].Position, room.Position, roomWidth, roomHeight);
                }
            }
        }
Exemplo n.º 6
0
 public void ConnectTo(MapRoom room)
 {
     ConnectedRooms.Add(room);
     room.ConnectedRooms.Add(this);
 }