Exemple #1
0
    public System.Collections.IEnumerator CoMoveCell(Vector2 cellPosition, Direction direction)
    {
        movementCount++;
        yield return(new WaitForSeconds(movementCount * 0.01f));

        // Get current cell
        GameObject curCell = GetCell(cellPosition);

        // Sanity check the cell exists and is active
        if (curCell != null)
        {
            // Enter loop to move cell as far as possible
            bool keepChecking = true;
            while (keepChecking)
            {
                // Force check to false for now
                keepChecking = false;

                // Get current grid cell component
                GridCell   curGridCell = curCell.GetComponent <GridCell>();
                GameObject nextCell    = GetCell(curGridCell.NextCell(direction));

                //  If we have an active cell and a cell to try move to
                if (curGridCell.cellActive && nextCell != null)
                {
                    // Get next grid cell component
                    GridCell nextGridCell = nextCell.GetComponent <GridCell>();

                    // Check that moving to the next cell is an eligible option
                    if (!nextGridCell.DontTouch(curGridCell))
                    {
                        // Move cell data into next and disable current
                        nextGridCell.UpdateCell(curGridCell.cellValue);
                        curGridCell.DisableCell();

                        // Update fruit layer
                        fruitManager.MoveFruit(curGridCell.fruitReference, nextGridCell);

                        // Override current cell with one moved into and keep checking
                        curCell      = nextCell;
                        keepChecking = true;
                        moveMade     = true;
                    }
                }
            }
        }
    }