Beispiel #1
0
    /// <summary>
    /// Updates the grid
    /// </summary>
    /// <param name="figure"></param>
    public void UpdateGrid(FigurePositionController figure)
    {
        //  Update grid array. Doing this by starting a for loop that iterates over all the grid rows starting at 0
        for (int y = 0; y < _gridHeight; y++)
        {
            //  For each row, iterate over each individual x coordinate that represents a spot on the grid where a block could be
            for (int x = 0; x < _gridWidth; x++)
            {
                //  For each iteration, checking the grid array for a null value
                if (grid[x, y] != null)
                {
                    //  If there's a transform stored at the current index of the array then checking if the transform parent is the transform of the figure
                    if (grid[x, y].parent == figure.transform)
                    {
                        //  if it is then setting that position in the array to null
                        grid[x, y] = null;
                    }
                }
            }
        }

        //  Stepping through all of the blocks (children) of the calling figure
        foreach (Transform block in figure.transform)
        {
            //  Then creating a vector2 with the rounded position of current block
            Vector2 pos = Round(block.position);

            //  Then checking the position of the block to make sure it's below the top line of the grid
            if (pos.y < _gridHeight)
            {
                //  If it is, then setting the block (transform) at the position of the block
                grid[(int)pos.x, (int)pos.y] = block;
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Check is above grid
    /// </summary>
    /// <param name="figure"></param>
    /// <returns></returns>
    public bool CheckIsAboveGrid(FigurePositionController figure)
    {
        for (int x = 0; x < _gridWidth; x++)
        {
            foreach (Transform block in figure.transform)
            {
                Vector2 pos = Round(block.position);
                if (pos.y > _gridHeight - 1)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Beispiel #3
0
 public void SetCurrentFigure(GameObject figure)
 {
     _figureController = figure.GetComponent <FigurePositionController>();
 }