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); } } }
public JumpOnlyKeyboardController(Game1 myGame) { game = myGame; int playerNumber = 0; continueMoving = new MarioRightCommand(playerNumber); controllerMappings = new Dictionary <Keys, ICommand> { { Keys.Q, new ExitGameCommand() }, { Keys.W, new MarioUpCommand(playerNumber) }, { Keys.Up, new MarioUpCommand(playerNumber) }, { Keys.R, new ResetAllCommand() }, { Keys.J, new JumpOnlyModeCommand(playerNumber) }, { Keys.N, new NightmareModeCommand(playerNumber) }, { Keys.L, new LevelEditorCommand() } }; }