// get the room/rooms
    public Rect GetRoom()
    {
        // if the node has no children then return the room
        if (IsLeaf())
        {
            return(room);
        }

        // if the node has child nodes then get the them
        if (left != null)
        {
            Rect leftRoom = left.GetRoom();
            if (leftRoom.x != -1)
            {
                return(leftRoom);
            }
        }
        if (right != null)
        {
            Rect rightRoom = right.GetRoom();
            if (rightRoom.x != -1)
            {
                return(rightRoom);
            }
        }

        // workaround non nullable structs
        return(new Rect(-1, -1, 0, 0));
    }
Exemplo n.º 2
0
        public Rect GetRoom()
        {
            if (IAmLeaf())
            {
                return(room);
            }
            if (left != null)
            {
                Rect lroom = left.GetRoom();
                if (lroom.x != -1)
                {
                    return(lroom);
                }
            }
            if (right != null)
            {
                Rect rroom = right.GetRoom();
                if (rroom.x != -1)
                {
                    return(rroom);
                }
            }

            // workaround non nullable structs
            return(new Rect(-1, -1, 0, 0));
        }
Exemplo n.º 3
0
        public Rect GetRoom()
        {
            if (IAmLeaf())
            {
                Debug.Log(room);
                return(room);
            }
            if (left != null)
            {
                Rect lroom = left.GetRoom();
                if (lroom.x != -1)
                {
                    return(lroom);
                }
            }
            if (right != null)
            {
                Rect rroom = right.GetRoom();
                if (rroom.x != -1)
                {
                    return(rroom);
                }
            }

            return(new Rect(-1, -1, 0, 0));
        }
        public Vector2 randRoomPoint(SubDungeon room)
        {
            Rect    rect  = room.GetRoom();
            Vector2 point = new Vector2((int)Random.Range(rect.x + 1, rect.xMax - 1), (int)Random.Range(rect.y + 1, rect.yMax - 1));

            return(point);
        }
