Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        //Tint blocks below or above the push line
        if (y < 0 && blockRenderer != null)
        {
            blockRenderer.material.color = new Color(.5f, .5f, .5f);
        }
        else if (state != BlockState.Match && state != BlockState.Moving && blockRenderer != null)
        {
            blockRenderer.material.color = new Color(1f, 1f, 1f);
        }

        //If held, move it around and check for matches, swaps or a hole
        if (state == BlockState.Held)
        {
            float       xMovement    = Input.GetAxis("Mouse X") * 12f * Time.deltaTime;
            int         xForPosition = fieldScript.GetBlockXForPosition(transform.position);
            BlockScript swapBlock    = null;

            //print("Held block (x,y),(pX): (" + x + ", " + y + ") (" + xForPosition + ")");

            if (xMovement > 0)   //Moving right
            {
                if (x < 5)
                {
                    swapBlock = fieldScript.GetBlockForXY(x + 1, y);

                    if (fieldScript.IsBlockEligibleForSwap(swapBlock) == true)
                    {
                        transform.Translate(xMovement, 0f, 0f);
                        if (xForPosition != x)
                        {
                            if (swapBlock != null)
                            {
                                swapBlock.SwapBlock(x, y);
                            }

                            ChangeBlock(xForPosition, y);
                        }
                    }
                }
            }
            else if (xMovement < 0)   //Moving Left
            {
                if (x > 0)
                {
                    swapBlock = fieldScript.GetBlockForXY(x - 1, y);

                    if (fieldScript.IsBlockEligibleForSwap(swapBlock) == true)
                    {
                        transform.Translate(xMovement, 0f, 0f);
                        if (xForPosition != x)
                        {
                            if (swapBlock != null)
                            {
                                swapBlock.SwapBlock(x, y);
                            }
                            ChangeBlock(xForPosition, y);
                        }
                    }
                }
            }

            DropBlock(fieldScript.CheckForHolesAtBlock(this));
            fieldScript.CheckForMatchesAtBlock(this, true);
            //fieldScript.CheckForMatchesAtSwap(this, swapBlock, true);
        }

        //Check for hole, then drop it
        if (state == BlockState.None)
        {
            DropBlock(fieldScript.CheckForHolesAtBlock(this));
        }
    }