public void Update(GameTime gameTime) { Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys(); KeyboardState currentState = Keyboard.GetState(); if (Game1.notPaused) { continueMoving.Execute(game); } foreach (Keys key in pressedKeys) { if (Game1.notPaused) { if (controllerMappings.ContainsKey(key)) { controllerMappings[key].Execute(game); } } } if (previousState.IsKeyDown(Keys.Enter) && currentState.IsKeyUp(Keys.Enter)) { new PauseCommand(0).Execute(game); } if (currentState.IsKeyDown(Keys.X) && previousState.IsKeyUp(Keys.X)) { new MarioRunningCommand(0).Register(game); } previousState = currentState; }
public void Update(GameTime gameTime) { GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); foreach (Buttons button in Enum.GetValues(typeof(Buttons))) { if (gamePadState.IsConnected && controllerMappings.ContainsKey(button) && gamePadState.IsButtonDown(button)) { controllerMappings[button].Execute(game); } } if (gamePadState.IsConnected) { float xDirection = gamePadState.ThumbSticks.Left.X; float yDirection = gamePadState.ThumbSticks.Left.Y; bool isIdle = true; if (xDirection > variance) { MarioRightCommand marioRightCmd = new MarioRightCommand(playerNumber); marioRightCmd.Execute(this.game); isIdle = false; } else if (xDirection < (-1 * variance)) { MarioLeftCommand marioLeftCmd = new MarioLeftCommand(playerNumber); marioLeftCmd.Execute(this.game); isIdle = false; } if (yDirection > variance) { } else if (yDirection < (-1 * variance)) { MarioDownCommand marioDownCmd = new MarioDownCommand(playerNumber); marioDownCmd.Execute(this.game); isIdle = false; } if (isIdle) { MarioIdleCommand marioIdleCmd = new MarioIdleCommand(playerNumber); marioIdleCmd.Execute(this.game); } } }