예제 #1
0
        private Code.MapGeneration.Room CarveRoom(int xSize, int ySize, bool overlap = false)
        {
            // If overlap is set to true, then the carver doesn't care if it draws over other rooms.
            // This method only tries to carve a room 100 times -- if it can't find a good place in that
            // many goes, it gives up.

            Code.MapGeneration.Room r = new Code.MapGeneration.Room();
            r.xDimension = xSize;
            r.yDimension = ySize;

            for (int i = 1; i <= 100; i++)
            {
                // I know row 0, col 0, row yDimension, and col xDimension are forbidden. So.
                r.TopLeftX = Game.Dice.XdY(1, (XDimension - 1) - xSize);
                r.TopLeftY = Game.Dice.XdY(1, (YDimension - 1) - ySize);

                if (!overlap)
                {
                    // Check each corner to make sure it's not covered.
                    if (TileArray[r.TopLeftX, r.TopLeftY].Name != "floor" &&
                        TileArray[r.TopLeftX, r.TopLeftY + ySize - 1].Name != "floor" &&
                        TileArray[r.TopLeftX + xSize - 1, r.TopLeftY].Name != "floor" &&
                        TileArray[r.TopLeftX + xSize - 1, r.TopLeftY + ySize - 1].Name != "floor")
                    {
                        // We're good. Carve and return.
                        r.CalculateCentre();    // While I'm thinking of it.
                        for (int x = 0; x < xSize; x++)
                        {
                            for (int y = 0; y < ySize; y++)
                            {
                                TileArray[r.TopLeftX + x, r.TopLeftY + y].MakeTile("floor");
                            }
                        }
                        return(r);
                    }
                }
            }

            // If we get here, room generation has failed.
            if (Globals.DEBUG_MODE)
            {
                Game.Globals.DEBUG_ERROR_LIST.Add("Room generation failed!");
            }
            r.CentreX = -1;
            return(r);
        }
예제 #2
0
        private void GenerateDungeonMap()
        {
            // A dungeon map fills the entire level with wall, then cuts ten rooms, then links them with tunnels.
            // Right now it produces quite an open-plan dungeon. Which I'm okay with?
            // But I think I need to refine the overlap parameters.
            for (int i = 0; i <= TileArray.GetUpperBound(0); i++)
            {
                for (int j = 0; j <= TileArray.GetUpperBound(1); j++)
                {
                    TileArray[i, j] = new Tile(i, j);
                    TileArray[i, j].MakeTile("wall");
                }
            }

            // Carve some rooms.
            List <Code.MapGeneration.Room> RoomList = new List <Code.MapGeneration.Room>();

            for (int i = 1; i <= 10; i++)
            {
                int xDim = Game.Dice.XdY(1, 7) + 3;
                int yDim = Game.Dice.XdY(1, 7) + 3;

                Code.MapGeneration.Room r = CarveRoom(xDim, yDim);
                if (r.CentreX != -1)
                {
                    RoomList.Add(CarveRoom(xDim, yDim));
                }
                // If r.centrex IS -1, that means the room generation failed.
            }

            // Link the rooms with tunnels.
            // Nice basic L-shaped tunnels for now.
            for (int i = 0; i < RoomList.Count - 1; i++)
            {
                if (RoomList[i].CentreX > 0)    // Ruling out the duff rooms.
                {
                    // Go across.
                    CarveLine(RoomList[i].CentreX, RoomList[i].CentreY, RoomList[i + 1].CentreX, RoomList[i].CentreY);
                    // Go down.
                    CarveLine(RoomList[i].CentreX, RoomList[i].CentreY, RoomList[i].CentreX, RoomList[i + 1].CentreY);
                }
            }
            // And then one more to link room(last) to room(first).
            // TODO: THIS ISN'T WORKING.

            for (int i = RoomList.Count - 1; i > 0; i--)
            {
                if (RoomList[i].CentreX != -1)
                {
                    CarveLine(RoomList[i].CentreX, RoomList[i].CentreY, RoomList[0].CentreX, RoomList[i].CentreY);
                    CarveLine(RoomList[i].CentreX, RoomList[i].CentreY, RoomList[i].CentreX, RoomList[0].CentreY);
                    break;
                }
            }

            // And then we drop the player in the start of Room 1.
            int x = RoomList[0].CentreX;
            int y = RoomList[0].CentreY;

            InstantiatePlayer(TileArray[x, y]);
        }