Пример #1
0
        public void UpdateFocus()
        {
            if (null == SelectedButton)
            {
                Log.Error(TAG, "SelectedButton is null!");
                return;
            }

            if (Mappings.ContainsKey(SelectedButton))
            {
                #region DPADS

                if (OuyaInput.GetButtonDown(OuyaController.BUTTON_DPAD_LEFT))
                {
                    if (null != Mappings[SelectedButton].Left)
                    {
                        SetSelection(Mappings[SelectedButton].Left);
                    }
                }
                else if (OuyaInput.GetButtonDown(OuyaController.BUTTON_DPAD_RIGHT))
                {
                    if (null != Mappings[SelectedButton].Right)
                    {
                        SetSelection(Mappings[SelectedButton].Right);
                    }
                }

                #endregion
            }
        }
    /* -----------------------------------------------------------------------------------
     * 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");
            }
        }
    }
Пример #3
0
    /* -----------------------------------------------------------------------------------
     * INITIAL SETUP
     */

    public void Start()
    {
        // OPTIONAL: set button state scanning to receive input state events for trigger and d-pads
        OuyaInput.SetContinuousScanning(continuousScan);

        // OPTIONAL: define the deadzone if you want to use advanced joystick and trigger access
        OuyaInput.SetDeadzone(deadzoneType, deadzone);
        OuyaInput.SetTriggerThreshold(triggerTreshold);

        // do one controller update here to get everything started as soon as possible
        OuyaInput.UpdateControllers();
    }
Пример #4
0
 /// <summary>
 /// Use default input, bypass plugin input
 /// </summary>
 public static void useDefaultInput()
 {
     if (!isIAPInitComplete())
     {
         return;
     }
     OuyaUnityPlugin.useDefaultInput();
     OuyaInput.ClearAxes();
     OuyaInput.ClearButtons();
     OuyaInput.ClearButtonStates();
     OuyaInput.ClearButtonStates();
     OuyaInput.UpdateInputFrame();
     s_useDefaultInput = true;
 }
    /* -----------------------------------------------------------------------------------
     * INITIAL SETUP
     */

    public void Start()
    {
        // set the editor platform to get correct input while testing in the editor
        OuyaInput.SetEditorPlatform(editorWorkPlatform);

        // set button state scanning to receive input state events for trigger and d-pads
        OuyaInput.SetContiniousScanning(continiousScan);

        // define the deadzone if you want to use advanced joystick and trigger access
        OuyaInput.SetDeadzone(deadzoneType, deadzone);
        OuyaInput.SetTriggerTreshold(triggerTreshold);

        // do one controller update here to get everything started as soon as possible
        OuyaInput.UpdateControllers();
    }
