public bool KeyReleased(Keys key, bool lastFrame = false) { if (lastFrame) { return(LastKeyboardState.IsKeyUp(key)); } return(KeyboardState.IsKeyUp(key)); }
public bool KeyClicked(Keys key) { if (KeyboardState.IsKeyDown(key) && LastKeyboardState.IsKeyUp(key)) { return(true); } return(false); }
public bool IsKeyPressed(Keys key) { if (CurrentKeyboardState.IsKeyDown(key) && (LastKeyboardState.IsKeyUp(key))) { return(true); } return(false); }
public bool KeyUp(params Keys[] keys) { var result = true; foreach (var key in keys) { if (LastKeyboardState.IsKeyUp(key)) { continue; } result = false; } return(result); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { //Update mouse scroll state. MouseScrollHandler.Update(); UpdateGameActiveState(gameTime); if (IsPaused || IsFocusLost) { base.Update(gameTime); SuppressDraw(); return; } var mouseState = Mouse.GetState(); var keyboardState = Keyboard.GetState(); //Fullscreen toggle if (!IsInEditMode && (keyboardState.IsKeyDown(Keys.LeftAlt) || keyboardState.IsKeyDown(Keys.RightAlt))) { if (keyboardState.IsKeyDown(Keys.Enter) && LastKeyboardState.IsKeyUp(Keys.Enter)) { _graphics.ToggleFullScreen(); Globals.IsFullScreen = !Globals.IsFullScreen; } } //Map layer draw toggle if (IsInEditMode) { if (keyboardState.IsKeyDown(Keys.D1) && LastKeyboardState.IsKeyUp(Keys.D1)) { MapBase.SwitchLayerDraw(0); } if (keyboardState.IsKeyDown(Keys.D2) && LastKeyboardState.IsKeyUp(Keys.D2)) { MapBase.SwitchLayerDraw(1); } if (keyboardState.IsKeyDown(Keys.D3) && LastKeyboardState.IsKeyUp(Keys.D3)) { MapBase.SwitchLayerDraw(2); } if (keyboardState.IsKeyDown(Keys.D4) && LastKeyboardState.IsKeyUp(Keys.D4)) { MapBase.SwitchLayerDraw(3); } if (keyboardState.IsKeyDown(Keys.D5) && LastKeyboardState.IsKeyUp(Keys.D5)) { MapBase.SwitchLayerDraw(4); } } if (ScriptExecuter.IsInPlayingMovie) { //Stop movie when Esc key pressed if (keyboardState.IsKeyDown(Keys.Escape) && LastKeyboardState.IsKeyUp(Keys.Escape)) { ScriptExecuter.StopMovie(); } } else { //Update GUI first, GUI will decide whether user input be intercepted or pass through GuiManager.Update(gameTime); switch (GameState.State) { case GameState.StateType.Start: ScriptManager.RunScript(Utils.GetScriptParser("title.txt")); GameState.State = GameState.StateType.Title; break; case GameState.StateType.Title: break; case GameState.StateType.Playing: if (IsGamePlayPaused) { break; } UpdatePlaying(gameTime); break; default: throw new ArgumentOutOfRangeException(); } } //Update script after GuiManager, because script executing rely GUI state. ScriptManager.Update(gameTime); LastKeyboardState = Keyboard.GetState(); LastMouseState = mouseState; base.Update(gameTime); }
public static bool KeyPress(Keys key) { return(KeyboardState.IsKeyDown(key) && LastKeyboardState.IsKeyUp(key)); }
/// <summary> /// Helper for checking if a key was newly pressed during this update. The /// controllingPlayer parameter specifies which player to read input for. /// If this is null, it will accept input from any player. When a keypress /// is detected, the output playerIndex reports which player pressed it. /// </summary> public bool IsNewKeyPress(Keys key) { return(CurrentKeyboardState.IsKeyDown(key) && LastKeyboardState.IsKeyUp(key)); }
public bool KeyPressed(Keys key) => KeyboardState.IsKeyDown(key) && LastKeyboardState.IsKeyUp(key);
protected override void OnUpdateFrame(FrameEventArgs e) { var timespan = _stopwatch.Elapsed; if (timespan.TotalMilliseconds >= (16 + _stopwatchOvershoot) || _fastForward == true) { _stopwatchOvershoot = 16 - timespan.TotalMilliseconds; if (_stopwatchOvershoot > 0) { _stopwatchOvershoot = 0; } _stopwatch.Restart(); _joypadState = GetJoypadState(); for (int i = 0; i < 17000; i++) { _soundPlayer.QueueAudioSample(Channels.Channel1, _gameBoy.GetAudioSample(Channels.Channel1)); _soundPlayer.QueueAudioSample(Channels.Channel2, _gameBoy.GetAudioSample(Channels.Channel2)); _soundPlayer.QueueAudioSample(Channels.Channel3, _gameBoy.GetAudioSample(Channels.Channel3)); _soundPlayer.QueueAudioSample(Channels.Channel4, _gameBoy.GetAudioSample(Channels.Channel4)); _gameBoy.AdvanceMachineCycle(_joypadState); } } if (KeyboardState.IsKeyDown(Key.Escape)) { Close(); } if (KeyboardState.IsKeyDown(Key.Tab)) { _fastForward = true; } else { _fastForward = false; } if (KeyboardState.IsKeyDown(Key.P) && LastKeyboardState.IsKeyUp(Key.P)) { if (Size.X < 640) { Size = new OpenToolkit.Mathematics.Vector2i(ClientSize.X + 160, ClientSize.Y + 144); } } if (KeyboardState.IsKeyDown(Key.M) && LastKeyboardState.IsKeyUp(Key.M)) { if (Size.X > 160) { Size = new OpenToolkit.Mathematics.Vector2i(ClientSize.X - 160, ClientSize.Y - 144); } } if (KeyboardState.IsKeyDown(Key.L) && LastKeyboardState.IsKeyUp(Key.L)) { _gameBoy.EnableLogging(); } base.OnUpdateFrame(e); }
public bool IsKeyReleased(Key key) { return(KeyboardState.IsKeyUp(key) && !LastKeyboardState.IsKeyUp(key)); }
public bool IsKeyPressed(Keys key) { return(LastKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key)); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { runGame = false; } // We need to load the gamedata // Implement later //TODO: Implement Storage //Update sounds audioEngine.Update(); // Update input LastGamePadState = CurrentGamePadState; CurrentGamePadState = GamePad.GetState(PlayerIndex.One); LastKeyboardState = CurrentKeyboardState; CurrentKeyboardState = Keyboard.GetState(); if (CurrentKeyboardState.IsKeyDown(Keys.F) && LastKeyboardState.IsKeyUp(Keys.F)) { graphics.ToggleFullScreen(); } //we have to wait 3 seconds until we start playing if (gameTime.TotalGameTime.Seconds > 3 && playingGame == false) { playingGame = true; } //after 3 seconds start the game if (playingGame) { //Update players Catapult playerCatapult.Update(gameTime); if (playerCatapult.CurrentState == CatapultState.Reset) { // reset background and log screenPosition = Vector2.Zero; endObjectPos.X = 1000; endObjectPos.Y = 500; } // Move the background if (playerCatapult.CurrentState == CatapultState.ProjectileFlying) { screenPosition.X = (playerCatapult.PumpkinPosition.X - playerCatapult.PumpkinLaunchPosition) * -1.0f; endObjectPos.X = (playerCatapult.PumpkinPosition.X - playerCatapult.PumpkinLaunchPosition) * -1.0f + 1000; } //Calculate the pumpkin flying distance if (playerCatapult.CurrentState == CatapultState.ProjectileFlying || playerCatapult.CurrentState == CatapultState.ProjectileHit) { PumpkinDistance = playerCatapult.PumpkinPosition.X - playerCatapult.PumpkinLaunchPosition; PumpkinDistance /= 15.0f; } //Is this a highscore? if (HighScore < PumpkinDistance) { HighScore = (int)PumpkinDistance; } } // Exit game if (!runGame) { Exit(); } base.Update(gameTime); }