Esempio n. 1
0
    private void SetTilesValuesForCorridors()
    {
        // Go through every corridor...
        for (int i = 0; i < corridors.Length; i++)
        {
            OGCorridor 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;
                    if (tiles[xCoord - 1][yCoord] != TileType.Room && tiles[xCoord - 1][yCoord] != TileType.Corridor)
                    {
                        tiles[xCoord - 1][yCoord] = TileType.Wall;
                    }
                    if (tiles[xCoord + 1][yCoord] != TileType.Room && tiles[xCoord + 1][yCoord] != TileType.Corridor)
                    {
                        tiles[xCoord + 1][yCoord] = TileType.Wall;
                    }
                    break;

                case Direction.East:
                    xCoord += j;
                    if (tiles[xCoord][yCoord - 1] != TileType.Room && tiles[xCoord][yCoord - 1] != TileType.Corridor)
                    {
                        tiles[xCoord][yCoord - 1] = TileType.Wall;
                    }
                    if (tiles[xCoord][yCoord + 1] != TileType.Room && tiles[xCoord][yCoord + 1] != TileType.Corridor)
                    {
                        tiles[xCoord][yCoord + 1] = TileType.Wall;
                    }
                    break;

                case Direction.South:
                    yCoord -= j;
                    if (tiles[xCoord - 1][yCoord] != TileType.Room && tiles[xCoord - 1][yCoord] != TileType.Corridor)
                    {
                        tiles[xCoord - 1][yCoord] = TileType.Wall;
                    }
                    if (tiles[xCoord + 1][yCoord] != TileType.Room && tiles[xCoord + 1][yCoord] != TileType.Corridor)
                    {
                        tiles[xCoord + 1][yCoord] = TileType.Wall;
                    }
                    break;

                case Direction.West:
                    xCoord -= j;
                    if (tiles[xCoord][yCoord - 1] != TileType.Room && tiles[xCoord][yCoord - 1] != TileType.Corridor)
                    {
                        tiles[xCoord][yCoord - 1] = TileType.Wall;
                    }
                    if (tiles[xCoord][yCoord + 1] != TileType.Room && tiles[xCoord][yCoord + 1] != TileType.Corridor)
                    {
                        tiles[xCoord][yCoord + 1] = TileType.Wall;
                    }
                    break;
                }

                // Set the tile at these coordinates to Floor.
                if (tiles[xCoord][yCoord] != TileType.Room)
                {
                    tiles[xCoord][yCoord] = TileType.Corridor;
                }
            }
        }
    }
Esempio n. 2
0
    // This is an overload of the SetupRoom function and has a corridor parameter that represents the corridor entering the room.
    public void SetupRoom(IntRange widthRange, IntRange heightRange, int columns, int rows, OGCorridor corridor)
    {
        // Set the entering corridor direction.
        enteringCorridor = corridor.direction;

        // 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 - 1);

            // 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, 1, columns - roomWidth - 1);
            break;

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

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

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

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

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

            yPos = Random.Range(corridor.EndPositionY - roomHeight + 1, corridor.EndPositionY);
            yPos = Mathf.Clamp(yPos, 1, rows - roomHeight - 1);
            break;
        }
    }
Esempio n. 3
0
    private void CreateRoomsAndCorridors()
    {
        // Create the rooms array with a random size.
        int randomNumRooms = numRooms.Random;

        rooms = new OGRoom[randomNumRooms];

        if (exitRoom > randomNumRooms)
        {
            exitRoom = randomNumRooms;
        }

        // Create the first room and corridor.
        rooms[0] = new OGRoom();

        // Setup the first room, there is no previous corridor so we do not use one.
        rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);
        if (startingRoom == 1)
        {
            Vector3 playerPos = new Vector3(rooms[0].xPos, rooms[0].yPos, 0);
            ClearSpace(playerPos, 0.1f);
            GameManager.instance.GetPlayer().transform.position = playerPos;
        }
        // Setup the first corridor using the first room.
        if (randomNumRooms >= 2)
        {
            corridors    = new OGCorridor[randomNumRooms - 1];
            corridors[0] = new OGCorridor();
            corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);
        }

        /*
         * if (startingRoom == 1)
         * {
         *  Vector3 playerPos = new Vector3(rooms[0].xPos, rooms[0].yPos, 0);
         *  if (ClearSpace(playerPos, 0.1f))
         *      playerPos = new Vector3(rooms[0].xPos, rooms[0].yPos, 0);
         *  GameManager.instance.GetPlayer().transform.position = playerPos;
         * }
         *
         * if (exitRoom == 1)
         * {
         *  Vector3 exitPos = new Vector3(rooms[0].xPos + rooms[0].roomWidth - 1, rooms[0].yPos + rooms[0].roomHeight - 1, 0);
         *  if (ClearSpace(exitPos, 0.1f))
         *      exitPos = new Vector3(rooms[0].xPos + rooms[0].roomWidth - 1, rooms[0].yPos + rooms[0].roomHeight - 1, 0);
         *  GameObject tileInstance = Instantiate(exit, exitPos, Quaternion.identity) as GameObject;
         *  tileInstance.transform.parent = boardHolder.transform;
         * }
         */

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

            // Setup the room based on the previous corridor.
            rooms[i].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[i - 1]);

            // If we haven't reached the end of the corridors array...
            if (i < corridors.Length)
            {
                // ... create a corridor.
                corridors[i] = new OGCorridor();

                // Setup the corridor based on the room that was just created.
                corridors[i].SetupCorridor(rooms[i], corridorLength, roomWidth, roomHeight, columns, rows, false);
            }

            /*
             * if (i == startingRoom - 1)
             * {
             *  Vector3 playerPos = new Vector3(rooms[i].xPos, rooms[i].yPos, 0);
             *  if (ClearSpace(playerPos, 0.1f))
             *      playerPos = new Vector3(rooms[i].xPos, rooms[i].yPos + 1, 0);
             *  GameManager.instance.GetPlayer().transform.position = playerPos;
             * }
             *
             * if (i == exitRoom - 1)
             * {
             *  Vector3 exitPos = new Vector3(rooms[i].xPos, rooms[i].yPos, 0);
             *  if (ClearSpace(exitPos, 0.1f))
             *      exitPos = new Vector3(rooms[i].xPos + 1, rooms[i].yPos, 0);
             *  GameObject tileInstance = Instantiate(exit, exitPos, Quaternion.identity) as GameObject;
             *  tileInstance.transform.parent = boardHolder.transform;
             * }*/
        }
    }