예제 #1
0
    //this will do basically same as above just check each coridor val
    void SetTilesValuesForCorridors()
    {
        //for each corridor
        for (int i = 0; i < corridors.Length; i++)
        {
            CorridorMaker currentCorridor = corridors[i];

            ////start looking from start pos of this coridor
            int xCoord = currentCorridor.startXPos;
            int yCoord = currentCorridor.startYPos;


            //check we increment along correct axis to check each corridor position
            //when moving along corridor set positon to true, so we can place floor tile later
            switch (currentCorridor.direction)
            {
            case Direction.North:
                for (int j = 0; j < currentCorridor.corridorLength; j++)
                {
                    FloorTiles[xCoord, yCoord] = true;

                    yCoord += 1;
                }
                break;

            case Direction.East:
                for (int j = 0; j < currentCorridor.corridorLength; j++)
                {
                    FloorTiles[xCoord, yCoord] = true;

                    xCoord += 1;
                }
                break;

            case Direction.South:
                for (int j = 0; j < currentCorridor.corridorLength; j++)
                {
                    FloorTiles[xCoord, yCoord] = true;

                    yCoord -= 1;
                }
                break;

            case Direction.West:
                for (int j = 0; j < currentCorridor.corridorLength; j++)
                {
                    FloorTiles[xCoord, yCoord] = true;

                    xCoord -= 1;
                }
                break;
            }
        }
    }
예제 #2
0
    void CreateRoomsAndCorridors()
    {
        //change our tile array to right size
        FloorTiles = new bool[columns, rows];
        //MazeGrid = new TileVector2[columns, rows];
        //create the rooms array with random size between upper and lower bound
        rooms = new RoomMaker[numRooms.Random];

        //one less corridor than there is rooms
        //as we go room , corridoor, room, (we both start and finish with making a room so we want one less corridoor)
        corridors = new CorridorMaker[rooms.Length - 1];

        //create 1st room corridor
        rooms[0]     = new RoomMaker();
        corridors[0] = new CorridorMaker();

        //setup the first room (no corridors exist yet)
        rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);

        //make first corridor using room above
        corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);

        //for each room we gotta make, excluding first (start at in i = 1)
        for (int i = 1; i < rooms.Length; i++)
        {
            //make room
            rooms[i] = new RoomMaker();
            rooms[i].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[i - 1]);

            //make a corridor if we not at end (dont want corridor leading to nothing
            if (i < corridors.Length)
            {
                corridors[i] = new CorridorMaker();
                corridors[i].SetupCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false);
            }
        }
    }
예제 #3
0
    //Same as above but know we need to draw on the end of a corridor from the previous room/corridor
    public void SetupRoom(IntRange widthRange, IntRange heightRange, int columns, int rows, CorridorMaker corridor)
    {
        //where did corridor come from, that we trying to join onto
        enteringCorridor = corridor.direction;

        //give random width height to room
        roomWidth  = widthRange.Random;
        roomHeight = heightRange.Random;

        //see where corridor came from and adjust accordingly
        switch (corridor.direction)
        {
        //here for each case we are going to do similar things

        //check we are not going to try draw over the size of the mazegrid with clamp
        //this is both for height/width of room depending on direction but also x or y of where room is placed

        //put room at end of the corridor we joining onto
        //however we can randomize where about they connect a bit
        //eg if going north, the room can connect to corridor with any of its x positions (well not very ends of room)


        case Direction.North:

            roomHeight = Mathf.Clamp(roomHeight, 1, rows - corridor.EndPositionY);

            yPos = corridor.EndPositionY;

            xPos = Random.Range(corridor.EndPositionX - roomWidth + 1, corridor.EndPositionX);
            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 + 1;

            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;
        }
    }