Exemplo n.º 5
0
        public void CreateCorridorBetween(SubDungeon left, SubDungeon right)
        {
            Rect lroom = left.GetRoom();
            Rect rroom = right.GetRoom();

            Debug.Log("Creating corridor(s) between " + left.debugId + "(" + lroom + ") and " + right.debugId + " (" + rroom + ")");

            // attach the corridor to a random point in each room
            Vector2 lpoint = new Vector2((int)Random.Range(lroom.x + 1, lroom.xMax - 1), (int)Random.Range(lroom.y + 1, lroom.yMax - 1));
            Vector2 rpoint = new Vector2((int)Random.Range(rroom.x + 1, rroom.xMax - 1), (int)Random.Range(rroom.y + 1, rroom.yMax - 1));

            // always be sure that left point is on the left to simplify the code
            if (lpoint.x > rpoint.x)
            {
                Vector2 temp = lpoint;
                lpoint = rpoint;
                rpoint = temp;
            }

            int w = (int)(lpoint.x - rpoint.x);
            int h = (int)(lpoint.y - rpoint.y);

            Debug.Log("lpoint: " + lpoint + ", rpoint: " + rpoint + ", w: " + w + ", h: " + h);

            // if the points are not aligned horizontally
            if (w != 0)
            {
                // choose at random to go horizontal then vertical or the opposite
                if (Random.Range(0, 1) > 2)
                {
                    // add a corridor to the right
                    corridors.Add(new Rect(lpoint.x, lpoint.y, Mathf.Abs(w) + 1, corridorWidth));

                    // if left point is below right point go up
                    // otherwise go down
                    if (h < 0)
                    {
                        corridors.Add(new Rect(rpoint.x, lpoint.y, corridorWidth, Mathf.Abs(h)));
                    }
                    else
                    {
                        corridors.Add(new Rect(rpoint.x, lpoint.y, corridorWidth, -Mathf.Abs(h)));
                    }
                }
                else
                {
                    // go up or down
                    if (h < 0)
                    {
                        corridors.Add(new Rect(lpoint.x, lpoint.y, corridorWidth, Mathf.Abs(h)));
                    }
                    else
                    {
                        corridors.Add(new Rect(lpoint.x, rpoint.y, corridorWidth, Mathf.Abs(h)));
                    }

                    // then go right
                    corridors.Add(new Rect(lpoint.x, rpoint.y, Mathf.Abs(w) + 1, corridorWidth));
                }
            }
            else
            {
                // if the points are aligned horizontally
                // go up or down depending on the positions
                if (h < 0)
                {
                    corridors.Add(new Rect((int)lpoint.x, (int)lpoint.y, corridorWidth, Mathf.Abs(h)));
                }
                else
                {
                    corridors.Add(new Rect((int)rpoint.x, (int)rpoint.y, corridorWidth, Mathf.Abs(h)));
                }
            }

            Debug.Log("Corridors: ");
            foreach (Rect corridor in corridors)
            {
                Debug.Log("corridor: " + corridor);
            }
        }
    // creates a corridor, connecting two rooms together
    public void CreateCorridorBetween(SubDungeon left, SubDungeon right)
    {
        //get the rooms to be connected
        Rect leftRoom  = left.GetRoom();
        Rect rightRoom = right.GetRoom();

        // create the corridor at a random point in each room
        Vector2 leftPosition  = new Vector2((int)Random.Range(leftRoom.x + 1, leftRoom.xMax - 1), (int)Random.Range(leftRoom.y + 1, leftRoom.yMax - 1));
        Vector2 rightPosition = new Vector2((int)Random.Range(rightRoom.x + 1, rightRoom.xMax - 1), (int)Random.Range(rightRoom.y + 1, rightRoom.yMax - 1));

        // if the left point is greater than the right point
        // swap them to make the code more understandable
        if (leftPosition.x > rightPosition.x)
        {
            Vector2 temp = leftPosition;
            leftPosition  = rightPosition;
            rightPosition = temp;
        }

        // checks how well aligned the two vector positions are
        int horizontalAlignment = (int)(leftPosition.x - rightPosition.x);
        int verticalAlignment   = (int)(leftPosition.y - rightPosition.y);

        // if the points are not aligned horizontally
        if (horizontalAlignment != 0)
        {
            // randomly choose to go horizontal then vertical or the opposite
            if (Random.Range(0, 1) > 2)
            {
                // add a corridor to the right
                corridors.Add(new Rect(leftPosition.x, leftPosition.y, Mathf.Abs(horizontalAlignment) + 1, 1));

                // if left point is below right point go up
                if (verticalAlignment < 0)
                {
                    corridors.Add(new Rect(rightPosition.x, leftPosition.y, 1, Mathf.Abs(verticalAlignment)));
                }
                // otherwise go down
                else
                {
                    corridors.Add(new Rect(rightPosition.x, leftPosition.y, 1, -Mathf.Abs(verticalAlignment)));
                }
            }
            else
            {
                // go up
                if (verticalAlignment < 0)
                {
                    corridors.Add(new Rect(leftPosition.x, leftPosition.y, 1, Mathf.Abs(verticalAlignment)));
                }
                // or down
                else
                {
                    corridors.Add(new Rect(leftPosition.x, rightPosition.y, 1, Mathf.Abs(verticalAlignment)));
                }

                // then go right
                corridors.Add(new Rect(leftPosition.x, rightPosition.y, Mathf.Abs(horizontalAlignment) + 1, 1));
            }
        }
        else
        {
            // if the vectors are aligned horizontally
            // go up or down depending on the positions
            if (verticalAlignment < 0)
            {
                corridors.Add(new Rect((int)leftPosition.x, (int)leftPosition.y, 1, Mathf.Abs(verticalAlignment)));
            }
            else
            {
                corridors.Add(new Rect((int)rightPosition.x, (int)rightPosition.y, 1, Mathf.Abs(verticalAlignment)));
            }
        }
    }
