Exemplo n.º 1
0
        public bool ActionReleased(InputActions action)
        {
            if (!IsPressed.ContainsKey(action) || !WasPressed.ContainsKey(action))
            {
                return(false);
            }

            return(!IsPressed[action] && WasPressed[action]);
        }
Exemplo n.º 2
0
        public void Update()
        {
            if (GameServices.GetService<ShroomGame>().IsActive)
            {
                this._lastState = this._state;
                this._state = Mouse.GetState();
                this._lastPosition = new Vector2(GameServices.GetService<GraphicsDevice>().Viewport.Width / 2,
                    GameServices.GetService<GraphicsDevice>().Viewport.Height / 2);
                this._currentPosition = new Vector2(this._state.X, this._state.Y);
                if(ShroomGame.actualGameState != GameState.Dead && ShroomGame.actualGameState != GameState.MainMenu && ShroomGame.actualGameState != GameState.Options && ShroomGame.actualGameState != GameState.Credits)
                {
                    Mouse.SetPosition(GameServices.GetService<GraphicsDevice>().Viewport.Width / 2,
                    GameServices.GetService<GraphicsDevice>().Viewport.Height / 2);
                }
                this.ScrollTotal = this._state.ScrollWheelValue;
                this.ScrollValue = this._state.ScrollWheelValue - this._lastState.ScrollWheelValue;
                if (this.ScrollValue != 0)
                    //To podobnie jak wyżej
                {
                    Scroll?.Invoke(this.ScrollValue);
                }


                foreach (var key in this._keys.Keys)
                {
                    switch (key)
                    {
                        case SupportedMouseButtons.Left:
                            this[key].Update(this._state.LeftButton == ButtonState.Pressed);
                            break;

                        case SupportedMouseButtons.Right:
                            this[key].Update(this._state.RightButton == ButtonState.Pressed);
                            break;

                        case SupportedMouseButtons.Middle:
                            this[key].Update(this._state.MiddleButton == ButtonState.Pressed);
                            break;

                        default:
                            break;
                    }

                    if (this[key].WasPressed)
                    {
                        WasPressed?.Invoke(this[key]);
                    }
                    else if (this[key].WasReleased)
                    {
                        WasReleased?.Invoke(this[key]);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Update()
        {
            this._state = Keyboard.GetState();

            foreach (var key in this._keys.Keys)
            {
                this[key].Update(this._state.IsKeyDown(key));
                if (this[key].WasPressed)
                {
                    WasPressed?.Invoke(this[key]);
                }
                else if (this[key].WasReleased)
                {
                    WasReleased?.Invoke(this[key]);
                }
            }
        }