예제 #1
0
    void Update()
    {
        if (moving != null)
        {
            Vector2 dir  = ((Vector2)Input.mousePosition - mouseStart);
            Vector2 nDir = dir.normalized;
            Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y));

            newIndex = Point.clone(moving.index);
            Point add = Point.zero;
            if (dir.magnitude > 34) //If our mouse is 34 pixels away from the starting point of the mouse
            {
                //Make add either (1,0) | (-1,0) | (0,1) | (0.-1) depending on the direction of the mouse point
                if (aDir.x > aDir.y)
                {
                    add = (new Point((nDir.x > 0) ? 1 : -1, 0));
                }
                else if (aDir.y > aDir.x)
                {
                    add = (new Point(0, (nDir.y > 0) ? -1 : 1));
                }
            }
            newIndex.add(add);

            Vector2 pos = game.getPositionFromPoint(moving.index);
            if (!newIndex.Equals(moving.index))
            {
                pos += Point.mult(new Point(add.x, -add.y), 16).ToVector();
            }
            moving.MovePositionTo(pos);
        }
    }
예제 #2
0
    void Update()
    {
        if (moving != null)
        {
            Vector2 dir  = ((Vector2)Input.mousePosition - mouseStart);
            Vector2 nDir = dir.normalized;
            Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); // absolute direction

            newIndex = Point.clone(moving.index);
            Point add = Point.zero;
            if (dir.magnitude > 32) // jezeli myszka jest odallona od 32px od pozycji startowej
            {
                // make add either (1,0) | (-1, 0) | (0, 1) | (0, -1) depending on the direction of the mouse point
                if (aDir.x > aDir.y)
                {
                    add = (new Point((nDir.x > 0) ? 1 : -1, 0));
                }
                else if (aDir.y > aDir.x)
                {
                    add = (new Point(0, (nDir.y > 0) ? -1 : 1));
                }
            }
            newIndex.add(add);

            Vector2 pos = game.getPositionFromPoint(moving.index);
            if (!newIndex.Equals(moving.index))
            {
                pos += Point.mult(new Point(add.x, -add.y), 16).ToVector();
            }
            moving.MovePositionTo(pos);
        }
    }
예제 #3
0
    void Update()
    {
        if (moving != null)
        {
            Vector2 dir  = (Vector2)Input.mousePosition - mouseStart;
            Vector2 nDir = dir.normalized;
            Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y));

            newIndex = Point.clone(moving.index);
            Point add = Point.zero;

            if (dir.magnitude > 32)
            {
                if (aDir.x > aDir.y)
                {
                    add = new Point((nDir.x > 0) ? 1 : -1, 0);
                }
                else if (aDir.y > aDir.x)
                {
                    add = new Point(0, (nDir.y > 0) ? -1 : 1);
                }
            }

            newIndex.add(add);

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

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

            moving.MovePositionTo(pos);
        }
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        if (moving != null)
        {
            Vector2 dir  = ((Vector2)Input.mousePosition - mouseStart);
            Vector2 nDir = dir.normalized;
            Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y));

            newIndex = Point.clone(moving.index);
            Point add = Point.zero;
            if (dir.magnitude > 32)// Se o mouse estiver a 32 pixels de distancia de onde começou
            {
                // Faz adicionar ou (1, 0) || (-1, 0) || (0, 1) || (0, -1) dependendo da direção do ponto do mouse
                if (aDir.x > aDir.y)
                {
                    add = (new Point((nDir.x > 0) ? 1 : -1, 0));
                }
                else if (aDir.y > aDir.x)
                {
                    add = (new Point(0, (nDir.y > 0) ? -1 : 1));
                }
            }
            newIndex.add(add);

            Vector2 pos = game.getPositionFromPoint(moving.index);
            if (!newIndex.Equals(moving.index))
            {
                pos += Point.mult(new Point(add.x, -add.y), 16).toVector();
            }
            moving.MovePositionTo(pos);
        }
    }
