Exemplo n.º 1
0
        void SetSetNumbers(MazeNode[] row, ref int prevSetNumber)
        {
            for (int i = 0; i < row.Length; ++i)
            {
                int      setNumber = prevSetNumber + 1;
                MazeNode node      = row[i];

                node.SetNumber = setNumber;
                prevSetNumber++;
            }
        }
Exemplo n.º 2
0
        void CreateNodes()
        {
            nodes = new MazeNode[GridSize.x][];

            for (int x = 0; x < GridSize.x; ++x)
            {
                nodes[x] = new MazeNode[GridSize.y];

                for (int y = 0; y < GridSize.y; ++y)
                {
                    nodes[x][y] = CreateNode(new Vector2Int(x, y));
                }
            }
        }
Exemplo n.º 3
0
        void EqualizeAdjacentCells(MazeNode[] row)
        {
            for (int i = 1; i < row.Length; ++i)
            {
                MazeNode node         = row[i];
                MazeNode previousNode = row[i - 1];

                if (node.SetNumber != previousNode.SetNumber && rand.Next(0, 2) == 0)
                {
                    node.SetNumber = previousNode.SetNumber;
                    previousNode.RemoveMask(MazeNode.WALL_TOP);
                    node.RemoveMask(MazeNode.WALL_BOTTOM);
                }
            }
        }
Exemplo n.º 4
0
        void OpenWays(MazeNode[] row)
        {
            if (row == null)
            {
                return;
            }

            var setNumbers = new HashSet <int>();
            var openSets   = new HashSet <int>();

            for (int i = 0; i < row.Length; ++i)
            {
                MazeNode node = row[i];

                setNumbers.Add(node.SetNumber);

                if (node.HasWallRight && rand.Next(0, 5) == 0)
                {
                    node.RemoveMask(MazeNode.WALL_RIGHT);
                    openSets.Add(node.SetNumber);
                }
            }

            foreach (int setNumber in setNumbers)
            {
                if (openSets.Contains(setNumber))
                {
                    continue;
                }

                for (int i = 0; i < row.Length; ++i)
                {
                    MazeNode node = row[i];

                    if (node.SetNumber != setNumber)
                    {
                        continue;
                    }

                    node.RemoveMask(MazeNode.WALL_RIGHT);
                    openSets.Add(setNumber);

                    break;
                }
            }
        }
Exemplo n.º 5
0
        MazeNode CreateNode(Vector2Int gridPos)
        {
            Vector3 worldBottomLeft = Position - new Vector3(Size.x / 2, 0, Size.z / 2);

            Vector3 worldPos = worldBottomLeft
                               + Vector3.right * (gridPos.x * NodeWidth + NodeWidth * 0.5f)
                               + Vector3.up * NodeHeight * 0.5f
                               + Vector3.forward * (gridPos.y * NodeDepth + NodeDepth * 0.5f);

            var node = new MazeNode(game.Prefabs.MazeWall, gridPos, worldPos, new Vector3(NodeWidth, NodeHeight, NodeDepth), MazeNode.WALL_AROUND);

            node.Options &= ~MazeNode.WALL_LEFT;

            node.Walkable = !UnityEngine.Physics.CheckSphere(worldPos, NodeWidth * 0.5f, ~walkableMask);

            return(node);
        }
Exemplo n.º 6
0
        void ApplySetNumbersFromPreviousRow(MazeNode[] row, MazeNode[] previousRow)
        {
            if (row == null || previousRow == null)
            {
                return;
            }

            for (int i = 0; i < previousRow.Length; ++i)
            {
                MazeNode prevRowNode = previousRow[i];

                if (prevRowNode.HasWallRight)
                {
                    continue;
                }

                row[i].SetNumber = prevRowNode.SetNumber;
                row[i].RemoveMask(MazeNode.WALL_LEFT);
            }
        }
Exemplo n.º 7
0
 public MazeNode[] GetRowOfNode(MazeNode node) => nodes[node.GridPos.x];