Exemplo n.º 7
0
        public void CreateCorridorBetween(SubDungeon left, SubDungeon right)
        {
            _totalCorridorIdCount++;
            Rect lroom = left.GetRoom();
            Rect rroom = right.GetRoom();

            // attach the corridor to a random point in each room
            Vector2 lpoint = new Vector2((int)Random.Range(lroom.x + 1, lroom.xMax - 1), (int)Random.Range(lroom.y + 1, lroom.yMax - 1));
            Vector2 rpoint = new Vector2((int)Random.Range(rroom.x + 1, rroom.xMax - 1), (int)Random.Range(rroom.y + 1, rroom.yMax - 1));

            // Be sure that left point is on the left to simplify the code
            if (lpoint.x > rpoint.x)
            {
                Vector2 temp = lpoint;
                lpoint = rpoint;
                rpoint = temp;
            }

            int w = (int)(lpoint.x - rpoint.x);
            int h = (int)(lpoint.y - rpoint.y);

            // if the points are not aligned horizontally
            if (w != 0)
            {
                // choose at random to go horizontal then vertical or the opposite
                if (Random.Range(0, 1) > 2)
                {
                    // add a corridor to the right
                    corridors.Add(new DungeonCorridor(new Rect(lpoint.x, lpoint.y, Mathf.Abs(w) + 1, 1), _totalCorridorIdCount));
                    // if left point is below right point go up
                    // otherwise go down
                    if (h < 0)
                    {
                        corridors.Add(new DungeonCorridor(new Rect(rpoint.x, lpoint.y, 1, Mathf.Abs(h)), _totalCorridorIdCount));
                    }
                    else
                    {
                        corridors.Add(new DungeonCorridor(new Rect(rpoint.x, lpoint.y, 1, -Mathf.Abs(h)), _totalCorridorIdCount));
                    }
                }
                else
                {
                    // go up or down
                    if (h < 0)
                    {
                        corridors.Add(new DungeonCorridor(new Rect(lpoint.x, lpoint.y, 1, Mathf.Abs(h)), _totalCorridorIdCount));
                    }
                    else
                    {
                        corridors.Add(new DungeonCorridor(new Rect(lpoint.x, rpoint.y, 1, Mathf.Abs(h)), _totalCorridorIdCount));
                    }

                    // then go right
                    corridors.Add(new DungeonCorridor(new Rect(lpoint.x, rpoint.y, Mathf.Abs(w) + 1, 1), _totalCorridorIdCount));
                }
            }
            else
            {
                // if the points are aligned horizontally
                // go up or down depending on the positions
                if (h < 0)
                {
                    corridors.Add(new DungeonCorridor(new Rect((int)lpoint.x, (int)lpoint.y, 1, Mathf.Abs(h)), _totalCorridorIdCount));
                }
                else
                {
                    corridors.Add(new DungeonCorridor(new Rect((int)rpoint.x, (int)rpoint.y, 1, Mathf.Abs(h)), _totalCorridorIdCount));
                }
            }
        }
Exemplo n.º 8
0
        //Определить размер и положение коридора между комнатами двух узлов
        public void CreateCorridorBetween(SubDungeon left, SubDungeon right)
        {
            Rect lroom = left.GetRoom();
            Rect rroom = right.GetRoom();

            //Debug.Log("Creating corridor(s) between " + left.debugId + "(" + lroom + ") and " + right.debugId + " (" + rroom + ")");

            Vector2 lpoint = new Vector2((int)Random.Range(lroom.x + 2, lroom.xMax - 2), (int)Random.Range(lroom.y + 2, lroom.yMax - 2));
            Vector2 rpoint = new Vector2((int)Random.Range(rroom.x + 2, rroom.xMax - 2), (int)Random.Range(rroom.y + 2, rroom.yMax - 2));

            if (lpoint.x > rpoint.x)
            {
                Vector2 temp = lpoint;
                lpoint = rpoint;
                rpoint = temp;
            }

            int w = (int)(lpoint.x - rpoint.x);
            int h = (int)(lpoint.y - rpoint.y);

            //Debug.Log("lpoint: " + lpoint + ", rpoint: " + rpoint + ", w: " + w + ", h: " + h);

            if (w != 0)
            {
                if (Random.Range(0, 1) > 2)
                {
                    corridors.Add(new Rect(lpoint.x, lpoint.y, Mathf.Abs(w) + 1, 1));
                    if (h < 0)
                    {
                        corridors.Add(new Rect(rpoint.x, lpoint.y, 1, Mathf.Abs(h)));
                    }
                    else
                    {
                        corridors.Add(new Rect(rpoint.x, lpoint.y, 1, -Mathf.Abs(h)));
                    }
                }
                else
                {
                    if (h < 0)
                    {
                        corridors.Add(new Rect(lpoint.x, lpoint.y, 1, Mathf.Abs(h)));
                    }
                    else
                    {
                        corridors.Add(new Rect(lpoint.x, rpoint.y, 1, Mathf.Abs(h)));
                    }
                    corridors.Add(new Rect(lpoint.x, rpoint.y, Mathf.Abs(w) + 1, 1));
                }
            }
            else
            {
                if (h < 0)
                {
                    corridors.Add(new Rect((int)lpoint.x, (int)lpoint.y, 1, Mathf.Abs(h)));
                }
                else
                {
                    corridors.Add(new Rect((int)rpoint.x, (int)rpoint.y, 1, Mathf.Abs(h)));
                }
            }

            /*Debug.Log("Corridors: ");
             * foreach (Rect corridor in corridors)
             * {
             *  Debug.Log("corridor: " + corridor);
             * }*/
        }
