Пример #1
0
 void Start()
 {
     if (Direction == RotationDir.Random)
     {
         Direction = Random.Range(1, 101) > 50 ? RotationDir.Left : RotationDir.Right;
     }
 }
Пример #2
0
    private IEnumerator Move()
    {
        float time = 0.0f;

        while (time < travelTime)
        {
            time += Time.deltaTime;
            transform.Translate(transform.forward * -1 * moveSpeed * Time.deltaTime);
            yield return(null);
        }

        //transform.Rotate(rotationAxis, Random.Range(0, 360));

        if (randRotDir == RotationDir.Clockwise)
        {
            transform.Rotate(rotationAxis,
                             Mathf.Max(transform.eulerAngles.z + Random.Range(3, 7), -360));
        }
        else if (randRotDir == RotationDir.CounterClockwise)
        {
            transform.Rotate(rotationAxis,
                             Mathf.Min(transform.eulerAngles.z - Random.Range(3, 7), 360));
        }

        //Regenerate the rotation direction
        if (rotateCounter <= 0)
        {
            randRotDir    = GenerateRandRotNum();
            rotateCounter = ROTATION_STEPS;
        }

        rotateCounter--;
        StartCoroutine(Move());
    }
Пример #3
0
 public IEnumerator Animate(RotationDir dir)
 {
     Start(dir);
     while (Rotating)
     {
         Update();
         yield return(new WaitForEndOfFrame());
     }
 }
Пример #4
0
        public void Rotate(RotationDir dir)
        {
            if (!InputEnabled)
            {
                return;
            }

            boardController.AnimateRotation(dir);
            game.Rotate(dir);
        }
Пример #5
0
 public void Rotate(RotationDir dir)
 {
     if (dir == RotationDir.Left)
     {
         board.RotateLeft();
     }
     else
     {
         board.RotateRight();
     }
 }
Пример #6
0
        void RotatePCs(RotationDir dir)
        {
            var newPcs = new PieceController[Size, Size];

            foreach (var c_pc in CoordAndControllers)
            {
                var oldCoord = c_pc.Key;
                var pc       = c_pc.Value;
                var newCoord = RotatedCoord(pc, oldCoord, dir);
                newPcs[newCoord.row, newCoord.col] = pc;
            }
            pcs = newPcs;
        }
    /* #endregion */
    /* ======================================================================================== */

    /* #region ==== G E T  C U R R E N T  C A M E R A  P O S I T I O N ======================== */
    private void getCameraPosition(RotationDir direction)
    {
        if (CamPos == CameraPosition.South)
        {
            if (direction == RotationDir.Left)
            {
                CamPos = CameraPosition.West;
            }
            else
            {
                CamPos = CameraPosition.East;
            }
        }
        else if (CamPos == CameraPosition.East)
        {
            if (direction == RotationDir.Left)
            {
                CamPos = CameraPosition.South;
            }
            else
            {
                CamPos = CameraPosition.North;
            }
        }
        else if (CamPos == CameraPosition.North)
        {
            if (direction == RotationDir.Left)
            {
                CamPos = CameraPosition.East;
            }
            else
            {
                CamPos = CameraPosition.West;
            }
        }
        else if (CamPos == CameraPosition.West)
        {
            if (direction == RotationDir.Left)
            {
                CamPos = CameraPosition.North;
            }
            else
            {
                CamPos = CameraPosition.South;
            }
        }
        else
        {
            Debug.Log("Something bad happened! No side!", this.gameObject);
        }
    }
    /* #endregion */
    /* ======================================================================================== */

    /* #region ==== R O T A T E  M A I N  C A M E R A ========================================= */
    private void rotate(RotationDir direction)
    {
        if (direction == RotationDir.Left)
        {
            getCameraPosition(RotationDir.Left);
            transform.Rotate(Vector3.up, 90, Space.Self);
            MatchManager.MainCameraControler.UpdateCamera(CamPos);
        }
        else if (direction == RotationDir.Right)
        {
            getCameraPosition(RotationDir.Right);
            transform.Rotate(Vector3.up, -90, Space.Self);
            MatchManager.MainCameraControler.UpdateCamera(CamPos);
        }
        else
        {
            Debug.Log("No direction set!");
        }
    }
Пример #9
0
 private void SetRotationDir(RotationDir dir)
 {
     if (dir == RotationDir.Right)
     {
         curRotationX += Time.deltaTime * rotationSpeed;
         if (curRotationX > 1f)
         {
             curRotationX = 1f;
         }
     }
     else if (dir == RotationDir.Left)
     {
         curRotationX -= Time.deltaTime * rotationSpeed;
         if (curRotationX < -1f)
         {
             curRotationX = -1f;
         }
     }
     else
     {
         if (curRotationX != 0f)
         {
             if (curRotationX > 0f)
             {
                 curRotationX -= rotationSpeed * Time.deltaTime;
                 if (curRotationX < 0f)
                 {
                     curRotationX = 0f;
                 }
             }
             else
             {
                 curRotationX += rotationSpeed * Time.deltaTime;
                 if (curRotationX > 0f)
                 {
                     curRotationX = 0f;
                 }
             }
         }
     }
     Debug.Log("SetRotationDir value: " + curRotationX);
     trCharacter.localRotation = LeanToRotation(curRotationX);
 }
Пример #10
0
    // Update is called once per frame
    void Update()
    {
        if (initialize == false)
        {
            gameManager = GetComponent <GameManager>();

            initialize = true;
        }

        //if gameplay state
        if (gameManager.state == State.Gameplay)
        {
            //whilst holding right mouse button
            if (Input.GetMouseButton(1) && resetCamera == false)
            {
                rotating = true;              //allow camera to rotate

                newx = Input.mousePosition.x; //constantly update the mouse x position

                //if origin mouse x position isnt set
                if (originX == 0)
                {
                    originX = newx;    //set origin mouse x position
                }
                dist = newx - originX; //calculate how far mouse has moved

                //if player moves mouse left
                if (newx < originX)
                {
                    Dir = RotationDir.left; //Set direction enum left
                }
                //if player moves mouse right
                else if (newx > originX)
                {
                    Dir = RotationDir.right; //Set direction enum right
                }
            }
        }
    }
Пример #11
0
 Coord RotatedCoord(PieceController pc, Coord coord, RotationDir dir)
 {
     return((dir == RotationDir.Left) ?
            board.AdjustForRotateLeft(board.RotateCoordLeft(coord), pc.piece) :
            board.AdjustForRotateRight(board.RotateCoordRight(coord), pc.piece));
 }
Пример #12
0
 public void AnimateRotation(RotationDir dir)
 {
     StartCoroutine(rotator.Animate(dir));
     RotatePCs(dir);
 }
Пример #13
0
 void Start(RotationDir dir)
 {
     targetRotation   = (lastRotation + (int)dir) % 360;
     rotationProgress = 0f;
 }