Esempio n. 1
0
    public bool GetDoor(RoomConnections door, out Vector2Int location)
    {
        if ((door & RoomConnections.Top) != 0)
        {
            location = new Vector2Int(m_DoorCentre.x, FullExtent.z - 1);
            return(true);
        }
        if ((door & RoomConnections.Bottom) != 0)
        {
            location = new Vector2Int(m_DoorCentre.x, 0);
            return(true);
        }
        if ((door & RoomConnections.Left) != 0)
        {
            location = new Vector2Int(0, m_DoorCentre.y);
            return(true);
        }
        if ((door & RoomConnections.Right) != 0)
        {
            location = new Vector2Int(FullExtent.x - 1, m_DoorCentre.y);
            return(true);
        }

        location = Vector2Int.zero;
        return(false);
    }
Esempio n. 2
0
 public PlacedRoomInfo(RoomSettings settings, Vector3Int centre, Vector3Int extents, RoomConnections connection = RoomConnections.None)
 {
     m_Settings   = settings;
     m_Centre     = centre;
     m_Extents    = extents;
     m_Connection = connection;
 }
Esempio n. 3
0
    public static PlacedRoomInfo FindRoomSlot(RoomSettings settings, List <PlacedRoomInfo> allRooms)
    {
        Vector3Int centre  = new Vector3Int();
        Vector3Int extents = settings.RandomExtents();

        int randomIndex = Random.Range(0, allRooms.Count - 1);

        for (int i = 0; i < allRooms.Count; ++i)
        {
            int index = (randomIndex + i) % allRooms.Count;

            RoomConnections connection = allRooms[index].FindOpenSlot(allRooms, ref centre, extents);
            if (connection != RoomConnections.None)
            {
                return(new PlacedRoomInfo(settings, centre, extents, connection));
            }
        }

        Debug.Assert(false, "Failed to find a room slot!");
        return(null);
    }
Esempio n. 4
0
    private bool CheckForOpenSlot(List <PlacedRoomInfo> allRooms, RoomConnections connection, ref Vector3Int centre, Vector3Int extents)
    {
        if ((m_Connection & connection) != 0)
        {
            return(false);
        }

        switch (connection)
        {
        case RoomConnections.Top:
            centre = m_Centre + new Vector3Int(0, 0, (m_Extents.z + extents.z) / 2);
            break;

        case RoomConnections.Bottom:
            centre = m_Centre - new Vector3Int(0, 0, (m_Extents.z + extents.z) / 2);
            break;

        case RoomConnections.Right:
            centre = m_Centre + new Vector3Int((m_Extents.x + extents.x) / 2, 0, 0);
            break;

        case RoomConnections.Left:
            centre = m_Centre - new Vector3Int((m_Extents.x + extents.x) / 2, 0, 0);
            break;
        }

        foreach (PlacedRoomInfo roomInfo in allRooms)
        {
            if (roomInfo != this && roomInfo.Overlaps(centre, extents))
            {
                return(false);
            }
        }

        m_Connection |= connection;
        return(true);
    }
Esempio n. 5
0
    public RoomGeneratorHelper(RoomSettings settings, Vector3Int targetExtent, RoomConnections connections)
    {
        m_Settings    = settings;
        m_Connections = connections;
        m_NoiseMap    = new PerlinNoise(Random.Range(int.MinValue, int.MaxValue));

        // Decide room size
        m_TraversableExtent = new Vector3Int(
            targetExtent.x - settings.m_Padding.x * 2,
            targetExtent.y,
            targetExtent.z - settings.m_Padding.z * 2
            );

        // Populate voxel data
        Vector3Int fullExtent = FullExtent;
        VoxelData  voxelData  = VoxelData.New(fullExtent.x, fullExtent.y, fullExtent.z);

        m_DoorCentre = new Vector2Int(fullExtent.x / 2, fullExtent.z / 2);

        for (int x = 0; x < fullExtent.x; ++x)
        {
            for (int z = 0; z < fullExtent.z; ++z)
            {
                int height = GetHeight(x, z);

                // Try to create a placement spot here
                if (x % m_Settings.m_PlacementFrequency == 0 && z % m_Settings.m_PlacementFrequency == 0)
                {
                    if (height == m_Settings.m_FloorHeight)
                    {
                        m_AccessibleSpots.Add(new Vector3Int(x, height, z));
                    }
                    else if (height == m_TraversableExtent.y)
                    {
                        m_InaccessibleSpots.Add(new Vector3Int(x, height, z));
                    }
                }


                for (int y = 0; y <= height; ++y)
                {
                    uint[] coloursTable = m_Settings.m_ColourIndices;

                    float rawNoise = GetRawNoise(x, z, m_Settings.m_TextureHeightFrequency, m_Settings.m_TextureNoiseScale);

                    if (rawNoise <= 0.3f && m_Settings.m_LowNoiseColourIndices.Length != 0)
                    {
                        coloursTable = m_Settings.m_LowNoiseColourIndices;
                    }
                    else if (rawNoise >= 0.6f && m_Settings.m_HighNoiseColourIndices.Length != 0)
                    {
                        coloursTable = m_Settings.m_HighNoiseColourIndices;
                    }

                    int  colourLookupIdx = Mathf.Clamp(height - y, 0, coloursTable.Length - 1);
                    uint colour          = coloursTable[colourLookupIdx];

                    voxelData.SetVoxel(new Voxel(colour), x, y, z);
                }
            }
        }

        m_Mesh      = voxelData.GenerateMesh(Vector3.zero, settings.m_Scale);
        m_Mesh.name = "GeneratedMesh";
    }
Esempio n. 6
0
    public static RoomInstance PlaceRoom(RoomInstance prefab, bool isBossRoom, FloorSettings floorSettings, RoomSettings roomSettings, Vector3Int location, Vector3Int extents, RoomConnections connection)
    {
        RoomInstance instance = Instantiate(prefab, location, Quaternion.identity);

        instance.m_Connections   = connection;
        instance.m_IsBossRoom    = isBossRoom;
        instance.m_RoomSettings  = roomSettings;
        instance.m_FloorSettings = floorSettings;

        RoomGeneratorHelper generator = new RoomGeneratorHelper(roomSettings, extents, connection);

        instance.SetupRoom(generator, extents);
        return(instance);
    }