示例#1
0
文件: RoomGen.cs 项目: cobellini/Game
    public Dir CorridorEntry; //direction the corridor is heading.


    //used for the first room.
    public void SetupRoom(RandomIntGen widthRng, RandomIntGen heightRng, int columns, int rows)
    {
        roomWidth  = widthRng.Random;                                 //set a width&height to random values
        roomHeight = heightRng.Random;
        xPosition  = Mathf.RoundToInt(columns / 2f - roomWidth / 2f); //set x&y coord so the room is around the middle of the board.
        yPosition  = Mathf.RoundToInt(rows / 2f - roomHeight / 2f);
    }
示例#2
0
文件: RoomGen.cs 项目: cobellini/Game
    //overload of setuproom with corridor parameter. used for all other rooms except first.
    public void SetupRoom(RandomIntGen widthRng, RandomIntGen heightRng, int columns, int rows, CorridorGen corridor)
    {
        CorridorEntry = corridor.dir;    //entery corridor direction
        roomWidth     = widthRng.Random; //set width&height to random values
        roomHeight    = heightRng.Random;

        switch (corridor.dir)
        {
        // depending on corridor enetering room direction
        case Dir.North:                         //height of room cant go beyond the board so its clamped. On the height of board, end of corridor leads to room
            roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndPositionY);
            yPosition  = corridor.EndPositionY; //y coord of room must be at end of the corridor
            //xposition can be rand but left-most possibility no further than width and right-most possiblity is end of the corridor is at the pos of the room
            xPosition = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);
            //clamped to ensure room isnt off board.
            xPosition = Mathf.Clamp(xPosition, 0, columns - roomWidth);
            break;

        case Dir.East:
            roomWidth = Mathf.Clamp(roomWidth, 1, columns - corridor.EndPositionX);
            xPosition = corridor.EndPositionX;

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

        case Dir.South:
            roomHeight = Mathf.Clamp(roomHeight, 1, corridor.EndPositionY);
            yPosition  = corridor.EndPositionY - roomHeight + 1;

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

        case Dir.West:
            roomWidth = Mathf.Clamp(roomWidth, 1, corridor.EndPositionX);
            xPosition = corridor.EndPositionX - roomWidth + 1;

            yPosition = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
            yPosition = Mathf.Clamp(yPosition, 0, rows - roomHeight);
            break;
        }
    }
示例#3
0
    public void CorridorSetup(RoomGen room, RandomIntGen length, RandomIntGen roomWidth, RandomIntGen roomHeight, int columns, int rows, bool firstCorridor)
    {
        // Set a random direction (random index from 0-3, cast to Direction).
        dir = (Dir)Random.Range(0, 4);

        // Find direction opposite to one entering room current corridor is leaving from.
        // Cast prev corridor direction to int between 0 and 3 then add 2, then find remainder
        Dir oppositeDirection = (Dir)(((int)room.CorridorEntry + 2) % 4);

        // If this is not the first corridor and the randomly selected direction is opposite to the previous corridor's direction...
        if (!firstCorridor && dir == oppositeDirection)
        {
            // Rotate the direction 90 degrees clockwise (North becomes East, East becomes South.)
            int directionVal = (int)dir;
            directionVal++;
            directionVal = directionVal % 4;
            dir          = (Dir)directionVal;
        }

        // Set random length.
        corridorLength = length.Random;

        // Create cap from randomvalue script for how long it can be..
        int max_Length = length.maximumVal;

        switch (dir)
        {
        // If the choosen direction is North
        case Dir.North:
            // starting position in the x axis can be random but within the width of the room.
            startXPos = Random.Range(room.xPosition, room.xPosition + room.roomWidth - 1);

            // starting position in the y axis must be the top of the room.
            startYPos = room.yPosition + room.roomHeight;

            // maximum length the corridor can be is the height of the board (rows) but from the top of the room (y pos + height).
            max_Length = rows - startYPos - roomHeight.minimumvVal;
            break;

        case Dir.East:
            startXPos  = room.xPosition + room.roomWidth;
            startYPos  = Random.Range(room.yPosition, room.yPosition + room.roomHeight - 1);
            max_Length = columns - startXPos - roomWidth.minimumvVal;
            break;

        case Dir.South:
            startXPos  = Random.Range(room.xPosition, room.xPosition + room.roomWidth);
            startYPos  = room.yPosition;
            max_Length = startYPos - roomHeight.minimumvVal;
            break;

        case Dir.West:
            startXPos  = room.xPosition;
            startYPos  = Random.Range(room.yPosition, room.yPosition + room.roomHeight);
            max_Length = startXPos - roomWidth.minimumvVal;
            break;
        }

        // clamp the corridor length to make sure it doesn't go off the board.
        corridorLength = Mathf.Clamp(corridorLength, 1, max_Length);
    }