public void HandleInput(KeyboardState state) { if (!_keyLocker.KeyPressed && state.IsKeyDown(Keys.Space) && !oldState.IsKeyDown(Keys.Space)) { // Change to JumpAction _actionStateMachine.Change("jump"); _keyLocker.LockKey(Keys.Space); } else if (state.IsKeyDown(Keys.Left) || state.IsKeyDown(Keys.Right)) // If left or right key is pressed { _actionStateMachine.Change("move"); } else if (!_keyLocker.KeyPressed && state.IsKeyDown(Keys.Z) && !oldState.IsKeyDown(Keys.Z)) { _actionStateMachine.Change("attack"); _keyLocker.LockKey(Keys.Z); } else if (oldState.IsKeyUp(Keys.X) && state.IsKeyDown(Keys.X)) { // Change to ThrowAction if actor is currently not throwing if (!_actor.isThrowing) { _actionStateMachine.Change("throw", "stand"); } } else if (state.IsKeyDown(Keys.Down)) { _actionStateMachine.Change("crouch"); } _keyLocker.CheckInputLock(state, Keys.Space); _keyLocker.CheckInputLock(state, Keys.Z); oldState = state; }
/// <summary> /// Handles the movement of the viewport, what button does what /// </summary> /// <param name="state">The current state of the keyboard</param> private void handleViewPortMovement(KeyboardState state) { if (state.IsKeyDown(Keys.Up)) { currentLoc.Y -= 1; } else if (state.IsKeyDown(Keys.Down)) { currentLoc.Y += 1; } if (state.IsKeyDown(Keys.Left)) { currentLoc.X -= 1; } else if (state.IsKeyDown(Keys.Right)) { currentLoc.X += 1; } // Zoom in if (state.IsKeyDown(Keys.OemPlus)) { viewPortSize.X -= 5; viewPortSize.Y -= 5; } // zoom out else if (state.IsKeyDown(Keys.OemMinus)) { viewPortSize.X += 5; viewPortSize.Y += 5; } // Go the menu if (!keyLocker.KeyPressed && state.IsKeyDown(Keys.Escape) && !oldState.IsKeyDown(Keys.Escape)) { gameStateManager.Change("menu"); keyLocker.LockKey(Keys.Escape); } // Go the inventory else if (!keyLocker.KeyPressed && state.IsKeyDown(Keys.I) && !oldState.IsKeyDown(Keys.I)) { gameStateManager.Change("inventory", player); keyLocker.LockKey(Keys.I); } // Play the stage if it is selectable else if (!keyLocker.KeyPressed && state.IsKeyDown(Keys.Enter) && !oldState.IsKeyDown(Keys.Enter)) { if (selectedStage != 0) { gameStateManager.Change("stage", selectedStage, player); keyLocker.LockKey(Keys.Enter); } } keyLocker.CheckInputLock(state, Keys.Enter); keyLocker.CheckInputLock(state, Keys.Escape); keyLocker.CheckInputLock(state, Keys.I); }