Пример #6
0
    void Update()
    {
        OuyaInput.UpdateControllers();

        if (OuyaInput.GetButtonDown(OuyaButton.RB, OuyaPlayer.P01))
        {
            FPSGraphC hudFps = GameObject.FindObjectOfType(typeof(FPSGraphC)) as FPSGraphC;
            hudFps.enabled = !hudFps.enabled;
        }

        if (OuyaInput.GetButtonDown(OuyaButton.LB, OuyaPlayer.P01))
        {
            OuyaInputTester inputTester = gameObject.GetComponent <OuyaInputTester>();
            inputTester.enabled = !inputTester.enabled;
        }
    }
    /* -----------------------------------------------------------------------------------
     * GUI CONTROLLER DISPLAY
     */

    public void OnGUI()
    {
        if (debug)
        {
            GUI.Label(new Rect(50, 40, 100, 20), "LX " + OuyaInput.GetAxis(OuyaAxis.LX, observedPlayer));
            GUI.Label(new Rect(50, 60, 100, 20), "LY " + OuyaInput.GetAxis(OuyaAxis.LY, observedPlayer));

            GUI.Label(new Rect(250, 40, 100, 20), "RX " + OuyaInput.GetAxis(OuyaAxis.RX, observedPlayer));
            GUI.Label(new Rect(250, 60, 100, 20), "RY " + OuyaInput.GetAxis(OuyaAxis.RY, observedPlayer));

            GUI.Label(new Rect(50, 100, 200, 20), "LT " + OuyaInput.GetAxis(OuyaAxis.LT, observedPlayer));
            GUI.Label(new Rect(50, 120, 200, 20), "RT " + OuyaInput.GetAxis(OuyaAxis.RT, observedPlayer));

            GUI.Label(new Rect(250, 100, 200, 20), "LT-B " + OuyaInput.GetButton(OuyaButton.LT, observedPlayer));
            GUI.Label(new Rect(250, 120, 200, 20), "RT-B " + OuyaInput.GetButton(OuyaButton.RT, observedPlayer));

            GUI.Label(new Rect(50, 160, 100, 20), "DX " + OuyaInput.GetAxis(OuyaAxis.DX, observedPlayer));
            GUI.Label(new Rect(50, 180, 100, 20), "DY " + OuyaInput.GetAxis(OuyaAxis.DY, observedPlayer));

            GUI.Label(new Rect(50, 200, 100, 20), "L3 " + OuyaInput.GetButton(OuyaButton.L3, observedPlayer));
            GUI.Label(new Rect(50, 220, 100, 20), "R3 " + OuyaInput.GetButton(OuyaButton.R3, observedPlayer));

            GUI.Label(new Rect(250, 160, 100, 20), "DU-B " + OuyaInput.GetButton(OuyaButton.DU, observedPlayer));
            GUI.Label(new Rect(250, 180, 100, 20), "DD-B " + OuyaInput.GetButton(OuyaButton.DD, observedPlayer));
            GUI.Label(new Rect(250, 200, 100, 20), "DL-B " + OuyaInput.GetButton(OuyaButton.DL, observedPlayer));
            GUI.Label(new Rect(250, 220, 100, 20), "DR-B " + OuyaInput.GetButton(OuyaButton.DR, observedPlayer));

            GUI.Label(new Rect(250, 260, 200, 20), "LB " + OuyaInput.GetButton(OuyaButton.LB, observedPlayer));
            GUI.Label(new Rect(250, 280, 200, 20), "RB " + OuyaInput.GetButton(OuyaButton.RB, observedPlayer));

            GUI.Label(new Rect(50, 260, 100, 20), "O " + OuyaInput.GetButton(OuyaButton.O, observedPlayer));
            GUI.Label(new Rect(50, 280, 100, 20), "U " + OuyaInput.GetButton(OuyaButton.U, observedPlayer));
            GUI.Label(new Rect(50, 300, 100, 20), "Y " + OuyaInput.GetButton(OuyaButton.Y, observedPlayer));
            GUI.Label(new Rect(50, 320, 100, 20), "A " + OuyaInput.GetButton(OuyaButton.A, observedPlayer));

            GUI.Label(new Rect(50, 360, 100, 20), "SEL " + OuyaInput.GetButton(OuyaButton.SELECT, observedPlayer));
            GUI.Label(new Rect(50, 380, 100, 20), "SYS " + OuyaInput.GetButton(OuyaButton.SYSTEM, observedPlayer));
            GUI.Label(new Rect(50, 400, 100, 20), "START " + OuyaInput.GetButton(OuyaButton.START, observedPlayer));

            GUI.Label(new Rect(50, 440, 600, 20), "JOY_L " + OuyaInput.GetJoystick(OuyaJoystick.LeftStick, observedPlayer));
            GUI.Label(new Rect(50, 460, 600, 20), "JOY_R " + OuyaInput.GetJoystick(OuyaJoystick.RightStick, observedPlayer));
            GUI.Label(new Rect(50, 480, 600, 20), "JOY_D " + OuyaInput.GetJoystick(OuyaJoystick.DPad, observedPlayer));

            GUI.Label(new Rect(50, 520, 600, 20), "NAME " + OuyaInput.GetControllerName(observedPlayer));
            GUI.Label(new Rect(50, 540, 600, 20), "TYPE " + OuyaInput.GetControllerType(observedPlayer));
        }
    }
Пример #8
0
    void Update()
    {
        if (OuyaInput.GetButtonDown(OuyaButton.O, OuyaPlayer.P01))
        {
            selectedPress = true;
        }

        if (OuyaInput.GetButtonDown(OuyaButton.DU, OuyaPlayer.P01) || OuyaInput.GetButtonDown(OuyaButton.DL, OuyaPlayer.P01))
        {
            selected--;
        }

        if (OuyaInput.GetButtonDown(OuyaButton.DD, OuyaPlayer.P01) || OuyaInput.GetButtonDown(OuyaButton.DR, OuyaPlayer.P01))
        {
            selected++;
        }
    }
Пример #9
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)
        {
            foreach (ButtonSprite button in _buttons)
            {
                if (button == _focusManager.SelectedButton)
                {
                    button.ButtonTexture = button.ButtonActive;
                }
                else
                {
                    button.ButtonTexture = button.ButtonInactive;
                }
            }

            if (OuyaInput.GetButton(OuyaController.BUTTON_DPAD_DOWN))
            {
                GetFocusManager().FocusDown();
            }
            if (OuyaInput.GetButton(OuyaController.BUTTON_DPAD_LEFT))
            {
                GetFocusManager().FocusLeft();
            }
            if (OuyaInput.GetButton(OuyaController.BUTTON_DPAD_RIGHT))
            {
                GetFocusManager().FocusRight();
            }
            if (OuyaInput.GetButton(OuyaController.BUTTON_DPAD_UP))
            {
                GetFocusManager().FocusUp();
            }
            if (OuyaInput.GetButton(OuyaController.BUTTON_O))
            {
                GetFocusManager().InvokeClick();
            }
            if (OuyaInput.GetButton(OuyaController.BUTTON_A))
            {
                Exit();
            }

            base.Update(gameTime);
        }