예제 #5
0
    void Update()
    {
        if (moving != null)
        {
            Vector2 dir  = ((Vector2)Input.mousePosition - mouseStart);
            Vector2 nDir = dir.normalized;
            Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y));

            newIndex = Point.clone(moving.index);
            Point add = Point.zero;
            if (dir.magnitude > 50)  //마우스가 시작점부터 50이상 떨어졌다면
            {
                // if eles if 와 삼항연산자를 이용해서 4개의 경우의 수를 가려내고
                if (aDir.x > aDir.y)
                {
                    add = (new Point((nDir.x > 0) ? 1 : -1, 0));
                }
                else if (aDir.y > aDir.x)
                {
                    add = (new Point(0, (nDir.y > 0) ? -1 : 1));
                }
            }
            newIndex.add(add);

            Vector2 pos = game.getPositionFromPoint(moving.index);
            //50만큼 이동
            if (!newIndex.Equals(moving.index))
            {
                pos += Point.mult(new Point(add.x, -add.y), 25).ToVector();
            }
            moving.MovePositionTo(pos);
        }
    }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        if (moving != null)
        {
            Vector2 dir  = ((Vector2)Input.mousePosition - mouseStart);
            Vector2 nDir = dir.normalized;
            Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y));

            newIndex = Point.clone(moving.index);
            Point add = Point.zero;
            if (dir.magnitude > 32) //Ha rákattintunk és 32pixellel arréb húzzuk az egerünket
            {
                if (aDir.x > aDir.y)
                {
                    add = (new Point((nDir.x > 0) ? 1 : -1, 0));
                }
                else if (aDir.y > aDir.x)
                {
                    add = (new Point(0, (nDir.y > 0) ? -1 : 1));
                }
            }
            newIndex.add(add);

            Vector2 pos = game.getPositionFromPoint(moving.index);
            if (!newIndex.Equals(moving.index)) // az irányába a gem egy kicsit mozduljon meg
            {
                pos += Point.mul(new Point(add.x, -add.y), 64).ToVector();
            }
            moving.MovePositionTo(pos);
        }
    }
예제 #7
0
    void Update()
    {
        if (moving != null)
        {
            Vector2 dir  = ((Vector2)Input.mousePosition - mouseStart);
            Vector2 nDir = dir.normalized;
            Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y));

            newIndex = Point.clone(moving.index);
            Point add = Point.zero;

            if (dir.magnitude > 32) // Если наша мышка на 32 пикселя отдалилась от своего первоначального значения
            {
                // дает понять мышке координаты обьекта на котором она находится ((0,0) | (1,0) | (0,1) | (1,1) и т.д.)
                if (aDir.x > aDir.y)
                {
                    add = (new Point((nDir.x > 0) ? 1 : -1, 0));
                }
                else if (aDir.y > aDir.x)
                {
                    add = (new Point(0, (nDir.y > 0) ? -1 : 1));
                }
            }
            newIndex.x = newIndex.x + add.x;
            newIndex.y = newIndex.y + add.y;

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

            if (!newIndex.Equals(moving.index))
            {
                pos += Point.mult(new Point(add.x, -add.y), 16).ToVector(); // (16) - расстояние на которое сдвинется от начальной позиции эллемент при попытке направить его пальцем или мышкой
                // должна быть половина от размера эллемента
            }
            moving.MovePositionTo(pos);
        }
    }
