예제 #1
0
    public void GenerateHexagonRadiusGrid(int radius)  //keeping the radius
    {
        if (radius <= 0)
        {
            return;
        }

        int prevRadius = 0;         //hexagon shape board is null when 'prevRadius' <= 0

        if (blockToGrid != null)
        {
            prevRadius = (blockToGrid.GetLength(0) - 1) / 2 + 1;
        }

        if (radius < prevRadius)
        {
            for (int i = 0; i < prevRadius; i++)
            {
                HexagonShape nextHexagonShape = HexagonAxis.GetDirection(4) * i;
                for (int dir = 0; dir < 6; dir++)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if (i >= radius)
                        {
                            Destroy(blockToGrid[nextHexagonShape.ToArrayPos(prevRadius).b, nextHexagonShape.ToArrayPos(prevRadius).a].gameObject);

                            nextHexagonShape = nextHexagonShape.GetNeighbour(dir);
                        }
                    }
                }
            }
        }

        HexagonShapeScript[,] newHexagonShapeBoard = new HexagonShapeScript[(radius - 1) * 2 + 1, (radius - 1) * 2 + 1];

        //generate blocks in the center
        if (0 < prevRadius)
        {
            //itinerate
            newHexagonShapeBoard[0, 0] = (HexagonShapeScript)blockToGrid[0, 0];
        }
        else
        {
            //Instantiate
            newHexagonShapeBoard[0, 0] = Instantiate(savedBlocks[(int)shapeOfBlock]).GetComponent <HexagonShapeScript>();
            newHexagonShapeBoard[0, 0].transform.parent = hexagonShapeBoardParent;
        }

        newHexagonShapeBoard[0, 0].transform.localScale  = Vector3.one * blockSize;
        newHexagonShapeBoard[0, 0].transformValueHexagon = new HexagonShape(0, 0);

        newHexagonShapeBoard[0, 0]._isScannedArea = false;
        newHexagonShapeBoard[0, 0].isWall         = false;
        newHexagonShapeBoard[0, 0].trackPos       = Mathf.Infinity;
        newHexagonShapeBoard[0, 0].groupBlock     = null;
        newHexagonShapeBoard[0, 0].currentSit     = blockEnum.baseBlock;


        for (int i = 1; i < radius; i++)
        {
            HexagonShape nextHexagonShape = HexagonAxis.GetDirection(4) * i;
            for (int dir = 0; dir < 6; dir++)
            {
                for (int j = 0; j < i; j++)
                {
                    HexagonShape arrayPos    = nextHexagonShape.ToArrayPos(radius);
                    HexagonShape oldArrayPos = nextHexagonShape.ToArrayPos(prevRadius);

                    if (i < prevRadius)
                    {
                        //Itinerate
                        newHexagonShapeBoard[arrayPos.b, arrayPos.a] = (HexagonShapeScript)blockToGrid[oldArrayPos.b, oldArrayPos.a];
                    }
                    else
                    {
                        //Instantiating
                        newHexagonShapeBoard[arrayPos.b, arrayPos.a] = Instantiate(savedBlocks[(int)shapeOfBlock]).GetComponent <HexagonShapeScript>();
                        newHexagonShapeBoard[arrayPos.b, arrayPos.a].transform.parent = hexagonShapeBoardParent;
                    }


                    newHexagonShapeBoard[arrayPos.b, arrayPos.a].transform.localScale  = Vector3.one * blockSize;
                    newHexagonShapeBoard[arrayPos.b, arrayPos.a].transformValueHexagon = new HexagonShape(nextHexagonShape.a, nextHexagonShape.b);

                    newHexagonShapeBoard[arrayPos.b, arrayPos.a]._isScannedArea = false;
                    newHexagonShapeBoard[arrayPos.b, arrayPos.a].isWall         = false;
                    newHexagonShapeBoard[arrayPos.b, arrayPos.a].trackPos       = Mathf.Infinity;
                    newHexagonShapeBoard[arrayPos.b, arrayPos.a].groupBlock     = null;
                    newHexagonShapeBoard[arrayPos.b, arrayPos.a].currentSit     = blockEnum.baseBlock;

                    nextHexagonShape = nextHexagonShape.GetNeighbour(dir);
                }
            }
        }

        //Save the new hexagon shape board
        blockToGrid = newHexagonShapeBoard;
        return;
    }
예제 #2
0
 //Setting the functions
 public HexagonShape GetDirection(int dir)
 {
     return(HexagonAxis.GetDirection(dir));
 }