Пример #10
0
        /// <summary>
        /// Draw the player
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="font"></param>
        /// <param name="gameTime"></param>
        public void Draw(SpriteBatch spriteBatch, SpriteFont font, GameTime gameTime)
        {
            spriteBatch.Draw(_mTexture, _mPosition - new Vector2(_mRectangle.Width * 0.5f, _mRectangle.Height * 0.5f), Color.White);
            spriteBatch.DrawString(font, string.Format("{0}", _mIndex + 1),
                                   _mPosition + new Vector2(-5, -10),
                                   Color.Black);

            float lsX = OuyaInput.GetAxis(_mIndex, OuyaController.AXIS_LS_X);

            if (Math.Abs(lsX) > DEAD_ZONE)
            {
                _mPosition.X += lsX * (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            }
            float lsY = OuyaInput.GetAxis(_mIndex, OuyaController.AXIS_LS_Y);

            if (Math.Abs(lsY) > DEAD_ZONE)
            {
                _mPosition.Y += lsY * (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            }

            PositionPlayerInBounds();

            float rsX = OuyaInput.GetAxis(_mIndex, OuyaController.AXIS_RS_X);
            float rsY = OuyaInput.GetAxis(_mIndex, OuyaController.AXIS_RS_Y);

            if (Math.Abs(rsX) > DEAD_ZONE ||
                Math.Abs(rsY) > DEAD_ZONE)
            {
                Vector2 direction = new Vector2(rsX, rsY);
                Vector2 variance  = new Vector2((Game1._sRandom.Next() % 10 * PROJECTILE_VARIANCE), (Game1._sRandom.Next() % 10 * PROJECTILE_VARIANCE));
                direction += variance;
                if (direction != Vector2.Zero)
                {
                    direction.Normalize();
                    Game1._sProjectiles.Add(new Projectile(_mProjectilePrefab, _mPosition, direction));
                }
            }
        }
Пример #11
0
    void Update()
    {
        float rotationInput = 0f;

        //input += Input.GetAxis("Horizontal") * 120f;
        rotationInput += OuyaInput.GetAxis(OuyaAxis.LX, OuyaPlayer.P01);

        if (Input.GetKey(KeyCode.A))             // Keyboard input for testing.
        {
            rotationInput += 1.0f;
        }
        if (Input.GetKey(KeyCode.D))
        {
            rotationInput -= 1.0f;
        }

        rotationInput *= ROTATE_SPEED;

        if (Mathf.Abs(rotationInput) > Mathf.Epsilon)
        {
            EventDispatcher.SendEvent(EventKey.INPUT_ROTATE, rotationInput * Time.deltaTime);
        }
    }
Пример #12
0
        /// <summary>
        /// Draw the sprite
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void Draw(SpriteBatch spriteBatch)
        {
            Draw(spriteBatch, Controller);

            #region MENU

            if (OuyaInput.GetButtonDown(Index, OuyaController.BUTTON_MENU))
            {
                m_timerMenuDetected = DateTime.Now + TimeSpan.FromSeconds(1);
                Draw(spriteBatch, ButtonMenu);
            }
            else if (m_timerMenuDetected > DateTime.Now)
            {
                Draw(spriteBatch, ButtonMenu);
            }

            #endregion

            #region DPADS

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_DPAD_DOWN))
            {
                Draw(spriteBatch, DpadDown);
            }

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_DPAD_LEFT))
            {
                Draw(spriteBatch, DpadLeft);
            }

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_DPAD_RIGHT))
            {
                Draw(spriteBatch, DpadRight);
            }

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_DPAD_UP))
            {
                Draw(spriteBatch, DpadUp);
            }

            #endregion

            #region Buttons

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_A))
            {
                Draw(spriteBatch, ButtonA);
            }

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_O))
            {
                Draw(spriteBatch, ButtonO);
            }

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_U))
            {
                Draw(spriteBatch, ButtonU);
            }

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_Y))
            {
                Draw(spriteBatch, ButtonY);
            }

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_L1))
            {
                Draw(spriteBatch, LeftBumper);
            }

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_R1))
            {
                Draw(spriteBatch, RightBumper);
            }

            #endregion

            #region Triggers

            if (OuyaInput.GetAxis(Index, OuyaController.AXIS_L2) > DeadZone)
            {
                Draw(spriteBatch, LeftTrigger);
            }

            if (OuyaInput.GetAxis(Index, OuyaController.AXIS_R2) > DeadZone)
            {
                Draw(spriteBatch, RightTrigger);
            }

            #endregion

            #region Sticks

            //rotate input by N degrees to match image
            float degrees = 135;
            float radians = degrees / 180f * 3.14f;
            float cos     = (float)Math.Cos(radians);
            float sin     = (float)Math.Sin(radians);

            Vector2 input = new Vector2(OuyaInput.GetAxis(Index, OuyaController.AXIS_LS_X), OuyaInput.GetAxis(Index, OuyaController.AXIS_LS_Y));

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_L3) ||
                Math.Abs(input.X) > DeadZone ||
                Math.Abs(input.Y) > DeadZone)
            {
                Draw(spriteBatch, LeftStickActive, Position + AXIS_SCALER * new Vector2(input.X * cos - input.Y * sin, input.X * sin + input.Y * cos));
            }
            else
            {
                Draw(spriteBatch, LeftStickInactive, Position + AXIS_SCALER * new Vector2(input.X * cos - input.Y * sin, input.X * sin + input.Y * cos));
            }

            //rotate by same degrees
            input = new Vector2(OuyaInput.GetAxis(Index, OuyaController.AXIS_RS_X), OuyaInput.GetAxis(Index, OuyaController.AXIS_RS_Y));

            if (OuyaInput.GetButton(Index, OuyaController.BUTTON_R3) ||
                Math.Abs(input.X) > DeadZone ||
                Math.Abs(input.Y) > DeadZone)
            {
                Draw(spriteBatch, RightStickActive, Position + AXIS_SCALER * new Vector2(input.X * cos - input.Y * sin, input.X * sin + input.Y * cos));
            }
            else
            {
                Draw(spriteBatch, RightStickInactive, Position + AXIS_SCALER * new Vector2(input.X * cos - input.Y * sin, input.X * sin + input.Y * cos));
            }

            #endregion
        }
