Exemplo n.º 1
0
    public static Vector3 SquarePosition(SprawlerSquare square, PrefabDimensions dimensions)
    {
        Vector3 position = new Vector3(
            square.coordinates.x * dimensions.width,
            square.coordinates.y * dimensions.height,
            square.coordinates.z * dimensions.length
            );

        return(position);
    }
Exemplo n.º 2
0
    public void GenerateGrid()
    {
        Maze2DLogic.ClearGrid(transform);
        squares = new Maze2DSquare[length, width];
        PrefabDimensions dimensions = mazeSquare.GetComponent <PrefabDimensions>();

        coordinates = Maze2DLogic.GenerateCoordinates(dimensions.width, dimensions.length, squares);

        //[Layer][Column][Cluster][Square]
        List <List <Maze2DSquare[]> > gridClusters;

        Maze2DLogic.WriteClusters(gapFrequency, out gridClusters, squares);

        Maze2DLogic.GenerateSquares(transform, useColumns, levelPrefabs, mazeSquare, coordinates, squares);
        GenerateOutlets();
    }
Exemplo n.º 3
0
    public void GenerateGrid()
    {
        ClearGrid();
        squares = new DungeonSquare[length, width];
        PrefabDimensions dimensions = connectLogic.dungeonSquare.GetComponent <PrefabDimensions>();

        GenerateCoordinates(dimensions.width, dimensions.length, squares);

        //[Column][Cluster][Square]
        List <List <DungeonSquare[]> > gridClusters = new List <List <DungeonSquare[]> >();

        for (int i = 0; i < length; i++)
        {
            List <DungeonSquare[]> rowClusters = new List <DungeonSquare[]>();
            int clusterSize = 0;

            for (int j = 0; j < width; j++)
            {
                #region Clustering
                DungeonSquare[] cluster;

                //Only 1 cluster for the origin
                if (i == 0 && j == 0)
                {
                    squares[i, j] = new DungeonSquare(i, j);
                    clusterSize++;
                    continue;
                }

                //Store clusters
                float rand = Random.Range(0, 1f);
                if (rand < gapFrequency)
                {
                    if (clusterSize > 0)
                    {
                        //Cluster excluding current (null) square
                        cluster = SetCluster(clusterSize, i, j, squares);
                        rowClusters.Add(cluster);
                        clusterSize = 0;
                    }

                    if (i == 0)
                    {
                        break;
                    }
                    continue;
                }

                squares[i, j] = new DungeonSquare(i, j);

                clusterSize++;
                if (j == width - 1)
                {
                    //Cluster including current (!null) square
                    cluster = SetCluster(clusterSize, i, j + 1, squares);
                    rowClusters.Add(cluster);
                }
                #endregion
            }

            gridClusters.Add(rowClusters);
        }

        #region Linking
        for (int i = 1; i < length; i++)
        {
            //Iterate through clusters
            for (int j = 0; j < gridClusters[i].Count; j++)
            {
                int connections = 0;

                for (int k = 0; k < gridClusters[i][j].Length; k++)
                {
                    DungeonSquare current = gridClusters[i][j][k];

                    if (squares[i - 1, current.yCoord] != null)
                    {
                        connections++;
                    }
                }

                if (connections == 0)
                {
                    //Scout out to the first row to find where this cluster can connect
                    bool hit = false;

                    for (int k = 0; k < gridClusters[i][j].Length; k++)
                    {
                        DungeonSquare current = gridClusters[i][j][k];

                        for (int l = i - 1; l >= 0; l--)
                        {
                            if (squares[l, current.yCoord] != null)
                            {
                                hit = true;
                                for (int m = i - 1; m > l; m--)
                                {
                                    squares[m, current.yCoord] = new DungeonSquare(m, current.yCoord);
                                }
                                break;
                            }
                        }

                        if (hit == true)
                        {
                            break;
                        }
                    }

                    //If there's nowhere it can connect, draw a vertical line, then horizontal to the origin
                    if (hit == false)
                    {
                        DungeonSquare sq = gridClusters[i][j][0];

                        for (int k = i - 1; k >= 0; k--)
                        {
                            squares[k, sq.yCoord] = new DungeonSquare(k, sq.yCoord);
                        }

                        for (int k = sq.yCoord; k >= gridClusters[0][0].Length; k--)
                        {
                            if (squares[0, k] == null)
                            {
                                squares[0, k] = new DungeonSquare(0, k);
                            }
                        }
                    }
                }
            }
        }
        #endregion

        GenerateSquares(squares);
        GenerateOutlets(squares);
    }