Ejemplo n.º 1
0
        private void AddTunnel(Point startPos, int tunnelLength, int[] direction)
        {
            int x = startPos.X;
            int y = startPos.Y;

            if (rng.Next(0, 100) < 40 && dungeonFloor[x + direction[1], y + direction[0]].Solid && dungeonFloor[x - direction[1], y - direction[0]].Solid)
            {
                dungeonFloor[x, y] = new Door(Material.Wood);
            }
            else
            {
                dungeonFloor[x, y] = new Air();
            }
            for (int i = 1; i <= tunnelLength * 2; i++)
            {
                x = startPos.X + direction[0] * i;
                y = startPos.Y + direction[1] * i;
                if (dungeonFloor[x, y].Solid == false)
                {
                    if (rng.Next(0, 100) < 40 && !(dungeonFloor[x - direction[0] * 2, y - direction[1] * 2] is Door) &&
                        dungeonFloor[x + direction[1], y + direction[0]].Solid && dungeonFloor[x - direction[1], y - direction[0]].Solid)
                    {
                        dungeonFloor[x - direction[0], y - direction[1]] = new Door(Material.Wood);
                    }
                    break;
                }
                dungeonFloor[x, y] = new Air();
            }
        }
Ejemplo n.º 2
0
 private void DoAutomataStep()
 {
     bool[] map = new bool[dungeonFloor.Width * dungeonFloor.Height];
     for (int x = 0; x < dungeonFloor.Width; x++)
     {
         for (int y = 0; y < dungeonFloor.Height; y++)
         {
             map[x * dungeonFloor.Width + y] = dungeonFloor[x, y].Solid;
         }
     }
     for (int x = 0; x < dungeonFloor.Width; x++)
     {
         for (int y = 0; y < dungeonFloor.Height; y++)
         {
             int nbs = CountAliveNeighbours(x, y);
             //The new value is based on our simulation rules
             //First, if a cell is alive but has too few neighbours, kill it.
             if (dungeonFloor[x, y].Opaque)
             {
                 if (nbs < 3)
                 {
                     map[x * dungeonFloor.Width + y] = false;
                 }
                 else
                 {
                     map[x * dungeonFloor.Width + y] = true;
                 }
             } //Otherwise, if the cell is dead now, check if it has the right number of neighbours to be 'born'
             else
             {
                 if (nbs > 4)
                 {
                     map[x * dungeonFloor.Width + y] = true;
                 }
                 else
                 {
                     map[x * dungeonFloor.Width + y] = false;
                 }
             }
         }
     }
     for (int x = 0; x < dungeonFloor.Width; x++)
     {
         for (int y = 0; y < dungeonFloor.Height; y++)
         {
             if (map[x * dungeonFloor.Width + y] && !dungeonFloor[x, y].Solid)
             {
                 dungeonFloor[x, y] = new Wall(Material.Stone);
             }
             else if (!map[x * dungeonFloor.Width + y] && dungeonFloor[x, y].Solid)
             {
                 dungeonFloor[x, y] = new Air();
             }
         }
     }
 }
Ejemplo n.º 3
0
        private Block[,] GenerateRectRoom()
        {
            Point size = new Point(rng.Next(minCrossRoomSize, maxCrossRoomSize), rng.Next(minCrossRoomSize, maxCrossRoomSize));

            Block[,] room = new Block[size.X, size.Y];
            for (int i = 0; i < room.GetLength(0); i++)
            {
                for (int j = 0; j < room.GetLength(1); j++)
                {
                    room[i, j] = new Air();
                }
            }
            return(room);
        }
Ejemplo n.º 4
0
        private Block[,] GenerateAutomataRoom()
        {
            while (true)
            {
                Block[,] room = new Block[maxCellularAutomataSize, maxCellularAutomataSize];

                for (int i = 0; i < room.GetLength(0); i++)
                {
                    for (int j = 0; j < room.GetLength(1); j++)
                    {
                        if (rng.Next(0, 100) >= wallProbability && i >= 2 && i < room.GetLength(0) - 2 && j >= 2 && j < room.GetLength(1) - 2)
                        {
                            room[i, j] = new Air();
                        }
                        else
                        {
                            room[i, j] = new Wall(Material.Stone);
                        }
                    }
                }
                for (int c = 0; c < 3; c++)
                {
                    for (int i = 1; i < room.GetLength(0) - 1; i++)
                    {
                        for (int j = 1; j < room.GetLength(1) - 1; j++)
                        {
                            if (DungeonHelper.GetNumOfAdjacentWalls(new Point(i, j), room) > 4)
                            {
                                room[i, j] = new Wall(Material.Stone);
                            }
                            else if (DungeonHelper.GetNumOfAdjacentWalls(new Point(i, j), room) < 4)
                            {
                                room[i, j] = new Air();
                            }
                        }
                    }
                }
                room = FloodFill(room);
                for (int i = 0; i < room.GetLength(0); i++)
                {
                    for (int j = 0; j < room.GetLength(1); j++)
                    {
                        if (room[i, j].Solid == false)
                        {
                            return(room);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private Block[,] GenerateCrossRoom()
        {
            int roomHorWidth  = (rng.Next(minCrossRoomSize + 2, maxCrossRoomSize)) / 2 * 2;
            int roomVerHeight = (rng.Next(minCrossRoomSize + 2, maxCrossRoomSize)) / 2 * 2;
            int roomHorHeight = (rng.Next(minCrossRoomSize, roomVerHeight - 2)) / 2 * 2;
            int roomVerWidth  = (rng.Next(minCrossRoomSize, roomHorWidth - 2)) / 2 * 2;

            Block[,] room = new Block[roomHorWidth, roomVerHeight];

            for (int i = 0; i < room.GetLength(0); i++)
            {
                for (int j = 0; j < room.GetLength(1); j++)
                {
                    room[i, j] = new Wall(Material.Stone);
                }
            }

            int verOffset = roomVerHeight / 2 - roomHorHeight / 2;

            for (int i = 0; i < roomHorWidth; i++)
            {
                for (int j = verOffset; j < roomHorHeight + verOffset; j++)
                {
                    room[i, j] = new Air();
                }
            }

            int horOffset = roomHorWidth / 2 - roomVerWidth / 2;

            for (int i = horOffset; i < roomVerWidth + horOffset; i++)
            {
                for (int j = 0; j < roomVerHeight; j++)
                {
                    room[i, j] = new Air();
                }
            }

            return(room);
        }