Пример #13
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);
        }
    }
Пример #14
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();
        }
Пример #15
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            #region Frames per second

            if (_mTimer < DateTime.Now)
            {
                _mFramesPerSecond = _mFrames;
                _mFrames          = 0;
                _mTimer           = DateTime.Now + TimeSpan.FromSeconds(1);
            }
            else
            {
                ++_mFrames;
            }

            #endregion

            #region Render to Light Render Texture
            GraphicsDevice.SetRenderTarget(_mLightRenderTarget);

            _sGraphics.GraphicsDevice.Clear(Color.White);

            _mSpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,
                                SamplerState.LinearClamp, DepthStencilState.Default,
                                RasterizerState.CullNone);

            foreach (Projectile projectile in _sProjectiles)
            {
                projectile.DrawLight(_mSpriteBatch);
            }

            foreach (Player player in _mPlayers)
            {
                player.DrawLight(_mSpriteBatch);
            }

            _mSpriteBatch.End();
            #endregion

            #region Render to Render Texture
            GraphicsDevice.SetRenderTarget(_mRenderTarget);

            _sGraphics.GraphicsDevice.Clear(Color.Green);

            _mSpriteBatch.Begin();
            foreach (Projectile projectile in _sProjectiles)
            {
                projectile.Draw(_mSpriteBatch, _mFont, gameTime);
            }
            foreach (Player player in _mPlayers)
            {
                player.Draw(_mSpriteBatch, _mFont, gameTime);
            }
            _mSpriteBatch.End();
            #endregion

            GraphicsDevice.SetRenderTarget(null);

            // draw through effect
            _mSpriteBatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, _mLightingEffect, Matrix.Identity);
            _mSpriteBatch.Draw(_mRenderTarget, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            _mSpriteBatch.End();

            //draw light source
            _mSpriteBatch.Begin();
            _mSpriteBatch.Draw(_mLightRenderTarget, Vector2.Zero, new Rectangle(0, 0, 200, 400), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            _mSpriteBatch.Draw(_mRenderTarget, new Vector2(200, 0), new Rectangle(200, 0, 200, 400), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            _mSpriteBatch.End();

            // set sampler
            GraphicsDevice.Textures[1] = _mLightRenderTarget;
            _mLightingEffect.Parameters["LightSampler"].SetValue(_mLightRenderTarget);

            _mSpriteBatch.Begin();
            _mSpriteBatch.DrawString(_mFont,
                                     string.Format("Hello from MonoGame: Projectiles={0} FPS={1:F2}", _sProjectiles.Count, _mFramesPerSecond),
                                     new Vector2(Window.ClientBounds.Width / 2 - 200, Window.ClientBounds.Height / 2 - 40), Color.White);
            _mSpriteBatch.End();

            OuyaInput.ClearButtonStates();

            base.Draw(gameTime);

            while (_sProjectiles.Count > 0 &&
                   _sProjectiles[0]._mLifeTime < 0)
            {
                _sProjectiles.RemoveAt(0);
            }
        }