Exemplo n.º 1
0
        RL CountSteps(RL x, int n, int[] dr, int notNoneIndex, bool isCross)
        {
            var steps = new RL(0, 0);

            if (rooms[n, dr[n]][(int)Index.rightDoor] == 0)
            {
                int maxLeft = (isCross) ? Math.Max(rooms[n, dr[n]][(int)Index.topDoor], rooms[n, dr[n]][(int)Index.bottomDoor]) : rooms[n, dr[n]][notNoneIndex];
                steps.R = maxLeft - x.L + 1;
            }
            else if (rooms[n, dr[n]][(int)Index.leftDoor] == 0)
            {
                int minLeft = (isCross) ? Math.Min(rooms[n, dr[n]][(int)Index.topDoor], rooms[n, dr[n]][(int)Index.bottomDoor]) : rooms[n, dr[n]][notNoneIndex];
                steps.L = x.R - minLeft + 1;
            }
            else
            {
                steps.R = rooms[n, dr[n]][notNoneIndex] - x.L;
                steps.L = x.R - rooms[n, dr[n]][notNoneIndex];
                if ((rooms[n, dr[n]][(int)Index.rightDoor] < rooms[n, dr[n]][(int)Index.leftDoor]) ^ notNoneIndex == (int)Index.bottomDoor)
                {
                    steps.L += 1;
                }
                else
                {
                    steps.R += 1;
                }
            }
            return(steps);
        }
Exemplo n.º 2
0
        void _ConnectHorizontalPath(RL x, RL steps, int n, int[] dr)
        {
            if (rooms[n, dr[n]][(int)Index.leftDoor] != 0)
            {
                for (int r = 0; r < steps.R; r++)
                {
                    map[x.L + r, rooms[n, dr[n]][(int)Index.leftDoor]] = (int)Tile.path;
                }
            }

            if (rooms[n, dr[n]][(int)Index.rightDoor] != 0)
            {
                for (int l = 0; l < steps.L; l++)
                {
                    map[x.R - l, rooms[n, dr[n]][(int)Index.rightDoor]] = (int)Tile.path;
                }
            }
        }
Exemplo n.º 3
0
        void _Connect(int[] dr, int[] dp)
        {
            var x = new RL(0, 0);

            for (int n = 1; n < nDivW - 1; n++)
            {
                var steps = new RL(0, 0);
                x.L = (unitW + 1) * n;
                x.R = (unitW + 1) * (n + 1) - 1;
                if (rooms[n, dr[n]][(int)Index.topDoor] != 0 && rooms[n, dr[n]][(int)Index.bottomDoor] != 0)
                {
                    steps = CountSteps(x, n, dr, (int)Index.bottomDoor, true);
                }
                else if (rooms[n, dr[n]][(int)Index.topDoor] != 0 || rooms[n, dr[n]][(int)Index.bottomDoor] != 0)
                {
                    int notNoneIndex = (rooms[n, dr[n]][(int)Index.topDoor] != 0) ? (int)Index.topDoor : (int)Index.bottomDoor;
                    steps = CountSteps(x, n, dr, notNoneIndex, false);
                }
                else
                {
                    steps.R  = UnityEngine.Random.Range(2, unitW - 1);
                    steps.L  = unitW - steps.R;
                    steps.R += 1;
                    steps.L += 1;
                    rooms[n, dr[n]][(int)Index.bottomDoor] = x.L + steps.R - 1;
                }
                _ConnectHorizontalPath(x, steps, n, dr);
            }

            int yTop, yBottom;

            for (int n = 1; n < nDivW - 1; n++)
            {
                yTop    = (unitH + 1) * (dr[n] + 1) - 1;
                yBottom = (unitH + 1) * dr[n] + 1;
                _ConnectVerticalPath(yTop, yBottom, n, dr, dp);
            }
        }