void UpdateWorker() { while (_keepRunning) { foreach (VirtualControllerSprite controller in _game.Controllers) { controller.UpdateInput(); } OuyaInput.clearButtonStates(); Thread.Sleep(10); } }
/// <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) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); #if MONOGAME_4_4 spriteBatch.DrawString(font, "Hello from MonoGame: " + DateTime.Now.ToString(), new Vector2(Window.ClientBounds.Width / 2 - 200, Window.ClientBounds.Height / 2 - 40), Color.White); #else spriteBatch.DrawString(font, "Hello from MonoGame: " + DateTime.Now.ToString(), new Vector2(Window.Width / 2 - 200, Window.Height / 2 - 40), Color.White); #endif Vector2 position = new Vector2(400, 100); int index = 0; for (; index < m_controllerButtons.Count && index < 7; ++index) { Texture2D texture = m_controllerButtons [index]; if (null != texture) { spriteBatch.Draw(texture, position, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); position.X += texture.Width; } } foreach (VirtualControllerSprite controller in Controllers) { controller.Draw(spriteBatch); } position = new Vector2(400, 800); for (; index < m_controllerButtons.Count; ++index) { Texture2D texture = m_controllerButtons [index]; if (null != texture) { spriteBatch.Draw(texture, position, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); position.X += texture.Width; } } spriteBatch.End(); OuyaInput.ClearButtonStates(); base.Draw(gameTime); }
public void UpdateInput() { #region Track Axis States lock (m_axisStates) { m_axisStates[OuyaController.AXIS_LS_X] = OuyaInput.getAxis(Index, OuyaController.AXIS_LS_X); m_axisStates[OuyaController.AXIS_LS_Y] = OuyaInput.getAxis(Index, OuyaController.AXIS_LS_Y); m_axisStates[OuyaController.AXIS_RS_X] = OuyaInput.getAxis(Index, OuyaController.AXIS_RS_X); m_axisStates[OuyaController.AXIS_RS_Y] = OuyaInput.getAxis(Index, OuyaController.AXIS_RS_Y); m_axisStates[OuyaController.AXIS_L2] = OuyaInput.getAxis(Index, OuyaController.AXIS_L2); m_axisStates[OuyaController.AXIS_R2] = OuyaInput.getAxis(Index, OuyaController.AXIS_R2); } #endregion #region Track Button Up / Down States lock (m_buttonStates) { m_buttonStates[OuyaController.BUTTON_O] = OuyaInput.isPressed(Index, OuyaController.BUTTON_O); m_buttonStates[OuyaController.BUTTON_U] = OuyaInput.isPressed(Index, OuyaController.BUTTON_U); m_buttonStates[OuyaController.BUTTON_Y] = OuyaInput.isPressed(Index, OuyaController.BUTTON_Y); m_buttonStates[OuyaController.BUTTON_A] = OuyaInput.isPressed(Index, OuyaController.BUTTON_A); m_buttonStates[OuyaController.BUTTON_L1] = OuyaInput.isPressed(Index, OuyaController.BUTTON_L1); m_buttonStates[OuyaController.BUTTON_R1] = OuyaInput.isPressed(Index, OuyaController.BUTTON_R1); m_buttonStates[OuyaController.BUTTON_L3] = OuyaInput.isPressed(Index, OuyaController.BUTTON_L3); m_buttonStates[OuyaController.BUTTON_R3] = OuyaInput.isPressed(Index, OuyaController.BUTTON_R3); m_buttonStates[OuyaController.BUTTON_DPAD_UP] = OuyaInput.isPressed(Index, OuyaController.BUTTON_DPAD_UP); m_buttonStates[OuyaController.BUTTON_DPAD_DOWN] = OuyaInput.isPressed(Index, OuyaController.BUTTON_DPAD_DOWN); m_buttonStates[OuyaController.BUTTON_DPAD_RIGHT] = OuyaInput.isPressed(Index, OuyaController.BUTTON_DPAD_RIGHT); m_buttonStates[OuyaController.BUTTON_DPAD_LEFT] = OuyaInput.isPressed(Index, OuyaController.BUTTON_DPAD_LEFT); m_buttonStates[OuyaController.BUTTON_MENU] = OuyaInput.isPressed(Index, OuyaController.BUTTON_MENU); } lock (m_buttonDownStates) { m_buttonDownStates[OuyaController.BUTTON_O] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_O); m_buttonDownStates[OuyaController.BUTTON_U] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_U); m_buttonDownStates[OuyaController.BUTTON_Y] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_Y); m_buttonDownStates[OuyaController.BUTTON_A] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_A); m_buttonDownStates[OuyaController.BUTTON_L1] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_L1); m_buttonDownStates[OuyaController.BUTTON_R1] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_R1); m_buttonDownStates[OuyaController.BUTTON_L3] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_L3); m_buttonDownStates[OuyaController.BUTTON_R3] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_R3); m_buttonDownStates[OuyaController.BUTTON_DPAD_UP] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_DPAD_UP); m_buttonDownStates[OuyaController.BUTTON_DPAD_DOWN] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_DPAD_DOWN); m_buttonDownStates[OuyaController.BUTTON_DPAD_RIGHT] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_DPAD_RIGHT); m_buttonDownStates[OuyaController.BUTTON_DPAD_LEFT] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_DPAD_LEFT); m_buttonDownStates[OuyaController.BUTTON_MENU] = OuyaInput.isPressedDown(Index, OuyaController.BUTTON_MENU); } lock (m_buttonUpStates) { m_buttonUpStates[OuyaController.BUTTON_O] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_O); m_buttonUpStates[OuyaController.BUTTON_U] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_U); m_buttonUpStates[OuyaController.BUTTON_Y] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_Y); m_buttonUpStates[OuyaController.BUTTON_A] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_A); m_buttonUpStates[OuyaController.BUTTON_L1] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_L1); m_buttonUpStates[OuyaController.BUTTON_R1] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_R1); m_buttonUpStates[OuyaController.BUTTON_L3] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_L3); m_buttonUpStates[OuyaController.BUTTON_R3] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_R3); m_buttonUpStates[OuyaController.BUTTON_DPAD_UP] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_DPAD_UP); m_buttonUpStates[OuyaController.BUTTON_DPAD_DOWN] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_DPAD_DOWN); m_buttonUpStates[OuyaController.BUTTON_DPAD_RIGHT] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_DPAD_RIGHT); m_buttonUpStates[OuyaController.BUTTON_DPAD_LEFT] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_DPAD_LEFT); m_buttonUpStates[OuyaController.BUTTON_MENU] = OuyaInput.isPressedUp(Index, OuyaController.BUTTON_MENU); } #endregion //debugOuyaController(deviceId); }
/// <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)) { 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)) { 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 }