Example #1
0
    void SetTilesValuesForCorridors()
    {
        // Go through every corridor...
        for (int i = 0; i < corridors.Length; i++)
        {
            Corridor3D 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;
                int CorridDepth = currentCorridor.Depth - 1;

                // 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[CorridDepth][xCoord][yCoord] = currentCorridor.FloorType;
            }
        }
        //Redo Room[0] to ensure entry room not destroyed
        Room3D EntryRoom = rooms[0];
        //Debug.Log("Total Rooms " + rooms.Length + " Room # " + i);
        int EntryDepth = EntryRoom.Depth - 1;

        // ... and for each room go through it's width.
        for (int j = 0; j < EntryRoom.roomWidth; j++)
        {
            int xCoord = EntryRoom.xPos + j;

            // For each horizontal tile, go up vertically through the room's height.
            for (int k = 0; k < EntryRoom.roomHeight; k++)
            {
                int yCoord = EntryRoom.yPos + k;

                // The coordinates in the jagged array are based on the room's position and it's width and height.
                tiles[EntryDepth][xCoord][yCoord] = EntryRoom.FloorType;
            }
        }
    }
Example #2
0
 public Room3DController(GameWorld world)
 {
     foreach (var room in world.Rooms)
     {
         Room3D.Init(room);
     }
 }
Example #3
0
    public void BuildEntryCorridor(Room3D room, int length)
    {
        FloorType = TileType3D.Floor;
        Depth     = 1;
        switch (room.FloorType)
        {
        case TileType3D.Entry1:
            direction = Direction.West;
            break;

        case TileType3D.Entry2:
            direction = Direction.East;
            break;

        case TileType3D.Entry4:
            direction = Direction.North;
            break;

        case TileType3D.Entry8:
            direction = Direction.South;
            break;
        }
        switch (direction)
        {
        case Direction.North:
            startXPos = room.xPos;
            startYPos = room.yPos + 1;
            break;

        case Direction.West:
            startXPos = room.xPos - 1;
            startYPos = room.yPos;
            break;

        case Direction.South:
            startXPos = room.xPos;
            startYPos = room.yPos - 1;
            break;

        case Direction.East:
            startXPos = room.xPos + 1;
            startYPos = room.yPos;
            break;
        }
        corridorLength = length;
    }
Example #4
0
    void SetTilesValuesForRooms()
    {
        // Go through all the rooms...
        for (int i = 0; i < rooms.Length; i++)
        {
            Room3D currentRoom = rooms[i];
            //Debug.Log("Total Rooms " + rooms.Length + " Room # " + i);
            int roomDepth = currentRoom.Depth - 1;
            // ... and for each room go through it's width.
            for (int j = 0; j < currentRoom.roomWidth; j++)
            {
                int xCoord = currentRoom.xPos + j;

                // For each horizontal tile, go up vertically through the room's height.
                for (int k = 0; k < currentRoom.roomHeight; k++)
                {
                    int yCoord = currentRoom.yPos + k;

                    // The coordinates in the jagged array are based on the room's position and it's width and height.
                    tiles[roomDepth][xCoord][yCoord] = currentRoom.FloorType;
                }
            }
        }
        //Redo Room[0] to ensure entry room not destroyed
        Room3D EntryRoom = rooms[0];
        //Debug.Log("Total Rooms " + rooms.Length + " Room # " + i);
        int EntryDepth = EntryRoom.Depth - 1;

        // ... and for each room go through it's width.
        for (int j = 0; j < EntryRoom.roomWidth; j++)
        {
            int xCoord = EntryRoom.xPos + j;

            // For each horizontal tile, go up vertically through the room's height.
            for (int k = 0; k < EntryRoom.roomHeight; k++)
            {
                int yCoord = EntryRoom.yPos + k;

                // The coordinates in the jagged array are based on the room's position and it's width and height.
                tiles[EntryDepth][xCoord][yCoord] = EntryRoom.FloorType;
            }
        }

        //Debug.Log("Rooms created in array.");
    }
