Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        float delta = Time.deltaTime;

        if (fastHorizontalMovementDelay > 0)
        {
            fastHorizontalMovementDelay -= delta;
        }

        if (rightSidePressed && fastHorizontalMovementDelay < 0)
        {
            gridScript.MoveFigure(true);
        }
        else if (leftSidePressed && fastHorizontalMovementDelay < 0)
        {
            gridScript.MoveFigure(false);
        }

        if (mousePressed)
        {
            Vector3 posDiff = Input.mousePosition - lastMousePosition;
            if (posDiff.magnitude < 1)
            {
                posDiff = new Vector3();
            }
            mouseMoved += posDiff;

            if (Mathf.Abs(mouseMoved.x) >= horizontalDragSpeed)
            {
                wasFigureMoved = true;
                int  turnsCount = 0;
                bool turnSide   = true;

                if (mouseMoved.x > 0)
                {
                    turnsCount    = (int)Mathf.Round(mouseMoved.x / horizontalDragSpeed);
                    mouseMoved.x -= horizontalDragSpeed * turnsCount;
                }
                else
                {
                    turnSide      = false;
                    turnsCount    = (int)Mathf.Round(Mathf.Abs(mouseMoved.x) / horizontalDragSpeed);
                    mouseMoved.x += horizontalDragSpeed * turnsCount;
                }

                for (int i = 0; i < turnsCount; i++)
                {
                    gridScript.MoveFigure(turnSide);
                }

                if (gridScript.CanFigureSpeedBeChanged())
                {
                    //SetFigureSpeed(1);
                    mouseMoved.y = 0;
                }
            }
            else if (posDiff.y < -superAccelerationDragSpeed)
            {
                gridScript.ApplyFigureSuperFastFall();
            }
            else if (mouseMoved.y <= -verticalDragSpeed)
            {
                mouseMoved.y = 0;
                gridScript.MoveFigureDownOnOneCell();
            }

            lastMousePosition = Input.mousePosition;
        }
    }