Exemplo 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);
 }
Exemplo n.º 2
0
    private void CreateToken(int gridX, int gridY, bool avoidMatches, bool withMove)
    {
        Vector3 newPos;

        if (withMove)
        {
            bool isDown = (collapseDirection == MoveDirection.Down);

            float columnsVerticalOffset = -Mathf.Abs(gridX - gridSize.x / 2) *
                                          tokenSize.y * generationTokensRelativeDistance;

            newPos = GridToWorldPosition(
                gridX,
                gridY + (isDown ? -1 : 1) * (gridSize.y))
                     + Vector3.up * (isDown ? -1 : 1) * columnsVerticalOffset;
        }
        else
        {
            newPos = GridToWorldPosition(gridX, gridY);
        }

        GameObject tokenObj = Instantiate(Settings.main.tokens.prefab,
                                          newPos, Quaternion.identity, transform);
        MaskToken token = tokenObj.GetComponent <MaskToken>();

        token.previousGridPosition = new Vector2Int(-1, -1);
        SetTokenInGrid(token, gridX, gridY);
        UpdateTokenPosition(token, Settings.main.tokens.collapseTime);
        token.wasMoved = false;

        if (avoidMatches)
        {
            List <int> unwantedElements = new List <int>();
            if (gridY > 1)
            {
                if (tokens[gridY - 1, gridX].elementId == tokens[gridY - 2, gridX].elementId)
                {
                    unwantedElements.Add(tokens[gridY - 1, gridX].elementId);
                }
            }

            if (gridX > 1)
            {
                if (tokens[gridY, gridX - 1].elementId == tokens[gridY, gridX - 2].elementId)
                {
                    unwantedElements.Add(tokens[gridY, gridX - 1].elementId);
                }
            }
            token.SetRandomElement(unwantedElements.ToArray());
        }
        else
        {
            token.SetRandomElement();
        }
        token.UpdateSpriteImmediate();
        tokenObj.name = Settings.main.elements[token.elementId].name + "(" + gridX + ", " + gridY + ")";
    }
Exemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            if (GUILayout.Button("Update Sprite"))
            {
                MaskToken token = target as MaskToken;
                token.UpdateSpriteImmediate();
            }
        }
Exemplo n.º 4
0
    public bool IsNextTo(MaskToken other)
    {
        int xDiff = Mathf.Abs(gridPosition.x - other.gridPosition.x);
        int yDiff = Mathf.Abs(gridPosition.y - other.gridPosition.y);

        if (xDiff + yDiff == 1)
        {
            return(true);
        }
        return(false);
    }
Exemplo n.º 5
0
    public void SetTokenInGrid(MaskToken token, int xGrid, int yGrid)
    {
        try
        {
            tokens[yGrid, xGrid] = token;
        }
        catch (Exception)
        {
            Debug.LogError("Problematyczny index:" + xGrid + ", " + yGrid);
        }

        token.gridPosition = new Vector2Int(xGrid, yGrid);
    }
Exemplo n.º 6
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;
        }
    }
Exemplo n.º 7
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);
    }
Exemplo n.º 8
0
 public void Awake()
 {
     puzzleController = SwapController.main;
     token            = GetComponent <MaskToken>();
 }
Exemplo n.º 9
0
 public void UpdateTokenPosition(MaskToken token, float time = 0)
 {
     token.BeginMovingToPosition(GridToWorldPosition(token.gridPosition.x, token.gridPosition.y), time);
 }
Exemplo n.º 10
0
 public void SetTokenInGrid(MaskToken token, Vector2Int gridPos)
 {
     SetTokenInGrid(token, gridPos.x, gridPos.y);
 }