Ejemplo n.º 1
0
    // Method that creates the rooms and corridors
    private void CreateRoomsAndCorridors()
    {
        rooms     = new Dungeon_Room[Random.Range(minNumRooms, maxNumRooms + 1)];   // Setup a random amount of rooms
        corridors = new Dungeon_Corridor[rooms.Length - 1];                         // There is always one less corridor than the amount of rooms

        rooms[0]     = new Dungeon_Room();                                          // Create the first room
        corridors[0] = new Dungeon_Corridor();                                      // Create the first corridor

        // Setup the first room
        rooms[0].SetupFirstRoom(Random.Range(minRoomWidth, maxRoomWidth + 1), Random.Range(minRoomHeight, maxRoomHeight + 1), columns, rows);

        // Setup the first corridor
        corridors[0].SetupCorridor(rooms[0], minCorridorLength, maxCorridorLength, rooms[0].roomWidth, rooms[0].roomHeight, columns, rows, true);

        // Create and Setup the other rooms
        for (int i = 1; i < rooms.Length; i++)
        {
            rooms[i] = new Dungeon_Room();
            rooms[i].SetupRoom(Random.Range(minRoomWidth, maxRoomWidth + 1), Random.Range(minRoomHeight, maxRoomHeight + 1), columns, rows, corridors[i - 1]);

            if (i < corridors.Length)
            {
                corridors[i] = new Dungeon_Corridor();
                corridors[i].SetupCorridor(rooms[i], minCorridorLength, maxCorridorLength, rooms[i].roomWidth, rooms[i].roomHeight, columns, rows, false);
            }
        }
    }
    // Method which sets up a corridor
    public void SetupCorridor(Dungeon_Room room, int minCorridorLength, int maxCorridorLength, int roomWidth, int roomHeight, int columns, int rows, bool isFirstCorridor)
    {
        // Set a direction for the corridor, a random int cast to a CorridorDirection
        direction = (CorridorDirection)Random.Range(0, 4);

        // This calculates the opposite direction from the corridor that enters the room.
        CorridorDirection oppositeDirection = (CorridorDirection)(((int)room.enteringCorridor + 2) % 4);

        // Only the direction of the first corridor has to be checked
        if (isFirstCorridor)
        {
            CheckFirstCorridorDirection(direction);
        }

        if (!isFirstCorridor && direction == oppositeDirection)
        {
            // It can't be the first corridor since it doesn't have an opposite direction
            // To make it so all the rooms are not connected by corridors all going the same way
            // This rotates the corridor 90 degrees instead of 180 degrees.
            int intDirection = (int)direction;
            intDirection = (intDirection + 1) % 4;
            direction    = (CorridorDirection)intDirection;
        }

        // Get a random length for the corridor
        corridorLength = Random.Range(minCorridorLength, maxCorridorLength + 1);

        // Make a variable which caps the maximum length of the corridor. This is necessary for making sure the corridor won't be able to exit the maximum size of the dungeon
        int maxLength = maxCorridorLength;

        if (direction == CorridorDirection.Up)
        {
            startXPos = Random.Range(room.xPos, room.xPos + room.roomWidth - 1);            // Get a random position along the X-axis
            startZPos = room.zPos + room.roomHeight;                                        // The Z position must be at the top of the room
            maxLength = rows - startZPos - room.roomHeight;                                 // This makes sure the corridor does not exit the dungeon on the top side
        }
        else if (direction == CorridorDirection.Right)
        {
            startXPos = room.xPos + room.roomWidth;
            startZPos = Random.Range(room.zPos, room.zPos + room.roomHeight - 1);
            maxLength = columns - startXPos - room.roomWidth;
        }
        else if (direction == CorridorDirection.Down)
        {
            startXPos = Random.Range(room.xPos, room.xPos + room.roomWidth);
            startZPos = room.zPos;
            maxLength = startZPos - room.roomHeight;
        }
        else if (direction == CorridorDirection.Left)
        {
            startXPos = room.xPos;
            startZPos = Random.Range(room.zPos, room.zPos + room.roomHeight);
            maxLength = startXPos - room.roomWidth;
        }

        // Finally, clamp the corridorlength using the maxLength calculated just before this
        corridorLength = Mathf.Clamp(corridorLength, 1, maxLength);
    }
Ejemplo n.º 3
0
    public void buildDungeonRooms()
    {
        for (int x = 0; x < floorMapHeight; x++)
        {
            for (int y = 0; y < floorMapWidth; y++)
            {
                if (dungeonIntMap[x, y] == -1)
                {
                    dungeonRoomMap[x, y] = null;
                }

                else if (dungeonIntMap[x, y] >= 1 && dungeonIntMap[x, y] < 50)
                {
                    dungeonRoomMap[x, y] = new Dungeon_Room(dungeonIntMap[x, y], x, y, dungeonSeed);
                }
                else if (dungeonIntMap[x, y] >= 100 && dungeonIntMap[x, y] < 500)
                {
                    dungeonRoomMap[x, y] = new Dungeon_Room_Monster(dungeonIntMap[x, y], x, y, dungeonSeed);
                }
                else if (dungeonIntMap[x, y] == 1000)
                {
                    dungeonRoomMap[x, y] = new Dungeon_Room_Hub(dungeonIntMap[x, y], x, y, dungeonSeed);
                }

                else if (dungeonIntMap[x, y] == 1001)
                {
                    dungeonRoomMap[x, y] = new Dungeon_Room_Treasure(dungeonIntMap[x, y], x, y, dungeonSeed);
                }
                else if (dungeonIntMap[x, y] == 1002)
                {
                    dungeonRoomMap[x, y] = new Dungeon_Room_Shop(dungeonIntMap[x, y], x, y, dungeonSeed);
                }
                else if (dungeonIntMap[x, y] == 2000)
                {
                    dungeonRoomMap[x, y] = new Dungeon_Room_Boss(dungeonIntMap[x, y], x, y, dungeonSeed);
                }
            } //forloop through map
        }     //forloop through map
    }         //buildDungeonRooms()