Exemple #1
0
 public bool KeyPressed(Keys key, bool lastFrame = false)
 {
     if (lastFrame)
     {
         return(LastKeyboardState.IsKeyDown(key));
     }
     return(KeyboardState.IsKeyDown(key));
 }
Exemple #2
0
 public bool IsKeyReleased(Keys key)
 {
     if (CurrentKeyboardState.IsKeyUp(key) && (LastKeyboardState.IsKeyDown(key)))
     {
         return(true);
     }
     return(false);
 }
Exemple #3
0
        /// <summary>
        /// Returns true is the given key was down last frame but isn't this frame
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool WasKeyDown(Keys key)
        {
            if (!Engine.Instance.WindowActive)
            {
                return(false);
            }

            if (LastKeyboardState.IsKeyDown(key))
            {
                if (Keyboard.GetState().IsKeyUp(key))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #4
0
        protected override void OnUpdateFrame(FrameEventArgs args)
        {
            base.OnUpdateFrame(args);

            if (LastKeyboardState.IsKeyDown(Key.Space))
            {
                int iterations = 10;
                for (int i = 1; i < iterations; i++)
                {
                    chip8.UpdateTimers((float)args.Time * 60 / iterations);
                    chip8.Step(this);
                }

                UpdateTextureTarget();
            }
        }
Exemple #5
0
            /*
             * Action up
             */
            // public bool ActionUp(string action) {
            //   if (InputType == InputType.GamePad) {
            //     return GamePadMap.ContainsKey(action) && GamePadState.IsButtonDown(GamePadMap[action]);
            //   }

            //   return KeyboardMap.ContainsKey(action) && KeyboardState.IsKeyDown(KeyboardMap[action]);
            // }

            /*
             * Action pressed
             */
            public bool ActionPressed(string action)
            {
                if (InputType == InputType.GamePad && GamePadMap.ContainsKey(action))
                {
                    foreach (Buttons button in GamePadMap[action])
                    {
                        if (button != 0 && GamePadState.IsButtonDown(button) && !LastGamePadState.IsButtonDown(button))
                        {
                            return(true);
                        }
                    }
                }
                else if (InputType == InputType.Keyboard && KeyboardMap.ContainsKey(action))
                {
                    foreach (Keys key in KeyboardMap[action])
                    {
                        if (KeyboardState.IsKeyDown(key) && !LastKeyboardState.IsKeyDown(key))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
                // if (InputType == InputType.GamePad)
                // {
                //   return (
                //     GamePadMap.ContainsKey(action) &&
                //     GamePadState.IsButtonDown(GamePadMap[action]) &&
                //     !LastGamePadState.IsButtonDown(GamePadMap[action])
                //   );
                // }

                // return (
                //   KeyboardMap.ContainsKey(action) &&
                //   KeyboardState.IsKeyDown(KeyboardMap[action]) &&
                //   !LastKeyboardState.IsKeyDown(KeyboardMap[action])
                // );
            }
Exemple #6
0
        protected override void OnKeyDown(KeyboardKeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Key == Key.S)
            {
                int iterations = 1;

                if (LastKeyboardState.IsKeyDown(Key.ControlLeft))
                {
                    iterations = 100;
                }

                for (int i = 0; i < iterations; i++)
                {
                    chip8.Step(this);
                }

                //chip8.DumpGfx();

                UpdateTextureTarget();
            }
        }
Exemple #7
0
 /// <summary>
 /// Determines if the provided <see cref="Keys"/> value was just lifted.
 /// </summary>
 /// <param name="key">The <see cref="Keys"/> value representing the key to check.</param>
 /// <returns>True if key state changes from down to up. False if no change.</returns>
 public static bool GetKeyUp(Keys key)
 {
     return(KeyboardState.IsKeyUp(key) && LastKeyboardState.IsKeyDown(key));
 }
Exemple #8
0
        protected override void Update(GameTime gameTime)
        {
            if (Window == null)
            {
                return;
            }

            if (Window.ClientBounds.Width != _clientWidth || Window.ClientBounds.Height != _clientHeight)
            {
                _clientWidth  = Window.ClientBounds.Width;
                _clientHeight = Window.ClientBounds.Height;
                _graphics.PreferredBackBufferWidth  = _clientWidth;
                _graphics.PreferredBackBufferHeight = _clientHeight;
                _graphics.ApplyChanges();

                var p = GraphicsDevice.PresentationParameters;
                OnResolutionChanged(new ResolutionEventArgs(p.BackBufferWidth, p.BackBufferHeight));
            }

            ShowFps(gameTime);

            LastKeyboardState = Keyboard.GetState();


            if (!MouseExtras.Instance.IsForeground(this, Window))
            {
                IsMouseVisible = true;
                Paused         = true;
                if (MouseExtras.Instance.HasCapture(this, Window))
                {
                    MouseExtras.Instance.ReleaseCapture();
                }

                MouseDelta = new Vector2I();
            }
            else
            {
                bool pauseIsPressed = LastKeyboardState.IsKeyDown(Keys.Tab);
                if (!_pauseWasPressed && pauseIsPressed)
                {
                    Paused = !Paused;
                    if (Paused)
                    {
                        if (MouseExtras.Instance.HasCapture(this, Window))
                        {
                            MouseExtras.Instance.ReleaseCapture();
                        }
                    }
                    IsMouseVisible = Paused;
                }
                _pauseWasPressed = pauseIsPressed;

                var mouseX = 0;
                var mouseY = 0;
                if (!Paused && MouseExtras.Instance.HasCapture(this, Window))
                {
                    var centerX = _clientWidth / 2;
                    var centerY = _clientHeight / 2;
                    var mouse   = MouseExtras.Instance.GetPosition(Window);
                    mouseX = mouse.X - centerX;
                    mouseY = mouse.Y - centerY;
                }
                MouseDelta = new Vector2I(mouseX, mouseY);
            }


            if (LastKeyboardState.IsKeyDown(Keys.Escape))
            {
                Exit();
                return;
            }

            base.Update(gameTime);

            if (!Paused && MouseExtras.Instance.IsForeground(this, Window))
            {
                if (!MouseExtras.Instance.HasCapture(this, Window))
                {
                    MouseExtras.Instance.SetCapture(Window);
                }

                var centerX = _clientWidth / 2;
                var centerY = _clientHeight / 2;
                MouseExtras.Instance.SetPosition(Window, centerX, centerY);
            }
        }
Exemple #9
0
 public static bool IsNewKeyRelease(Keys key)
 {
     return(LastKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key));
 }
Exemple #10
0
 protected bool IsUniquePress(KeyboardState state, Key key)
 {
     return(state.IsKeyDown(key) && !LastKeyboardState.IsKeyDown(key));
 }
Exemple #11
0
 public bool IsKeyPressed(Key key)
 {
     return(KeyboardState.IsKeyDown(key) && !LastKeyboardState.IsKeyDown(key));
 }
Exemple #12
0
 public bool HasKeyChanged(Key key)
 {
     return(LastKeyboardState.IsKeyDown(key) != KeyboardState.IsKeyDown(key));
 }
Exemple #13
0
 public bool IsKeyHeldDown(Keys key)
 {
     return(LastKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyDown(key));
 }
Exemple #14
0
 public static bool KeyReleased(Keys key)
 {
     return(KeyboardState.IsKeyUp(key) &&
            LastKeyboardState.IsKeyDown(key));
 }