示例#1
0
    IEnumerator ContinousMove(bool isLeft)
    {
        while (true)
        {
            TetrisGame.GetInstance().MoveTetromino(isLeft ? MoveDirection.Left : MoveDirection.Right);

            yield return(new WaitForSeconds(continousMoveTime));
        }
    }
示例#2
0
    public void StartGame()
    {
        score          = 0;
        Time.timeScale = 1.0f;

        InputController.EnableInput();
        UIManager.GetInstance().HideGameOverPanel();
        UIManager.GetInstance().UpdateScoreText(score);
        TetrisGame.GetInstance().StartNewGame();
    }
示例#3
0
    public void GameOver()
    {
        Time.timeScale = 0.0f;

        InputController.DisableInput();
        UIManager.GetInstance().ShowGameOverPanel();
        TetrisGame.GetInstance().GameOver();
        // Post highscore to database.
        if (isHighscoreBitten)
        {
            isHighscoreBitten = false;
            UserDatabase.Get().SyncUserHighscore();
        }
    }
示例#4
0
 public void ResumeGame()
 {
     Time.timeScale = 1.0f;
     TetrisGame.GetInstance().ResumeGame();
     InputController.EnableInput();
 }
示例#5
0
 public void PauseGame()
 {
     Time.timeScale = 0.0f;
     InputController.DisableInput();
     TetrisGame.GetInstance().PauseGame();
 }
示例#6
0
    void GetPlayerInput()
    {
 #if UNITY_STANDALONE || UNITY_EDITOR
        if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D))
        {
            StopCoroutine(continousMoveCorountine);
            continousMoveCorountine = null;
        }

        if (continousMoveCorountine == null && (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))) // Moving Tetromino to left or right.
        {
            bool isLeft = Input.GetKey(KeyCode.A);                                                   // If Key "A" is pressed - move left, otherwise Key "D" is pressed - move right.
            continousMoveCorountine = StartCoroutine(ContinousMove(isLeft));
        }

        if (Input.GetKeyDown(KeyCode.W)) // Rotating Tetromino.
        {
            TetrisGame.GetInstance().RotateTetromino();
        }
        else if (Input.GetKeyDown(KeyCode.S)) // Moving Tetromino to down.
        {
            TetrisGame.GetInstance().DownKeyPressed();
        }

        // Mouse Input.
        if (Input.GetMouseButtonDown(0))
        {
            swipeStart = Input.mousePosition;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (!isDraging)
            {
                TetrisGame.GetInstance().RotateTetromino();
            }
            else
            {
                isDraging = false;
            }
        }
        if (Input.GetMouseButton(0))
        {
            // Calculate the distance.
            swipeDelta = (Vector2)Input.mousePosition - swipeStart;

            // Did we cross the threshold?
            if (swipeDelta.magnitude > swipeThreshold)
            {
                isDraging = true;
                // Which direction?
                if (Mathf.Abs(swipeDelta.x) > Mathf.Abs(swipeDelta.y))
                {
                    // Left or Right.
                    if (swipeDelta.x > 0)
                    {
                        TetrisGame.GetInstance().MoveTetromino(MoveDirection.Right);
                    }
                    else
                    {
                        TetrisGame.GetInstance().MoveTetromino(MoveDirection.Left);
                    }
                }
                else
                {
                    // Up or Down.
                    if (swipeDelta.y < 0)
                    {
                        TetrisGame.GetInstance().DownKeyPressed();
                    }
                }

                swipeStart += swipeDelta;
                swipeDelta  = Vector2.zero;
            }
        }
#endif
        if (Input.touches.Length > 0)
        {
            if (Input.touches.Length > 0)
            {
                if (Input.touches[0].phase == TouchPhase.Began)
                {
                    swipeStart = Input.touches[0].position;
                }
                else if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled)
                {
                    if (!isDraging)
                    {
                        TetrisGame.GetInstance().RotateTetromino();
                    }
                    else
                    {
                        isDraging = false;
                    }
                }
            }
            // Calculate the distance.
            swipeDelta = Input.touches[0].position - swipeStart;

            // Did we cross the threshold?
            if (swipeDelta.magnitude > swipeThreshold)
            {
                isDraging = true;
                // Which direction?
                if (Mathf.Abs(swipeDelta.x) > Mathf.Abs(swipeDelta.y))
                {
                    // Left or Right.
                    if (swipeDelta.x > 0)
                    {
                        TetrisGame.GetInstance().MoveTetromino(MoveDirection.Right);
                    }
                    else
                    {
                        TetrisGame.GetInstance().MoveTetromino(MoveDirection.Left);
                    }
                }
                else
                {
                    // Up or Down.
                    if (swipeDelta.y < 0)
                    {
                        TetrisGame.GetInstance().DownKeyPressed();
                    }
                }

                swipeStart += swipeDelta;
                swipeDelta  = Vector2.zero;
            }
        }
    }