예제 #1
0
        // FUNCTIONS

        public void GenerateDungeon(int placementAttempts, int maxRoomCount, int floor)
        {
            DungeonHelper.InitializeMap(dungeonFloor);
            Block[,] room;

            firstRoomPos = floor > 0 ? Program.WorldMap.LocalTile.Dungeon.Floors[floor - 1].GetDownStairPos() : Program.Player.Position;

            for (int c = 0; c < placementAttempts; c++) // create all rooms
            {
                if (rooms.Count >= maxRoomCount)
                {
                    break;
                }
                room = GenerateRoom(); // generate the first room
                if (room != null)
                {
                    PlaceRoom(room);
                }
            }

            DungeonHelper.PlaceStairs(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceItemsAndChests(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceCreatures(dungeonFloor, firstRoomPos, monsterTypes);

            for (int i = 0; i < dungeonFloor.Width; i++)
            {
                for (int j = 0; j < dungeonFloor.Height; j++)
                {
                    if (dungeonFloor.Blocks[i * dungeonFloor.Width + j] == null)
                    {
                        dungeonFloor.Blocks[i * dungeonFloor.Width + j] = new Air();
                    }
                }
            }
        }
예제 #2
0
        // FUNCTIONS

        public override void GenerateDungeon(int size, int floor, Point worldIndex)
        {
            DungeonHelper.InitializeMap(dungeonFloor);
            Block[,] room;

            firstRoomPos = floor > 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[floor - 1].GetDownStairPos() : Program.Player.Position;

            for (int c = 0; c < size * 100; c++) /* create all rooms */
            {
                if (rooms.Count >= size)
                {
                    break;
                }
                room = GenerateRoom(); // generate the first room
                if (room != null)
                {
                    PlaceRoom(room);
                }
            }

            DungeonHelper.PlaceStairs(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceItemsAndChests(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceCreatures(dungeonFloor, firstRoomPos, monsterTypes, worldIndex, floor);

            for (int i = 0; i < dungeonFloor.Width; i++)
            {
                for (int j = 0; j < dungeonFloor.Height; j++)
                {
                    if (dungeonFloor.Blocks[i * dungeonFloor.Width + j] == null)
                    {
                        dungeonFloor.Blocks[i * dungeonFloor.Width + j] = new Air();
                    }
                }
            }
        }
예제 #3
0
        public override void GenerateDungeon(int size, int floor, Point worldIndex)
        {
            firstRoomPos = floor > 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[floor - 1].GetDownStairPos() : Program.Player.Position;

            DungeonHelper.InitializeMap(dungeonFloor);

            // fill the map with random blocks
            for (int i = Math.Max(0, firstRoomPos.X - size / 2); i < Math.Min(dungeonFloor.Width, firstRoomPos.X + size / 2); i++)
            {
                for (int j = Math.Max(0, firstRoomPos.Y - size / 2); j < Math.Min(dungeonFloor.Height, firstRoomPos.Y + size / 2); j++)
                {
                    if ((rng.Next(0, 100) < 40 && (new Point(i, j)).DistFrom(firstRoomPos) > 5))
                    {
                        dungeonFloor.Blocks[i * dungeonFloor.Width + j] = new Wall(Material.Stone);
                    }
                    else
                    {
                        dungeonFloor.Blocks[i * dungeonFloor.Width + j] = new Air();
                    }
                    dungeonFloor.Floor[i * Program.WorldMap.TileWidth + j] = new DirtFloor();
                }
            }
            for (int i = 0; i < 3; i++)
            {
                DoAutomataStep();
            }

            for (int i = 0; i < 15; i++)
            {
                Point pos = new Point(rng.Next(Math.Max(0, firstRoomPos.X - size / 2), Math.Min(dungeonFloor.Width, firstRoomPos.X + size / 2)),
                                      rng.Next(Math.Max(0, firstRoomPos.Y - size / 2), Math.Min(dungeonFloor.Height, firstRoomPos.Y + size / 2)));
                if (dungeonFloor[pos.X, pos.Y] is Air)
                {
                    dungeonFloor.PatrolPoints.Add(pos);
                }
            }

            DungeonHelper.PlaceStairs(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceItemsAndChests(dungeonFloor, firstRoomPos);
            DungeonHelper.PlaceCreatures(dungeonFloor, firstRoomPos, monsterTypes, worldIndex, floor);

            for (int i = 0; i < dungeonFloor.Width; i++)
            {
                for (int j = 0; j < dungeonFloor.Height; j++)
                {
                    if (dungeonFloor.Blocks[i * dungeonFloor.Width + j] == null)
                    {
                        dungeonFloor.Blocks[i * dungeonFloor.Width + j] = new Air();
                    }
                }
            }
        }
예제 #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);
                        }
                    }
                }
            }
        }