/* -----------------------------------------------------------------------------------
     * GUI CONTROLLER DISPLAY
     */

    public void Update()
    {
        if (debug)
        {
            /* UPDATE CONTROLERS */
            // IMPORTANT! update the controllers here for best results
            OuyaInput.UpdateControllers();

            /* CONSOLE TRIGGER AND D-PAD EVENTS */
            if (OuyaInput.GetButtonDown(OuyaButton.LT, observedPlayer))
            {
                Debug.Log("LT down event");
            }
            if (OuyaInput.GetButtonUp(OuyaButton.LT, observedPlayer))
            {
                Debug.Log("LT up event");
            }
            if (OuyaInput.GetButtonDown(OuyaButton.RT, observedPlayer))
            {
                Debug.Log("RT down event");
            }
            if (OuyaInput.GetButtonUp(OuyaButton.RT, observedPlayer))
            {
                Debug.Log("RT up event");
            }
            if (OuyaInput.GetButtonUp(OuyaButton.DU, observedPlayer))
            {
                Debug.Log("DU up event");
            }
            if (OuyaInput.GetButtonDown(OuyaButton.DU, observedPlayer))
            {
                Debug.Log("DU down event");
            }
            if (OuyaInput.GetButtonUp(OuyaButton.DD, observedPlayer))
            {
                Debug.Log("DD up event");
            }
            if (OuyaInput.GetButtonDown(OuyaButton.DD, observedPlayer))
            {
                Debug.Log("DD down event");
            }
            if (OuyaInput.GetButtonUp(OuyaButton.DR, observedPlayer))
            {
                Debug.Log("DR up event");
            }
            if (OuyaInput.GetButtonDown(OuyaButton.DR, observedPlayer))
            {
                Debug.Log("DR down event");
            }
            if (OuyaInput.GetButtonUp(OuyaButton.DL, observedPlayer))
            {
                Debug.Log("DL up event");
            }
            if (OuyaInput.GetButtonDown(OuyaButton.DL, observedPlayer))
            {
                Debug.Log("DL down event");
            }
        }
    }