Example #5
0
    public void SetupCorridor(Room3D room, IntRange length, IntRange roomWidth, IntRange roomHeight, int columns, int rows, bool firstCorridor, int level)
    {
        // Set a random direction (a random index from 0 to 3, cast to Direction).
        direction = (Direction)Random.Range(0, 4);
        Depth     = level;

        // Find the direction opposite to the one entering the room this corridor is leaving from.
        // Cast the previous corridor's direction to an int between 0 and 3 and add 2 (a number between 2 and 5).
        // Find the remainder when dividing by 4 (if 2 then 2, if 3 then 3, if 4 then 0, if 5 then 1).
        // Cast this number back to a direction.
        // Overall effect is if the direction was South then that is 2, becomes 4, remainder is 0, which is north.
        Direction oppositeDirection = (Direction)(((int)room.enteringCorridor + 2) % 4);

        // If this is noth the first corridor and the randomly selected direction is opposite to the previous corridor's direction...
        if (!firstCorridor && direction == oppositeDirection)
        {
            // Rotate the direction 90 degrees clockwise (North becomes East, East becomes South, etc).
            // This is a more broken down version of the opposite direction operation above but instead of adding 2 we're adding 1.
            // This means instead of rotating 180 (the opposite direction) we're rotating 90.
            int directionInt = (int)direction;
            directionInt++;
            directionInt = directionInt % 4;
            direction    = (Direction)directionInt;
        }

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

        // Create a cap for how long the length can be (this will be changed based on the direction and position).
        int maxLength = length.m_Max;

        FloorType = TileType3D.Floor;

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

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

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

        case Direction.East:
            startXPos = room.xPos + room.roomWidth;
            startYPos = Random.Range(room.yPos, room.yPos + room.roomHeight - 1);
            maxLength = columns - startXPos - roomWidth.m_Min;
            break;

        case Direction.South:
            startXPos = Random.Range(room.xPos, room.xPos + room.roomWidth);
            startYPos = room.yPos;
            maxLength = startYPos - roomHeight.m_Min;
            break;

        case Direction.West:
            startXPos = room.xPos;
            startYPos = Random.Range(room.yPos, room.yPos + room.roomHeight);
            maxLength = startXPos - roomWidth.m_Min;
            break;
        }

        // We clamp the length of the corridor to make sure it doesn't go off the board.
        corridorLength = Mathf.Clamp(corridorLength, 1, maxLength);
    }
Example #6
0
    void CreateRoomsAndCorridors()
    {
        // Create the rooms array with a random size.
        int TotalRooms;
        int RoomPerLvl;
        int RoomTotalLoop;

        RoomTotalLoop = 0;

        RoomPerLvl = numRooms.Random;
        //TotalRooms = (RoomPerLvl * Depth) + 3 + (1+(2*(Depth-1)));
        TotalRooms = (RoomPerLvl * Depth) + 3;
        Debug.Log("Total Rooms: " + TotalRooms);
        Debug.Log("Total Room per LVL " + RoomPerLvl);

        rooms = new Room3D[TotalRooms];

        // There should be one less corridor than there is rooms.
        corridors = new Corridor3D[TotalRooms - 1];

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

        //Create Entry Room
        rooms[0].CreateEntry(1, 1, columns, rows);
        corridors[0].BuildEntryCorridor(rooms[0], 5);
        RoomTotalLoop++;
        rooms[1]     = new Room3D();
        corridors[1] = new Corridor3D();
        rooms[1].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[0], 1, TileType3D.Floor);
        corridors[1].SetupCorridor(rooms[1], corridorLength, roomWidth, roomHeight, columns, rows, false, 1);

        RoomTotalLoop++;
        rooms[2]     = new Room3D();
        corridors[2] = new Corridor3D();
        rooms[2].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[1], 1, TileType3D.Floor);
        corridors[2].SetupCorridor(rooms[2], corridorLength, roomWidth, roomHeight, columns, rows, false, 1);

        // Setup the first room, there is no previous corridor so we do not use one.
        //rooms[0].SetupRoom(roomWidth, roomHeight, columns, rows);

        // Setup the first corridor using the first room.
        //corridors[0].SetupCorridor(rooms[0], corridorLength, roomWidth, roomHeight, columns, rows, true);
        for (int i = 0; i < RoomPerLvl; i++)
        {
            // Create a room.
            RoomTotalLoop++;
            rooms[RoomTotalLoop] = new Room3D();
            //Debug.Log("Room " + RoomTotalLoop);

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

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

                // Setup the corridor based on the room that was just created.
                corridors[RoomTotalLoop].SetupCorridor(rooms[RoomTotalLoop], corridorLength, roomWidth, roomHeight, columns, rows, false, 1);
            }
        }
        // Create an extra room on current level and next level down. Both will be classed as stair undef.

        for (int d = 1; d < Depth; d++)
        {
            for (int i = 0; i < RoomPerLvl; i++)
            {
                // Create a room.

                RoomTotalLoop++;
                rooms[RoomTotalLoop] = new Room3D();
                //Debug.Log("Depth " + d + " Room " + RoomTotalLoop);
                // Setup the room based on the previous corridor.
                rooms[RoomTotalLoop].SetupRoom(roomWidth, roomHeight, columns, rows, corridors[RoomTotalLoop - 1], d + 1, TileType3D.Floor);

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

                    // Setup the corridor based on the room that was just created.
                    corridors[RoomTotalLoop].SetupCorridor(rooms[RoomTotalLoop], corridorLength, roomWidth, roomHeight, columns, rows, false, d + 1);
                }
            }
            //Create same room at current level and next level for down stairs.
        }
    }