Ejemplo n.º 1
0
        protected virtual bool OnKeyboardEvent(KeyboardEvent e)
        {
            if (e.Key == Keys.P)
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    if (State == GameState.Pause)
                    {
                        MessageDispatcher.Get().SendMessage(new Message(MessageType.PlayGame, this, this));
                    }
                    else if (State == GameState.Play)
                    {
                        MessageDispatcher.Get().SendMessage(new Message(MessageType.PauseGame, this, this));
                    }
                }
            }
            else if (e.Key == Keys.Q)
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    MessageDispatcher.Get().SendMessage(new Message(MessageType.EndGame, this, this));
                }
            }
            else if (e.Key == Keys.F1)
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    DrawCollisionRects = !DrawCollisionRects;
                }
            }

            return true;
        }
Ejemplo n.º 2
0
 public void FireEvent(KeyboardEvent e)
 {
     OnKeyboardEvent(e);
 }
Ejemplo n.º 3
0
Archivo: Ceres.cs Proyecto: endy/IvyXNA
        bool OnKeyboardDirectionEvent(KeyboardEvent e)
        {
            // TODO: design some way to map events to messages to avoid switch code like this

            // TODO:  add some intelligence here to make sure that left and right keys are mutually exclusive
            if (e.Key == Keys.Left)
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    Message msg = new Message(MessageType.MoveLeft, this, m_playerOne);
                    MessageDispatcher.Get().SendMessage(msg);
                }
                else if (e.EventType == InputEventType.Released)
                {
                    Message msg = new Message(MessageType.Stand, this, m_playerOne);
                    MessageDispatcher.Get().SendMessage(msg);
                }
            }
            else if (e.Key == Keys.Right)
            {
                if (e.EventType == InputEventType.Pressed)
                {
                    Message msg = new Message(MessageType.MoveRight, this, m_playerOne);
                    MessageDispatcher.Get().SendMessage(msg);
                }
                else if (e.EventType == InputEventType.Released)
                {
                    Message msg = new Message(MessageType.Stand, this, m_playerOne);
                    MessageDispatcher.Get().SendMessage(msg);
                }
            }

            return true;
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 5
0
Archivo: Ceres.cs Proyecto: endy/IvyXNA
        protected override bool OnKeyboardEvent(KeyboardEvent e)
        {
            bool ret = true;

            // Jump!
            if (e.Key == Keys.Space)
            {
                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.Key == Keys.F) && (e.EventType == InputEventType.Pressed))
            {
                // Fire
                Message msg = new Message(MessageType.FireWeapon, this, m_playerOne);
                MessageDispatcher.Get().SendMessage(msg);
            }
            else
            {
                ret = base.OnKeyboardEvent(e);
            }

            return ret;
        }