Beispiel #2
0
    /* -----------------------------------------------------------------------------------
     * UPDATE CYCLE
     */

    public void Update()
    {
        /* UPDATE CONTROLERS */
        // IMPORTANT! update the controllers here for best results
        OuyaInput.UpdateControllers();

        /* GET VALUES FOR CONTROLLER AXES */

        // left joystick
        float x_Axis_LeftStick = OuyaInput.GetAxis(OuyaAxis.LX, player);
        float y_Axis_LeftStick = OuyaInput.GetAxis(OuyaAxis.LY, player);

        // right joystick
        float x_Axis_RightStick = OuyaInput.GetAxis(OuyaAxis.RX, player);
        float y_Axis_RightStick = OuyaInput.GetAxis(OuyaAxis.RY, player);

        // d-pad
        float x_Axis_DPad = OuyaInput.GetAxis(OuyaAxis.DX, player);
        float y_Axis_DPad = OuyaInput.GetAxis(OuyaAxis.DY, player);

        // triggers
        float axis_LeftTrigger  = OuyaInput.GetAxis(OuyaAxis.LT, player);
        float axis_RightTrigger = OuyaInput.GetAxis(OuyaAxis.RT, player);

        // examples for deadzone clipping (we can choose between three types)
        Vector2 leftStickInput  = OuyaInput.CheckDeadzoneCircular(x_Axis_LeftStick, y_Axis_LeftStick, deadzone);
        Vector2 rightStickInput = OuyaInput.CheckDeadzoneRescaled(x_Axis_RightStick, y_Axis_RightStick, deadzone);
        Vector2 dPadInput       = OuyaInput.CheckDeadzoneRescaled(x_Axis_DPad, y_Axis_DPad, deadzone);

        /* GET ADVANCED JOYSTICK AND TRIGGER INPUT WITH DEADZONE MAPPING */

        // examples for easy (or precision) joystick input
        Vector2 leftJoystick  = OuyaInput.GetJoystick(OuyaJoystick.LeftStick, player);
        Vector2 rightJoystick = OuyaInput.GetJoystick(OuyaJoystick.RightStick, player);
        Vector2 dPad          = OuyaInput.GetJoystick(OuyaJoystick.DPad, player);

        // examples for easy (or precision) trigger input
        float leftTrigger  = OuyaInput.GetTrigger(OuyaTrigger.Left, player);
        float rightTrigger = OuyaInput.GetTrigger(OuyaTrigger.Right, player);

        /* GET PRESSED STATES FOR CONTROLLER BUTTONS */

        // O U Y A buttons
        bool pressed_O = OuyaInput.GetButton(OuyaButton.O, player);
        bool pressed_U = OuyaInput.GetButton(OuyaButton.U, player);
        bool pressed_Y = OuyaInput.GetButton(OuyaButton.Y, player);
        bool pressed_A = OuyaInput.GetButton(OuyaButton.A, player);

        // joystick click down buttons
        bool pressed_LeftStick  = OuyaInput.GetButton(OuyaButton.L3, player);
        bool pressed_RightStick = OuyaInput.GetButton(OuyaButton.R3, player);

        // trigger buttons
        bool pressed_LeftTrigger  = OuyaInput.GetButton(OuyaButton.LT, player);
        bool pressed_RightTrigger = OuyaInput.GetButton(OuyaButton.RT, player);

        //shoulder buttons
        bool pressed_LeftShoulder  = OuyaInput.GetButton(OuyaButton.LB, player);
        bool pressed_RightShoulder = OuyaInput.GetButton(OuyaButton.RB, player);

        // center buttons
        bool pressed_Start  = OuyaInput.GetButton(OuyaButton.START, player);
        bool pressed_Select = OuyaInput.GetButton(OuyaButton.SELECT, player);
        bool pressed_System = OuyaInput.GetButton(OuyaButton.SYSTEM, player);

        /* GET DOWN EVENTS FOR CONTROLLER BUTTONS */

        // we need to have OuyaInput.SetContinuousScanning(true) in Start()
        // some controllers might work without this but we want to make sure
        if (continuousScan)
        {
            // O U Y A buttons
            bool down_O = OuyaInput.GetButtonDown(OuyaButton.O, player);
            bool down_U = OuyaInput.GetButtonDown(OuyaButton.U, player);
            bool down_Y = OuyaInput.GetButtonDown(OuyaButton.Y, player);
            bool down_A = OuyaInput.GetButtonDown(OuyaButton.A, player);

            // joystick click down buttons
            bool down_LeftStick  = OuyaInput.GetButtonDown(OuyaButton.L3, player);
            bool down_RightStick = OuyaInput.GetButtonDown(OuyaButton.R3, player);

            // trigger buttons
            bool down_LeftTrigger  = OuyaInput.GetButtonDown(OuyaButton.LT, player);
            bool down_RightTrigger = OuyaInput.GetButtonDown(OuyaButton.RT, player);

            //shoulder buttons
            bool down_LeftShoulder  = OuyaInput.GetButtonDown(OuyaButton.LB, player);
            bool down_RightShoulder = OuyaInput.GetButtonDown(OuyaButton.RB, player);

            // center buttons
            bool down_Start  = OuyaInput.GetButtonDown(OuyaButton.START, player);
            bool down_Select = OuyaInput.GetButtonDown(OuyaButton.SELECT, player);
            bool down_System = OuyaInput.GetButtonDown(OuyaButton.SYSTEM, player);
        }

        /* GET UP (RELEASE) EVENTS FOR CONTROLLER BUTTONS */

        // we need to have OuyaInput.SetContinuousScanning(true) in Start()
        // some controllers might work without this but we want to make sure
        if (continuousScan)
        {
            // O U Y A buttons
            bool up_O = OuyaInput.GetButtonUp(OuyaButton.O, player);
            bool up_U = OuyaInput.GetButtonUp(OuyaButton.U, player);
            bool up_Y = OuyaInput.GetButtonUp(OuyaButton.Y, player);
            bool up_A = OuyaInput.GetButtonUp(OuyaButton.A, player);

            // joystick click down buttons
            bool up_LeftStick  = OuyaInput.GetButtonUp(OuyaButton.L3, player);
            bool up_RightStick = OuyaInput.GetButtonUp(OuyaButton.R3, player);

            // trigger buttons
            bool up_LeftTrigger  = OuyaInput.GetButtonUp(OuyaButton.LT, player);
            bool up_RightTrigger = OuyaInput.GetButtonUp(OuyaButton.RT, player);

            //shoulder buttons
            bool up_LeftShoulder  = OuyaInput.GetButtonUp(OuyaButton.LB, player);
            bool up_RightShoulder = OuyaInput.GetButtonUp(OuyaButton.RB, player);

            // center buttons
            bool up_Start  = OuyaInput.GetButtonUp(OuyaButton.START, player);
            bool up_Select = OuyaInput.GetButtonUp(OuyaButton.SELECT, player);
            bool up_System = OuyaInput.GetButtonUp(OuyaButton.SYSTEM, player);
        }
    }