Exemplo n.º 9
0
    // metódus ami a bal és jobb fiút összekapcsolja egy folyosóval
    public void CreateCorridorBetween(SubDungeon left, SubDungeon right)
    {
        Rect lroom = left.GetRoom();
        Rect rroom = right.GetRoom();

        // kiválasz egy random pontot a bal és jobb szobán is ahol össze lesznek kapcsolva
        Vector2 lpoint = new Vector2((int)Random.Range(lroom.x + 1, lroom.xMax - 1), (int)Random.Range(lroom.y + 1, lroom.yMax - 1));
        Vector2 rpoint = new Vector2((int)Random.Range(rroom.x + 1, rroom.xMax - 1), (int)Random.Range(rroom.y + 1, rroom.yMax - 1));

        // ha a jobb szoba kapcsolódási ponjának az x koordinátája kisebb, mint a bal szobájé, azaz balrábbb van, akkor az lesz a bal kapcsolódási pont
        if (lpoint.x > rpoint.x)
        {
            Vector2 temp = lpoint;
            lpoint = rpoint;
            rpoint = temp;
        }

        int w = (int)(lpoint.x - rpoint.x);
        int h = (int)(lpoint.y - rpoint.y);


        // if the points are not aligned horizontally
        if (w != 0)
        {
            // choose at random to go horizontal then vertical or the opposite
            if (Random.Range(0, 1) > 2)
            {
                // add a corridor to the right
                corridors.Add(new Rect(lpoint.x, lpoint.y, Mathf.Abs(w) + 1, 1));

                // if left point is below right point go up
                // otherwise go down
                if (h < 0)
                {
                    corridors.Add(new Rect(rpoint.x, lpoint.y, 1, Mathf.Abs(h)));
                }
                else
                {
                    corridors.Add(new Rect(rpoint.x, lpoint.y, 1, -Mathf.Abs(h)));
                }
            }
            else
            {
                // go up or down
                if (h < 0)
                {
                    corridors.Add(new Rect(lpoint.x, lpoint.y, 1, Mathf.Abs(h)));
                }
                else
                {
                    corridors.Add(new Rect(lpoint.x, rpoint.y, 1, Mathf.Abs(h)));
                }

                // then go right
                corridors.Add(new Rect(lpoint.x, rpoint.y, Mathf.Abs(w) + 1, 1));
            }
        }
        else
        {
            // if the points are aligned horizontally
            // go up or down depending on the positions
            if (h < 0)
            {
                corridors.Add(new Rect((int)lpoint.x, (int)lpoint.y, 1, Mathf.Abs(h)));
            }
            else
            {
                corridors.Add(new Rect((int)rpoint.x, (int)rpoint.y, 1, Mathf.Abs(h)));
            }
        }
    }
Exemplo n.º 10
0
        public void CreateCorridorBetween(SubDungeon left, SubDungeon right)
        {
            Rect lroom = left.GetRoom();
            Rect rroom = right.GetRoom();

            Debug.Log("Creating corridor(s) between " + left.debugId + "(" + lroom + ") and " + right.debugId + " (" + rroom + ")");


            Vector2 lpoint = new Vector2((int)Random.Range(lroom.x + 1, lroom.xMax - 1), (int)Random.Range(lroom.y + 1, lroom.yMax - 1));
            Vector2 rpoint = new Vector2((int)Random.Range(rroom.x + 1, rroom.xMax - 1), (int)Random.Range(rroom.y + 1, rroom.yMax - 1));


            if (lpoint.x > rpoint.x)
            {
                Vector2 temp = lpoint;
                lpoint = rpoint;
                rpoint = temp;
            }

            int w = (int)(lpoint.x - rpoint.x);
            int h = (int)(lpoint.y - rpoint.y);


            if (w != 0)
            {
                if (Random.Range(0, 1) > 2)
                {
                    corridors.Add(new Rect(lpoint.x, lpoint.y, Mathf.Abs(w) + 1, 1));

                    if (h < 0)
                    {
                        corridors.Add(new Rect(rpoint.x, lpoint.y, 1, Mathf.Abs(h)));
                    }
                    else
                    {
                        corridors.Add(new Rect(rpoint.x, lpoint.y, 1, -Mathf.Abs(h)));
                    }
                }
                else
                {
                    if (h < 0)
                    {
                        corridors.Add(new Rect(lpoint.x, lpoint.y, 1, Mathf.Abs(h)));
                    }
                    else
                    {
                        corridors.Add(new Rect(lpoint.x, rpoint.y, 1, Mathf.Abs(h)));
                    }


                    corridors.Add(new Rect(lpoint.x, rpoint.y, Mathf.Abs(w) + 1, 1));
                }
            }
            else
            {
                if (h < 0)
                {
                    corridors.Add(new Rect((int)lpoint.x, (int)lpoint.y, 1, Mathf.Abs(h)));
                }
                else
                {
                    corridors.Add(new Rect((int)rpoint.x, (int)rpoint.y, 1, Mathf.Abs(h)));
                }
            }
        }
