Esempio n. 1
0
 public void MoveBack(MaskToken token)
 {
     Debug.Log("Moving back");
     grid.SetTokenInGrid(token, token.previousGridPosition);
     token.BeginMovingToPosition(grid.GridToWorldPosition(token.gridPosition),
                                 Settings.main.tokens.swapTime);
 }
Esempio n. 2
0
    private void RefillColumn(int col, int nullCount, bool isDown)
    {
        // create new tokens and collapse them
        for (int p = 0; p < nullCount; p++)
        {
            int initialRow = isDown ? (-p - 1) : (gridSize.y + p);
            int finalRow   = initialRow + (isDown ? 1 : -1) * nullCount;

            GameObject tokenObj = Instantiate(Settings.main.tokens.prefab,
                                              GridToWorldPosition(col, initialRow), Quaternion.identity, transform);

            MaskToken token = tokenObj.GetComponent <MaskToken>();
            token.previousGridPosition = new Vector2Int(-1, -1);
            token.SetRandomElement();

            tokenObj.name = Settings.main.elements[token.elementId].name + "(" + col + ", " + finalRow + ")";

            SetTokenInGrid(token, col, finalRow);
            token.BeginMovingToPosition(GridToWorldPosition(token.gridPosition), Settings.main.tokens.collapseTime);
            token.wasMoved = false;
        }
    }
Esempio n. 3
0
    private int CollapseTokensInColumn(int col, bool isDown)
    {
        int nullCount = 0;

        for (int j = 0; j < gridSize.y; j++)
        {
            int       currentRow   = (isDown) ? (gridSize.y - j - 1) : j;
            MaskToken currentToken = tokens[currentRow, col];

            if (currentToken == null)
            {
                nullCount += 1;
            }
            else if (nullCount > 0)
            {
                SetTokenInGrid(currentToken, col, currentRow + ((isDown) ? 1 : -1) * nullCount);
                tokens[currentRow, col] = null;
                currentToken.BeginMovingToPosition(GridToWorldPosition(currentToken.gridPosition), Settings.main.tokens.collapseTime);
                currentToken.wasMoved = false;
            }
        }
        return(nullCount);
    }
Esempio n. 4
0
 public void UpdateTokenPosition(MaskToken token, float time = 0)
 {
     token.BeginMovingToPosition(GridToWorldPosition(token.gridPosition.x, token.gridPosition.y), time);
 }