Esempio n. 1
0
    /// <summary>
    /// processes the player's input from all controllers
    /// </summary>
    private void ProcessInput()
    {
        //variable to store the next node being moved to
        NodeInfo nextNode = null;

        //get input
        if (Input.GetButtonDown("Horizontal"))
        {
            if (Input.GetAxis("Horizontal") < 0)
            {
                nextNode = m_BoardController.FindNode(m_CurrentNode.GridLocation + new Vector2Int(-1, 0));
            }
            else if (Input.GetAxis("Horizontal") > 0f)
            {
                nextNode = m_BoardController.FindNode(m_CurrentNode.GridLocation + new Vector2Int(1, 0));
            }
        }
        if (Input.GetButtonDown("Vertical"))
        {
            if (Input.GetAxis("Vertical") < 0)
            {
                nextNode = m_BoardController.FindNode(m_CurrentNode.GridLocation + new Vector2Int(0, -1));
            }
            else if (Input.GetAxis("Vertical") > 0f)
            {
                nextNode = m_BoardController.FindNode(m_CurrentNode.GridLocation + new Vector2Int(0, 1));
            }
        }

        //Swipe Input
        m_SwipeController.ProcessTouchInput();
        if (m_SwipeController.SwipeLeft)
        {
            nextNode = m_BoardController.FindNode(m_CurrentNode.GridLocation + new Vector2Int(-1, 0));
        }
        if (m_SwipeController.SwipeRight)
        {
            nextNode = m_BoardController.FindNode(m_CurrentNode.GridLocation + new Vector2Int(1, 0));
        }
        if (m_SwipeController.SwipeDown)
        {
            nextNode = m_BoardController.FindNode(m_CurrentNode.GridLocation + new Vector2Int(0, -1));
        }
        if (m_SwipeController.SwipeUp)
        {
            nextNode = m_BoardController.FindNode(m_CurrentNode.GridLocation + new Vector2Int(0, 1));
        }

        //if there is a node to move to
        if (nextNode != null)
        {
            //if the player is not already jumping
            if (!m_Player.GetComponent <DudeController>().IsJumping)
            {
                //jump from this node to next node
                m_Player.GetComponent <DudeController>().MoveTo(m_CurrentNode, nextNode);
                //set the next node to the current node
                m_CurrentNode = nextNode;

                //play the jump sound
                m_JumpSound.Play();

                //check if we are increasing the score and/or cycling rows
                if (nextNode.GridLocation.y > m_PlayerScore)
                {
                    //add/remove rows
                    for (int i = nextNode.GridLocation.y - m_PlayerScore; i > 0; i--)
                    {
                        m_BoardController.CycleRows();
                    }

                    //increase the score
                    m_PlayerScore = nextNode.GridLocation.y;
                }
            }
        }

        //update the player's score in the UI
        m_ScoreLabel.text = m_PlayerScore.ToString();
    }