예제 #8
0
    void Update()
    {
        if (selectedPiece != null)
        {
            RectTransform rect = selectedPiece.rect.parent.GetComponent <RectTransform>();
            Vector2       nPos = Vector2.zero;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, Input.mousePosition, canvas.worldCamera, out nPos);
            //selectedPiece.rect.anchoredPosition = nPos;
            selectBox.position = selectedPiece.rect.position;

            //becaus the anchor preset of the piece is top Left ,so need to  minus (board width /2) 因為珠子的錨點在左上角所以要減去盤面的一半
            float   disX = nPos.x + rect.sizeDelta.x / 2 - startPos.x;
            float   disY = nPos.y - rect.sizeDelta.y / 2 - startPos.y;
            Vector2 dir  = ((Vector2)Input.mousePosition - mouseStart);
            Vector2 nDir = dir.normalized;
            Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y));
            if (dir.magnitude > 32 && cDir == 0)
            {
                if (aDir.x > aDir.y)
                {
                    cDir = 1;
                }
                else if (aDir.y > aDir.x)
                {
                    cDir = 2;
                }
            }
            // else if(dir.magnitude < 32)
            //     cDir = 0;

            //avoid piece cross over the board 避免拉超過盤面 每個位置上的珠子都只能拉到最旁邊為止
            switch (selectedPiece.index.x)
            {
            //
            //  45678 ←index
            //4 XXXXX
            //5 XXXXX
            //6 XXXXX ←board
            //7 XXXXX
            //8 XXXXX

            //most left
            case 4:
            {
                //because the size of piece is 64x64
                if (disX > 64 * 4)
                {
                    disX = 64 * 4;
                }
                else if (disX < 0)
                {
                    disX = 0;
                }
                break;
            }

            //
            case 5:
            {
                if (disX > 64 * 3)
                {
                    disX = 64 * 3;
                }
                else if (disX < -64 * 1)
                {
                    disX = -64 * 1;
                }

                break;
            }

            // middle
            case 6:
            {
                if (disX > 64 * 2)
                {
                    disX = 64 * 2;
                }
                else if (disX < -64 * 2)
                {
                    disX = -64 * 2;
                }
                break;
            }

            case 7:
            {
                if (disX > 64 * 1)
                {
                    disX = 64 * 1;
                }
                else if (disX < -64 * 3)
                {
                    disX = -64 * 3;
                }
                break;
            }

            //most right
            case 8:
            {
                if (disX > 0)
                {
                    disX = 0;
                }
                else if (disX < -64 * 4)
                {
                    disX = -64 * 4;
                }
                break;
            }
            }

            switch (selectedPiece.index.y)
            {
            case 4:
            {
                if (disY > 0)
                {
                    disY = 0;
                }
                else if (disY < -64 * 4)
                {
                    disY = -64 * 4;
                }
                break;
            }

            case 5:
            {
                if (disY > 64 * 1)
                {
                    disY = 64 * 1;
                }
                else if (disY < -64 * 3)
                {
                    disY = -64 * 3;
                }
                break;
            }

            case 6:
            {
                if (disY > 64 * 2)
                {
                    disY = 64 * 2;
                }
                else if (disY < -64 * 2)
                {
                    disY = -64 * 2;
                }
                break;
            }

            case 7:
            {
                if (disY > 64 * 3)
                {
                    disY = 64 * 3;
                }
                else if (disY < -64 * 1)
                {
                    disY = -64 * 1;
                }
                break;
            }

            case 8:
            {
                if (disY > 64 * 4)
                {
                    disY = 64 * 4;
                }
                else if (disY < 0)
                {
                    disY = 0;
                }
                break;
            }
            }

            if (disX > 0)
            {
                disX = disX + 32;
            }
            else if (disX < 0)
            {
                disX = disX - 32;
            }

            if (disY > 0)
            {
                disY = disY + 32;
            }
            else if (disY < 0)
            {
                disY = disY - 32;
            }

            if (Mathf.Abs((int)((disX) / 63)) > 0 || Mathf.Abs((int)((disY) / 63)) > 0)
            {
                StateManager.Instance.state = StateManager.State.turning;
            }

            verticalSelectLine.gameObject.SetActive(false);
            horizontalSelectLine.gameObject.SetActive(false);

            switch (cDir)
            {
            case 1:
            {
                horizontalSelectLine.gameObject.SetActive(true);
                horizontalSelectLine.position = new Vector2(horizontalSelectLine.position.x, selectedPiece.rect.position.y);
                moving = game.getNodePiecesFromTheSameLineX(selectedPiece);
                foreach (NodePiece piece in moving)
                {
                    Vector2 pos = Vector2.right * (int)((disX) / 63) * 64;
                    moveAmount = (int)((disX) / 63);
                    piece.MovePositionTo(game.getPositionFromPoint(piece.index) + pos, 30f);
                }
                break;
            }

            case 2:
            {
                verticalSelectLine.gameObject.SetActive(true);
                verticalSelectLine.position = new Vector2(selectedPiece.rect.position.x, verticalSelectLine.position.y);
                moving = game.getNodePiecesFromTheSameLineY(selectedPiece);
                foreach (NodePiece piece in moving)
                {
                    Vector2 pos = Vector2.up * (int)((disY) / 63) * 64;
                    moveAmount = -(int)((disY) / 63);
                    piece.MovePositionTo(game.getPositionFromPoint(piece.index) + pos, 20f);
                }
                break;
            }
            }
        }
    }