Exemple #1
0
        private void RandomDepthFirstTraversal()
        {
            Maze.Edge edge = edges[edges.Count - 1];
            edges.RemoveAt(edges.Count - 1);

            if (maze.IsUnconnected(edge.exit.position))
            {
                maze.AddEdge(edge);
                List <Maze.Edge> newEdges = maze.GetPossibleConnections(edge.exit);
                newEdges.Shuffle();
                edges.AddRange(newEdges);

                if (config.drawEdge != null)
                {
                    config.drawEdge(edge);
                }
            }
        }
Exemple #2
0
        public static void EdgeToRect(Maze.Edge edge, int wallSize, int roomSize,
                                      out Vector2Int position, out int width, out int height)
        {
            position = new Vector2Int(
                x: wallSize + Mathf.Min(edge.origin.position.x, edge.exit.position.x) * (roomSize + wallSize),
                y: wallSize + Mathf.Min(edge.origin.position.y, edge.exit.position.y) * (roomSize + wallSize));

            if ((edge.exit.position - edge.origin.position).y == 0)
            {
                width  = roomSize * 2 + wallSize;
                height = roomSize;
            }
            else
            {
                width  = roomSize;
                height = roomSize * 2 + wallSize;
            }
        }
Exemple #3
0
        private void DrawEdge(Maze.Edge edge)
        {
            MazeGenerator.EdgeToRect(edge, wallSize, roomSize, out Vector2Int position, out int width, out int height);

            Color color;

            if (useGradient)
            {
                float gradient01  = Mathf.Repeat(edge.origin.depth / gradientLength, 1);
                float gradient010 = Mathf.Abs((gradient01 - 0.5f) * 2);

                color = GetColor(gradient010);
            }
            else
            {
                color = GetColor(0.75f);
            }
            texture.DrawRect(position.x, position.y, width, height, color);
        }