Exemple #1
0
    void SetTilesValuesForCorridors()
    {
        // Go through every corridor...
        for (int i = 0; i < corridors.Count; ++i)
        {
            CCorridor currentCorridor = corridors[i];

            // and go through it's length.
            for (int j = 0; j < currentCorridor.corridorLength; ++j)
            {
                // Start the coordinates at the start of the corridor.
                int xCoord = currentCorridor.startXPos;
                int yCoord = currentCorridor.startYPos;

                // Depending on the direction, add or subtract from the appropriate
                // coordinate based on how far through the length the loop is.
                switch (currentCorridor.direction)
                {
                case Direction.NORTH:
                    yCoord += j;
                    break;

                case Direction.EAST:
                    xCoord += j;
                    break;

                case Direction.SOUTH:
                    yCoord -= j;
                    break;

                case Direction.WEST:
                    xCoord -= j;
                    break;
                }

                // Set the tile at these coordinates to Floor.
                tiles[xCoord][yCoord] = TileType.Floor;
            }
        }
    }
Exemple #2
0
    void CreateRoomsAndCorridors(IntRange _numRooms, IntRange _numCorridors, IntRange _roomWidth, IntRange _roomHeight, IntRange _corridorLength)
    {
        // Create the rooms array with a random size.
        rooms = new CRoom[_numRooms.Random];

        // There should be one less corridor than there is rooms.
        int rand = _numCorridors.Random;

        corridors = new List <CCorridor>(rand);
        //Debug.Log(rand +  "   " + corridors.Count);

        // Create the first room and corridor.
        rooms[0] = new CRoom();
        // Setup the first room, there is no previous corridor so we do not use one.
        rooms[0].SetupRoom(_roomWidth, _roomHeight, columns, rows);

        for (int startingCorr = 0; startingCorr < 4; ++startingCorr)
        {         // ... create a corridor.
            CCorridor firstCorridor = new CCorridor();
            // Setup the first corridor using the first room.
            firstCorridor.SetupCorridor(rooms[0], _corridorLength, _roomWidth, _roomHeight, columns, rows, startingCorr);

            corridors.Add(firstCorridor);
        }

        for (int i = 1; i < rooms.Length; i++)
        {
            // Create a room.
            rooms[i] = new CRoom();

            List <int> notConnectedCorrsIndex = new List <int>();

            // Setup the room base on a unConnectedTo corridor
            for (int corIndex = 0; corIndex < corridors.Count; ++corIndex)
            {
                if (corridors[corIndex].connectedTo == false)
                {
                    notConnectedCorrsIndex.Add(corIndex);
                }
            }

            //choose randomly from the list of unconnected corridors
            if (notConnectedCorrsIndex.Count > 0)
            {
                int randomChoice = Random.Range(0, notConnectedCorrsIndex.Count);
                rooms[i].SetupRoom(_roomWidth, _roomHeight, columns, rows, corridors[notConnectedCorrsIndex[randomChoice]]);
            }
            else
            {
                rooms[i].SetupRoom(_roomWidth, _roomHeight, columns, rows, corridors[i - 1]);
            }

            notConnectedCorrsIndex.Clear();

            // If we haven't reached the end of the corridors array...
            if (corridors.Count < corridors.Capacity)
            {
                CCorridor tempCorridor = new CCorridor();
                int       firstDir     = tempCorridor.SetupCorridor(rooms[i], _corridorLength, _roomWidth, _roomHeight, columns, rows, false);
                corridors.Add(tempCorridor);
            }
        }
    }
Exemple #3
0
    public void SetupRoom(IntRange widthRange, IntRange heightRange, int columns, int rows, CCorridor corridor)
    {
        // Set the entering corridor direction.
        Corridors            = corridor.direction;
        corridor.connectedTo = true;
        generated            = true;

        // Set random values for width and height.
        roomWidth  = widthRange.Random;
        roomHeight = heightRange.Random;

        switch (corridor.direction)
        {
        // If the corridor entering this room is going north...
        case Direction.NORTH:
            // ... the height of the room mustn't go beyond the board so it must be clamped based
            // on the height of the board (rows) and the end of corridor that leads to the room.
            roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndPositionY);

            // The y coordinate of the room must be at the end of the corridor (since the corridor leads to the bottom of the room).
            yPos = corridor.EndPositionY;

            // The x coordinate can be random but the left-most possibility is no further than the width
            // and the right-most possibility is that the end of the corridor is at the position of the room.
            xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);

            // This must be clamped to ensure that the room doesn't go off the board.
            xPos = Mathf.Clamp(xPos, 0, columns - roomWidth);
            break;

        case Direction.EAST:
            roomWidth = Mathf.Clamp(roomWidth, 1, columns - corridor.EndPositionX);
            xPos      = corridor.EndPositionX;

            yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
            yPos = Mathf.Clamp(yPos, 0, rows - roomHeight);
            break;

        case Direction.SOUTH:
            roomHeight = Mathf.Clamp(roomHeight, 1, corridor.EndPositionY);
            yPos       = corridor.EndPositionY - roomHeight + 2;

            xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);
            xPos = Mathf.Clamp(xPos, 0, columns - roomWidth);
            break;

        case Direction.WEST:
            roomWidth = Mathf.Clamp(roomWidth, 1, corridor.EndPositionX);
            xPos      = corridor.EndPositionX - roomWidth + 1;

            yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
            yPos = Mathf.Clamp(yPos, 0, rows - roomHeight);
            break;
        }
    }