Beispiel #1
0
    /// <summary>
    /// Divide the room in a random Horizontal positions (random X value)
    /// </summary>
    void DivideVertically()
    {
        //We are able to create a room
        BSPDungeon dungeon = GameObject.FindObjectOfType <BSPDungeon>();
        float      minSize = dungeon.GetMinSize();

        if (m_width > minSize)
        {
            //We are able to create a room
            float randomX = Random.Range(minSize, (int)m_width - minSize);
            m_divideH     = false;
            m_divisionPos = randomX;

            //Divide and create two new rooms
            float   lWidth   = randomX;
            float   rWidth   = m_width - randomX;
            Vector3 leftMost = m_center - new Vector3(m_width * 0.5f, 0.0f, 0.0f);

            Vector3 lCenter = leftMost + new Vector3(lWidth * 0.5f, 0.0f, 0.0f);
            Vector3 rCenter = leftMost + new Vector3(lWidth + rWidth * 0.5f, 0.0f, 0.0f);

            CreateChild(lCenter, lWidth, m_height, true);
            CreateChild(rCenter, rWidth, m_height, false);
            m_lChild.GetComponent <Room>().SetBrother(m_rChild);
            m_rChild.GetComponent <Room>().SetBrother(m_lChild);
        }
    }
Beispiel #2
0
    /// <summary>
    /// Divide the room in a random Horizontal positions (random Y value)
    /// </summary>
    void DivideHorizontally()
    {
        //Calculate offset

        //We are able to create a room
        BSPDungeon dungeon = GameObject.FindObjectOfType <BSPDungeon>();
        float      minSize = dungeon.GetMinSize();

        if (m_height > minSize)
        {
            float randomY = Random.Range(minSize, (int)m_height - minSize);
            m_divideH     = true;
            m_divisionPos = m_height - randomY;

            //Divide and create two new rooms
            Vector3 bottom  = m_center - new Vector3(0.0f, m_height * 0.5f, 0.0f);
            float   lHeight = randomY;
            float   rHeight = m_height - randomY;

            Vector3 upCenter   = bottom + new Vector3(0.0f, rHeight + lHeight * 0.5f, 0.0f);
            Vector3 downCenter = bottom + new Vector3(0.0f, rHeight * 0.5f, 0.0f);

            CreateChild(upCenter, m_width, lHeight, true);
            CreateChild(downCenter, m_width, rHeight, false);
            m_lChild.GetComponent <Room>().SetBrother(m_rChild);
            m_rChild.GetComponent <Room>().SetBrother(m_lChild);
        }
    }