예제 #1
0
    void Move()
    {
        int     rotateOffset = 1;
        float   angle        = piece.transform.rotation.eulerAngles.z;
        Vector3 pos;

        if (Input.GetKeyDown("right") || Input.GetKeyDown("d") || rightButtonClicked)
        {
            rightButtonClicked = false;

            moveManager.MoveHorizontal(piece, Direction.Right);

            if (Collide3())
            {
                moveManager.MoveHorizontal(piece, Direction.Left);
            }
        }
        else if (Input.GetKeyDown("left") || Input.GetKeyDown("a") || leftButtonClicked)
        {
            leftButtonClicked = false;
            moveManager.MoveHorizontal(piece, Direction.Left);

            if (Collide3())
            {
                moveManager.MoveHorizontal(piece, Direction.Right);
            }
        }
        else if (Input.GetKey("down") || Input.GetKeyDown("s"))
        {
            time = time + Time.deltaTime;
            if (time > downTime)
            {
                time2 += Time.deltaTime;

                if (time2 > downTime2)
                {
                    Drop();
                    time2 = 0;
                }
            }
        }
        else if (Input.GetKeyDown("q") || leftRotateButtonClicked)
        {
            leftRotateButtonClicked = false;
            pos = piece.transform.position;

            if (!Collide4(rotate: 90))
            {
                StartCoroutine(moveManager.Rotate(piece, 90));
            }
            else
            {
                while (Collide4(rotate: 90))                                                                      //calisan
                {
                    piece.transform.position = piece.transform.position + new Vector3(rotateOffset, 0, 0);
                    rotateOffset             = -(rotateOffset + (rotateOffset > 0 ? 1 : -1));

                    if (rotateOffset > pieceArray.GetLength(0))
                    {
                        piece.transform.position = pos;
                        break;
                    }

                    if (!Collide4(rotate: 90))
                    {
                        StartCoroutine(moveManager.Rotate(piece, 90));
                        break;
                    }
                }
            }


            angle = piece.transform.rotation.eulerAngles.z;
        }
        else if (Input.GetKeyDown("e") || rightRotateButtonClicked)
        {
            #region CALISAN DONUS

            //pos = piece.transform.position;

            //piece.transform.rotation = Quaternion.Euler(0f, 0f, angle-90f);
            //angle = piece.transform.rotation.eulerAngles.z;

            //while (Collide3())
            //{
            //	piece.transform.position = piece.transform.position + new Vector3(rotateOffset, 0, 0);
            //	rotateOffset = -(rotateOffset + (rotateOffset > 0 ? 1 : -1));

            //	if (rotateOffset > pieceArray.GetLength(0))
            //	{
            //		piece.transform.rotation = Quaternion.Euler(0, 0, angle + 90);
            //		piece.transform.position = pos;
            //		break;
            //	}

            //}
            #endregion
            rightRotateButtonClicked = false;

            pos = piece.transform.position;

            if (!Collide4(rotate: -90))
            {
                StartCoroutine(moveManager.Rotate(piece, -90));
            }
            else
            {
                while (Collide4(rotate: -90))
                {
                    piece.transform.position = piece.transform.position + new Vector3(rotateOffset, 0, 0);
                    rotateOffset             = -(rotateOffset + (rotateOffset > 0 ? 1 : -1));

                    if (rotateOffset > pieceArray.GetLength(0))
                    {
                        piece.transform.position = pos;
                        break;
                    }

                    if (!Collide4(rotate: -90))
                    {
                        StartCoroutine(moveManager.Rotate(piece, -90));
                        break;
                    }
                }
            }
        }
    }