Exemplo n.º 1
0
 public EntrancePositions(EntrancePositions copy)
 {
     westEntrance = copy.westEntrance;
     eastEntrance = copy.eastEntrance;
     southEntrance = copy.southEntrance;
     northEntrance = copy.northEntrance;
 }
Exemplo n.º 2
0
 public EntrancePositions(EntrancePosition west, EntrancePosition east, EntrancePosition south, EntrancePosition north)
 {
     westEntrance = west;
     eastEntrance = east;
     southEntrance = south;
     northEntrance = north;
 }
Exemplo n.º 3
0
    private bool TryCreateRoom(EntrancePosition entrance, Room room, ref Direction direction)
    {
        if (entrance.cardinalDirection == Direction.north && room.GetAvailableEntranceDirection(Direction.south) == true)
        {
            List <Vector2Int> roomEntrancesCopy = CopyArray(room.entrancesS);

            bool whileLoop = true;
            while (whileLoop == true)
            {
                if (roomEntrancesCopy.Count == 0)
                {
                    return(false);
                }

                int roomEntranceIndex = Random.Range(0, roomEntrancesCopy.Count - 1);

                int xOffset = entrance.position.x - roomEntrancesCopy[roomEntranceIndex].x;
                int yOffset = entrance.position.y + 3;

                offset = new Vector2Int(xOffset, yOffset);

                if (LoadRoom.CanCreateRoom(room, offset, tilemap))
                {
                    direction = Direction.north;
                    return(true);
                }

                roomEntrancesCopy.RemoveAt(roomEntranceIndex);
            }
        }
        else if (entrance.cardinalDirection == Direction.east && room.GetAvailableEntranceDirection(Direction.west) == true)
        {
            List <Vector2Int> roomEntrancesCopy = CopyArray(room.entrancesW);

            bool whileLoop = true;
            while (whileLoop == true)
            {
                if (roomEntrancesCopy.Count == 0)
                {
                    return(false);
                }

                int roomEntranceIndex = Random.Range(0, roomEntrancesCopy.Count - 1);

                int xOffset = entrance.position.x + 3;
                int yOffset = entrance.position.y - roomEntrancesCopy[roomEntranceIndex].y;

                offset = new Vector2Int(xOffset, yOffset);

                if (LoadRoom.CanCreateRoom(room, offset, tilemap))
                {
                    direction = Direction.east;
                    return(true);
                }

                roomEntrancesCopy.RemoveAt(roomEntranceIndex);
            }
        }
        else if (entrance.cardinalDirection == Direction.south && room.GetAvailableEntranceDirection(Direction.north) == true)
        {
            List <Vector2Int> roomEntrancesCopy = CopyArray(room.entrancesN);

            bool whileLoop = true;
            while (whileLoop == true)
            {
                if (roomEntrancesCopy.Count == 0)
                {
                    return(false);
                }

                int roomEntranceIndex = Random.Range(0, roomEntrancesCopy.Count - 1);

                int xOffset = entrance.position.x - roomEntrancesCopy[roomEntranceIndex].x;
                int yOffset = entrance.position.y - 2 - room.roomHeight;

                offset = new Vector2Int(xOffset, yOffset);

                if (LoadRoom.CanCreateRoom(room, offset, tilemap))
                {
                    direction = Direction.south;
                    return(true);
                }

                roomEntrancesCopy.RemoveAt(roomEntranceIndex);
            }
        }
        else if (entrance.cardinalDirection == Direction.west && room.GetAvailableEntranceDirection(Direction.east) == true)
        {
            List <Vector2Int> roomEntrancesCopy = CopyArray(room.entrancesN);

            bool whileLoop = true;
            while (whileLoop == true)
            {
                if (roomEntrancesCopy.Count == 0)
                {
                    return(false);
                }

                int roomEntranceIndex = Random.Range(0, roomEntrancesCopy.Count - 1);

                int xOffset = entrance.position.x - 2 - room.roomWidth;
                int yOffset = entrance.position.y - roomEntrancesCopy[roomEntranceIndex].y + 1;

                offset = new Vector2Int(xOffset, yOffset);

                if (LoadRoom.CanCreateRoom(room, offset, tilemap))
                {
                    direction = Direction.west;
                    return(true);
                }

                roomEntrancesCopy.RemoveAt(roomEntranceIndex);
            }
        }
        return(false);
    }