コード例 #1
0
ファイル: BoardMaker.cs プロジェクト: cobellini/Game
    void SetCorridorTileValues()
    {
        for (int i = 0; i < corridor_.Length; i++)                   // loop through every corridor
        {
            CorridorGen currentCorridor = corridor_[i];              //assign current corridor index to currentcorridor object

            for (int j = 0; j < currentCorridor.corridorLength; j++) //loop through corridor array length
            {
                int xCoord = currentCorridor.startXPos;              //coordinates at start of the corridor
                int yCoord = currentCorridor.startYPos;

                switch (currentCorridor.dir) //depending on corridor direction, add or take away coord based on how far through  the length of the loop is.
                {
                case Dir.North:
                    yCoord += j;
                    break;

                case Dir.East:
                    xCoord += j;
                    break;

                case Dir.South:
                    yCoord -= j;
                    break;

                case Dir.West:
                    xCoord -= j;
                    break;
                }

                tile[xCoord][yCoord] = TypeofTile.Floor; //set tile at coords to floor.
            }
        }
    }
コード例 #2
0
ファイル: BoardMaker.cs プロジェクト: cobellini/Game
    void CreateRoomsCorridors()
    {
        room_        = new RoomGen[numRooms.Random];                                                    //create room_ array with random amount of rooms.
        corridor_    = new CorridorGen[room_.Length - 1];                                               //assign corridor_ array with same amount of rooms -1
        room_[0]     = new RoomGen();                                                                   //map room and corridor
        corridor_[0] = new CorridorGen();
        room_[0].SetupRoom(roomWidth, roomHeight, columns, rows);                                       //map second room
        corridor_[0].CorridorSetup(room_[0], corridorSize, roomWidth, roomHeight, columns, rows, true); // map second corridor from the first room.

        for (int i = 1; i < room_.Length; i++)                                                          //loop through the room_ array
        {
            room_[i] = new RoomGen();                                                                   //create new room
            room_[i].SetupRoom(roomWidth, roomHeight, columns, rows, corridor_[i - 1]);                 //set up room based on prev corridor position

            if (i < corridor_.Length)                                                                   //if current forloop iteration is less than the corridor_ value, create a corridor and set up corridor based on the room just created
            {
                corridor_[i] = new CorridorGen();
                corridor_[i].CorridorSetup(room_[i], corridorSize, roomWidth, roomHeight, columns, rows, false);
            }
        }
    }
コード例 #3
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;
        }
    }