Exemple #1
0
        protected virtual bool OnGamePadButtonEvent(GamePadButtonEvent e)
        {
            // Allows the game to exit
            if (e.Button == Buttons.Back && e.EventType == InputEventType.Pressed)
            {
                MessageDispatcher.Get().SendMessage(new Message(MessageType.EndGame, this, this));
            }

            return true;
        }
Exemple #2
0
        bool OnGamePadDirectionEvent(GamePadButtonEvent e)
        {
            // TODO: design some way to map events to messages to avoid switch code like this
            if ((e.Button == Buttons.LeftThumbstickLeft) ||
                (e.Button == Buttons.DPadLeft))
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    emitterPosition.X -= 15;
                }
            }
            else if ((e.Button == Buttons.LeftThumbstickRight) ||
                     (e.Button == Buttons.DPadRight))
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    emitterPosition.X += 15;
                }
            }
            else if ((e.Button == Buttons.LeftThumbstickUp) ||
                     (e.Button == Buttons.DPadUp))
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    emitterPosition.Y -= 15;
                }
            }
            else if ((e.Button == Buttons.LeftThumbstickDown) ||
                     (e.Button == Buttons.DPadDown))
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    emitterPosition.Y += 15;
                }
            }

            return true;
        }
Exemple #3
0
 public void FireEvent(GamePadButtonEvent e)
 {
     OnGamePadButtonEvent(e);
 }
Exemple #4
0
        private void QueryInputsAndFireEvents()
        {
            // Check Variable Inputs
            foreach (RegisteredVariableInput rvi in m_registeredVariableInput)
            {
                Vector2 value = Vector2.Zero;
                bool haveInput = false;
                switch (rvi.InputType)
                {
                    case VariableInputType.Mouse:
                        if ((MouseState.X != PrevMouseState.X) ||
                            (MouseState.Y != PrevMouseState.Y))
                        {
                            value = new Vector2(MouseState.X, MouseState.Y);
                            haveInput = true;
                        }
                        break;
                    case VariableInputType.LeftThumbStick:
                        if (GamePadState.ThumbSticks.Left != PrevGamePadState.ThumbSticks.Left)
                        {
                            value = GamePadState.ThumbSticks.Left;
                            haveInput = true;
                        }
                        break;
                    case VariableInputType.RightThumbStick:
                        if (GamePadState.ThumbSticks.Right != PrevGamePadState.ThumbSticks.Right)
                        {
                            value = GamePadState.ThumbSticks.Right;
                            haveInput = true;
                        }
                        break;
                    case VariableInputType.LeftTrigger:
                        if (GamePadState.Triggers.Left != PrevGamePadState.Triggers.Left)
                        {
                            value = new Vector2(GamePadState.Triggers.Left, 0);
                            haveInput = true;
                        }
                        break;
                    case VariableInputType.RightTrigger:
                        if (GamePadState.Triggers.Right != PrevGamePadState.Triggers.Right)
                        {
                            value = new Vector2(GamePadState.Triggers.Right, 0);
                            haveInput = true;
                        }
                        break;
                    default:
                        // TODO: error!
                        break;
                };

                if (haveInput == true)
                {
                    VariableInputEvent e = new VariableInputEvent(InputEventType.ChangedValue, rvi.InputType, value);
                    rvi.FireEvent(e);
                }
            }

            // Check Buttons
            foreach (RegisteredGamePadButton rb in m_registeredButtons)
            {
                if (PrevGamePadState.IsButtonDown(rb.Button) != GamePadState.IsButtonDown(rb.Button))
                {
                    GamePadButtonEvent e;
                    if (GamePadState.IsButtonDown(rb.Button))
                    {
                        e = new GamePadButtonEvent(InputEventType.Pressed, rb.Button);
                    }
                    else
                    {
                        e = new GamePadButtonEvent(InputEventType.Released, rb.Button);
                    }

                    rb.FireEvent(e);
                }
            }

            // Check Keys
            foreach (RegisteredKey rkey in m_registeredKeys)
            {
                if (PrevKeyboardState.IsKeyDown(rkey.Key) != KeyboardState.IsKeyDown(rkey.Key))
                {
                    KeyboardEvent e;
                    if (KeyboardState.IsKeyDown(rkey.Key))
                    {
                        e = new KeyboardEvent(InputEventType.Pressed, rkey.Key);
                    }
                    else
                    {
                        e = new KeyboardEvent(InputEventType.Released, rkey.Key);
                    }

                    rkey.FireEvent(e);
                }
            }
        }
Exemple #5
0
        bool OnGamePadDirectionEvent(GamePadButtonEvent e)
        {
            // TODO: design some way to map events to messages to avoid switch code like this
            if ((e.Button == Buttons.LeftThumbstickLeft) ||
                (e.Button == Buttons.DPadLeft))
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    Message msg = new Message(MessageType.MoveLeft, this, m_playerOne);
                    MessageDispatcher.Get().SendMessage(msg);
                }
                else if ((e.EventType == InputEventType.Released) &&
                         (InputMgr.Get().GamePadState.IsButtonUp(Buttons.LeftThumbstickRight)) &&
                         (InputMgr.Get().GamePadState.IsButtonUp(Buttons.DPadRight)))
                {
                    // TODO: need a better way of handling mutually exclusive button inputs

                    Message msg = new Message(MessageType.Stand, this, m_playerOne);
                    MessageDispatcher.Get().SendMessage(msg);
                }
            }
            else if ((e.Button == Buttons.LeftThumbstickRight) ||
                     (e.Button == Buttons.DPadRight))
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    Message msg = new Message(MessageType.MoveRight, this, m_playerOne);
                    MessageDispatcher.Get().SendMessage(msg);
                }
                else if ((e.EventType == InputEventType.Released) &&
                         (InputMgr.Get().GamePadState.IsButtonUp(Buttons.LeftThumbstickLeft)) &&
                         (InputMgr.Get().GamePadState.IsButtonUp(Buttons.DPadLeft)))
                {
                    // TODO: need a better way of handling mutually exclusive button inputs

                    Message msg = new Message(MessageType.Stand, this, m_playerOne);
                    MessageDispatcher.Get().SendMessage(msg);
                }
            }

            return true;
        }
Exemple #6
0
 bool DebugOnGamePadButtonEvent(GamePadButtonEvent e)
 {
     return true;
 }
Exemple #7
0
        protected override bool OnGamePadButtonEvent(GamePadButtonEvent e)
        {
            bool ret = true;

            if (e.Button == Buttons.B)
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    // start jump
                    Message msg = new Message(MessageType.Jump, this, m_playerOne);
                    MessageDispatcher.Get().SendMessage(msg);
                }
                else if (e.EventType == InputEventType.Released)
                {
                    // end jump!
                    Message msg = new Message(MessageType.Fall, this, m_playerOne);
                    MessageDispatcher.Get().SendMessage(msg);
                }
            }
            else if ((e.Button == Buttons.Y) && (e.EventType == InputEventType.Pressed))
            {
                // Fire
                Message msg = new Message(MessageType.FireWeapon, this, m_playerOne);
                MessageDispatcher.Get().SendMessage(msg);
            }
            else
            {
                ret = base.OnGamePadButtonEvent(e);
            }

            return ret;
        }