Beispiel #1
0
    private void Update()
    {
        if (_moving != null)
        {
            Vector2 direction  = (Vector2)Input.mousePosition - _mouseStart;
            Vector2 nDirection = direction.normalized;
            Vector2 aDirection = new Vector2(Mathf.Abs(direction.x), Mathf.Abs(direction.y));

            _newIndex = Point.Clone(_moving.index);
            Point add = Point.Zero;
            if (direction.magnitude > -258)
            {
                if (aDirection.x > aDirection.y)
                {
                    add = new Point(nDirection.x > 0 ? 1 : -1, 0);
                }
                else if (aDirection.x < aDirection.y)
                {
                    add = new Point(0, nDirection.y > 0 ? -1 : 1);
                }
            }

            _newIndex.Add(add);
            Vector2 position = _game.GetPositionFromPoint(_moving.index);
            if (!_newIndex.Equals(_moving.index))
            {
                position += Point.Multiply(new Point(add.x, -add.y), 16).ToVector();
            }
            _moving.MovePositionTo(position);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (moving != null)
        {
            Vector2 direction           = ((Vector2)Input.mousePosition - mouseStart);
            Vector2 normalizedDirection = direction.normalized;
            Vector2 absoluteDirection   = new Vector2(Mathf.Abs(direction.x), Mathf.Abs(direction.y));

            newIndex = Point.clone(moving.index);
            Point add = Point.zero;
            if (direction.magnitude > 32) // if mouse is 32 pixels away from starting point of the mouse
            {
                //Make add either (1, 0) or (-1, 0) or (0, 1) or (0, -1) depending on direction of the mouse pointer

                if (absoluteDirection.x > absoluteDirection.y)
                {
                    add = (new Point((normalizedDirection.x > 0) ? 1 : -1, 0));
                }
                else if (absoluteDirection.y > absoluteDirection.x)
                {
                    add = (new Point(0, (normalizedDirection.y > 0) ? -1 : 1));
                }
            }
            newIndex.add(add);

            Vector2 pos = game.GetPositionFromPoint(moving.index); // get position of current piece we are moving
            if (!newIndex.Equals(moving.index))
            {
                pos += Point.mult(new Point(add.x, -add.y), 16).ToVector();
            }
            moving.MovePositionTo(pos);
        }
    }
Beispiel #3
0
    private void Update()
    {
        if (_moving == null)
        {
            return;
        }

        Vector2 direction = (Vector2)Input.mousePosition - _mouseStart;
        Vector2 normalDir = direction.normalized;
        Vector2 absDir    = new Vector2(Mathf.Abs(direction.x), Mathf.Abs(direction.y));

        _newIndex = Point.Clone(_moving.Index);
        Point add = Point.Zero;

        if (direction.magnitude > 32)         //Если мышка сместилась на 32 пикселя с начальной точки
        {
            if (absDir.x > absDir.y)
            {
                add = new Point(normalDir.x > 0 ? 1 : -1, 0);
            }
            else if (absDir.x < absDir.y)
            {
                add = new Point(0, normalDir.y > 0 ? -1 : 1);
            }
        }
        _newIndex.Add(add);

        Vector2 pos = _game.GetPositionFromPoint(_moving.Index);

        if (!_newIndex.Equals(_moving.Index))
        {
            pos += Point.Multiply(new Point(add.X, -add.Y), 16).ToVector();
        }

        _moving.MoveTo(pos);
    }
Beispiel #4
0
    void Update()
    {
        if (moving != null)
        {
            Vector2 dir           = ((Vector2)Input.mousePosition - mouseStart);
            Vector2 normalizedDir = dir.normalized;
            Vector2 absDir        = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y));

            newIndex = Point.Clone(moving.index);
            Point add = Point.Zero;

            if (dir.magnitude > 64) // If cursor is 64 pixels away from the starting point of the cursor
            {
                // Make add either (1, 0) | (-1, 0) | (0, 1) | (0, -1) depending on the direction of the mouse point
                if (absDir.x > absDir.y)
                {
                    add = (new Point((normalizedDir.x > 0) ? 1 : -1, 0));
                }
                else if (absDir.y > absDir.x)
                {
                    add = (new Point(0, (normalizedDir.y > 0) ? -1 : 1));
                }
            }

            newIndex.Add(add);

            Vector2 pos = game.GetPositionFromPoint(moving.index);

            if (!newIndex.Equals(moving.index))
            {
                pos += Point.Multipy(new Point(add.x, -add.y), 16).ToVector();
            }

            moving.MovePositionTo(pos);
        }
    }