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 void Update() { ParseLog(); bool keyWasNotPressed = true; if (currentCommand.Equals("N")) { NonPressedCommand.Execute(game); } foreach (String str in currentString) { if (Game1.notPaused) { if (LogCommandMappings.ContainsKey(str)) { LogCommandMappings[str].Execute(game); keyWasNotPressed = false; } } } if (!lastCommand.Equals("T") && currentCommand.Equals("T")) { new GenerateFireballCommand(0).Execute(game); } if (keyWasNotPressed) { idleCommand.Execute(game); } /* if (currentState.IsKeyDown(Keys.T) && previousState.IsKeyUp(Keys.T)) * { * new GenerateFireballCommand(0).Execute(game); * } */ lastCommand = currentCommand; }
public void Update(GameTime gameTime) { Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys(); bool keyWasNotPressed = true; KeyboardState currentState = Keyboard.GetState(); if (pressedKeys.Count() == 0) { NonPressedCommand.Execute(game); GameRecorder.Write(game.swWriteFile, "N"); } foreach (Keys key in pressedKeys) { if (Game1.notPaused) { if (controllerMappings.ContainsKey(key)) { controllerMappings[key].Execute(game); keyWasNotPressed = false; if (GameRecorder.KeyboardRecordLogMappings.ContainsKey(key)) { GameRecorder.Write(game.swWriteFile, GameRecorder.KeyboardRecordLogMappings[key]); } } } } if (currentState.IsKeyDown(Keys.T)) { GameRecorder.Write(game.swWriteFile, GameRecorder.KeyboardRecordLogMappings[Keys.T]); } if (keyWasNotPressed) { idleCommand.Execute(game); } if (currentState.IsKeyDown(Keys.T) && previousState.IsKeyUp(Keys.T)) { new GenerateFireballCommand(0).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); } if (!currentState.IsKeyDown(Keys.X)) { new MarioRunningCommand(0).Unregister(game); } if (currentState.IsKeyDown(Keys.P) && previousState.IsKeyUp(Keys.P)) { new EnemySpawnerCommand(0).Execute(game); } previousState = currentState; GameRecorder.Enter(game.swWriteFile); }