Beispiel #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Log.Info(TAG, string.Format("BUTTON_O is {0}", OuyaInput.GetButton(OuyaController.BUTTON_O)));

            if (OuyaInput.GetButtonUp(0, OuyaController.BUTTON_A))
            {
                Exit();
            }

            // TODO: Add your update logic here
            m_focusManager.UpdateFocus();

            foreach (ButtonSprite button in m_buttons)
            {
                // button is active if the selected button is true
                button.m_isActive = (button == m_focusManager.SelectedButton);
            }

            if (OuyaInput.GetButtonUp(OuyaController.BUTTON_MENU))
            {
                m_debugText = "Pause button detected.";
                m_focusManager.SelectedButton = BtnPause;
            }

            if (OuyaInput.GetButtonUp(OuyaController.BUTTON_O))
            {
                if (m_focusManager.SelectedButton == BtnRequestProducts)
                {
                    s_productIndex = 0;
                    s_products.Clear();
                    m_debugText = "Requesting products...";
                    Activity1.RequestProducts();
                }
                else if (m_focusManager.SelectedButton == BtnRequestPurchase)
                {
                    if (s_productIndex < s_products.Count)
                    {
                        Purchasable purchasable = new Purchasable(s_products [s_productIndex].Identifier);
                        m_debugText = "Requesting purchase...";
                        Activity1.RequestPurchase(purchasable);
                    }
                    else
                    {
                        m_debugText = "Be sure to request products to select a purchase...";
                    }
                }
                else if (m_focusManager.SelectedButton == BtnRequestReceipts)
                {
                    m_debugText = "Requesting receipts...";
                    Activity1.RequestReceipts();
                }
                else if (m_focusManager.SelectedButton == BtnRequestGamerInfo)
                {
                    m_debugText = "Requesting GamerInfo...";
                    Activity1.RequestGamerInfo();
                }
                else if (m_focusManager.SelectedButton == BtnExit)
                {
                    m_debugText = "Exiting...";
                    Activity1.Quit();
                }
                else if (m_focusManager.SelectedButton == BtnPause)
                {
                    m_debugText = "Pause button detected...";
                    m_focusManager.SelectedButton = BtnPause;
                }
            }

            if (m_focusManager.SelectedButton == BtnRequestProducts ||
                m_focusManager.SelectedButton == BtnRequestPurchase)
            {
                if (OuyaInput.GetButtonUp(OuyaController.BUTTON_DPAD_UP))
                {
                    if (s_productIndex > 0)
                    {
                        --s_productIndex;
                    }
                }
                if (OuyaInput.GetButtonUp(OuyaController.BUTTON_DPAD_DOWN))
                {
                    if ((s_productIndex + 1) < s_products.Count)
                    {
                        ++s_productIndex;
                    }
                }
            }

            base.Update(gameTime);

            OuyaInput.ClearButtonStates();
        }