Exemplo n.º 11
0
        public void CreateCorridorBetween(SubDungeon left, SubDungeon right)
        {
            Rect lroom = left.GetRoom();
            Rect rroom = right.GetRoom();

            //Debug.Log("Creating corridor(s) between " + left.debugId + "(" + lroom + ") and " + right.debugId + " (" + rroom + ")");

            // attach the corridor to a random point in each room
            Vector2 lpoint, rpoint;

            do
            {
                lpoint = new Vector2((int)Random.Range(lroom.x + 1, lroom.xMax - 1), (int)Random.Range(lroom.y + 1, lroom.yMax - 1));
            } while (lpoint.x >= left.removedPiece.x && lpoint.x <= left.removedPiece.xMax && lpoint.y >= left.removedPiece.y && lpoint.y <= left.removedPiece.yMax);

            do
            {
                rpoint = new Vector2((int)Random.Range(rroom.x + 1, rroom.xMax - 1), (int)Random.Range(rroom.y + 1, rroom.yMax - 1));
            } while (rpoint.x >= right.removedPiece.x && rpoint.x <= right.removedPiece.xMax && rpoint.y >= right.removedPiece.y && rpoint.y <= right.removedPiece.yMax);

            // always be sure that left point is on the left to simplyfy code
            if (lpoint.x > rpoint.x)
            {
                Vector2 temp = lpoint;
                lpoint = rpoint;
                rpoint = temp;
            }

            int w = (int)(lpoint.x - rpoint.x);
            int h = (int)(lpoint.y - rpoint.y);

            int         thickness   = Random.Range(1, 4);                    // getting a random thickness
            List <Rect> connections = (thickness > 1) ? corridors : bridges; // if the tickness > 1, it is a corridor; otherwise, it's a bridge

            //Debug.Log("lpoint: " + lpoint + ", rpoint: " + rpoint + ", w: " + w + ", h: " + h);

            // if the points are not aligned horizontally
            if (w != 0)
            {
                if (Random.Range(0, 2) > 0)
                {
                    // add a corridor to the right
                    connections.Add(new Rect(lpoint.x, lpoint.y, Mathf.Abs(w) + 1, thickness));

                    // if left point is below right point go up
                    // otherwise go down
                    if (h < 0)
                    {
                        connections.Add(new Rect(rpoint.x, lpoint.y, thickness, Mathf.Abs(h)));
                    }
                    else
                    {
                        connections.Add(new Rect(rpoint.x, rpoint.y, thickness, Mathf.Abs(h)));
                    }
                }
                else
                {
                    // go up or down
                    if (h < 0)
                    {
                        connections.Add(new Rect(lpoint.x, lpoint.y, thickness, Mathf.Abs(h)));
                    }
                    else
                    {
                        connections.Add(new Rect(lpoint.x, rpoint.y, thickness, Mathf.Abs(h)));
                    }

                    // then go right
                    connections.Add(new Rect(lpoint.x, rpoint.y, Mathf.Abs(w) + 1, thickness));
                }
            }
            else
            {
                // if the points are aligned horizontally
                // go up or down depending on the positions
                if (h < 0)
                {
                    connections.Add(new Rect((int)lpoint.x, (int)lpoint.y, thickness, Mathf.Abs(h)));
                }
                else
                {
                    connections.Add(new Rect((int)rpoint.x, (int)rpoint.y, thickness, Mathf.Abs(h)));
                }
            }

            /*Debug.Log("Corridors: ");
             * foreach(Rect corridor in corridors) {
             *      Debug.Log("corridor: " + corridor);
             * }*/
        }