protected virtual void OnKeyPress(KeyboardState keyboardState) { // if left is pressed if (keyboardState.IsKeyDown(Keys.Left) && !keyLocker.IsKeyLocked(Keys.Left)) { HandleLeftKeyPressed(keyboardState); } // if right is pressed else if (keyboardState.IsKeyDown(Keys.Right) && !keyLocker.IsKeyLocked(Keys.Right)) { HandleRightKeyPressed(keyboardState); } // ctrl c, ctrl v if (keyboardState.IsKeyDown(Keys.LeftControl) || keyboardState.IsKeyDown(Keys.RightControl)) { HandleControlKeyShortcuts(keyboardState); } }
// player STANDING state logic protected void PlayerStanding(KeyboardState keyboardState) { // sets animation to a STAND animation based on which way player is facing currentAnimationName = FacingDirection == Direction.RIGHT ? "STAND_RIGHT" : "STAND_LEFT"; // if walk left or walk right key is pressed, player enters WALKING state if (keyboardState.IsKeyDown(MOVE_LEFT_KEY) || keyboardState.IsKeyDown(MOVE_RIGHT_KEY)) { PlayerState = PlayerState.WALKING; } // if jump key is pressed, player enters JUMPING state else if (keyboardState.IsKeyDown(JUMP_KEY) && !keyLocker.IsKeyLocked(JUMP_KEY)) { keyLocker.LockKey(JUMP_KEY); PlayerState = PlayerState.JUMPING; } // if crouch key is pressed, player enters CROUCHING state else if (keyboardState.IsKeyDown(CROUCH_KEY)) { PlayerState = PlayerState.CROUCHING; } }
public override void Update(GameTime gameTime) { //background.update(null); KeyboardState keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyUp(Keys.Space)) { keyLocker.UnlockKey(Keys.Space); } // if space is pressed, go back to main menu if (!keyLocker.IsKeyLocked(Keys.Space) && keyboardState.IsKeyDown(Keys.Space)) { screenCoordinator.GameState = GameState.MENU; } }
public override void Update(GameTime gameTime) { //keyTimer.Tick(gameTime.ElapsedGameTime.TotalMilliseconds); // update background map (to play tile animations) background.Update(null); KeyboardState keyboardState = Keyboard.GetState(); // if down or up is pressed, change menu item "hovered" over (blue square in front of text will move along with currentMenuItemHovered changing) if (keyboardState.IsKeyDown(Keys.Down) && keyTimer.IsTimeUp()) { keyTimer.Reset(); currentMenuItemHovered++; } else if (keyboardState.IsKeyDown(Keys.Up) && keyTimer.IsTimeUp()) { keyTimer.Reset(); currentMenuItemHovered--; } // if down is pressed on last menu item or up is pressed on first menu item, "loop" the selection back around to the beginning/end if (currentMenuItemHovered > 2) { currentMenuItemHovered = 0; } else if (currentMenuItemHovered < 0) { currentMenuItemHovered = 2; } // sets location for blue square in front of text (pointerLocation) and also sets color of spritefont text based on which menu item is being hovered if (currentMenuItemHovered == 0) { playGameText.Color = new Color(255, 215, 0); creditsText.Color = new Color(49, 207, 240); settingsText.Color = new Color(49, 207, 240); pointerLocationX = 170; pointerLocationY = 155; } else if (currentMenuItemHovered == 1) { playGameText.Color = new Color(49, 207, 240); creditsText.Color = new Color(255, 215, 0); settingsText.Color = new Color(49, 207, 240); pointerLocationX = 170; pointerLocationY = 255; } else if (currentMenuItemHovered == 2) { playGameText.Color = new Color(49, 207, 240); creditsText.Color = new Color(49, 207, 240); settingsText.Color = new Color(255, 215, 0); pointerLocationX = 170; pointerLocationY = 355; } // if space is pressed on menu item, change to appropriate screen based on which menu item was chosen if (keyboardState.IsKeyUp(Keys.Space)) { keyLocker.UnlockKey(Keys.Space); } if (!keyLocker.IsKeyLocked(Keys.Space) && keyboardState.IsKeyDown(Keys.Space)) { menuItemSelected = currentMenuItemHovered; if (menuItemSelected == 0) { screenCoordinator.GameState = GameState.LEVEL; } else if (menuItemSelected == 1) { screenCoordinator.GameState = GameState.CREDITS; } else if (menuItemSelected == 2) { screenCoordinator.GameState = GameState.SETTINGS; } } }