//Edited by Noble 12-11 public static void Update(GameTime gameTime) { if (UtilityClass.SingleActivationKey(Keys.Escape)) { Game1.GameState = Game1.GameStates.MainMenu; } }
// Edited by Noble 12-11 public static void Update(GameTime gameTime) { if (UtilityClass.SingleActivationKey(Keys.Escape)) { Game1.GameState = Game1.GameStates.MainMenu; } creditsTime += gameTime.ElapsedGameTime.Milliseconds / 2; }
/// <summary> /// Updates selected menu option in menus /// </summary> /// <returns>vector2 passed by reference to change</returns> public void UpdateSelected(ref Vector2 selected) { // When W or UP arrow keys are pressed if (UtilityClass.SingleActivationKey(Keys.W) || UtilityClass.SingleActivationKey(Keys.Up)) { // And selected.Y is GREATER THAN 0, preventing it from exiting the selection range, if (selected.Y > 0) { // Then move selected selected.Y--; } } // When A or Left arrow keys are pressed if (UtilityClass.SingleActivationKey(Keys.A) || UtilityClass.SingleActivationKey(Keys.Left)) { // And selected.X is GREATER THAN 0, preventing it from exiting the selection range, if (selected.X > 0) { // Then move selected selected.X--; } } // When S or Down arrow keys are pressed if (UtilityClass.SingleActivationKey(Keys.S) || UtilityClass.SingleActivationKey(Keys.Down)) { // And selected.Y is LESS THAN selectionMax.Y, preventing it from exceeding maximum Y selection range, if (selected.Y < selectionMax.Y) { // Then move selected selected.Y++; } } // When D or Right arrow keys are pressed if (UtilityClass.SingleActivationKey(Keys.D) || UtilityClass.SingleActivationKey(Keys.Right)) { // And selected.X is LESS THAN selectionMax.X, preventing it from exceeding maximum X selection range, if (selected.X < selectionMax.X) { // Then move selected selected.X++; } } // Update Enter key IsEnterDown = UtilityClass.SingleActivationKey(Keys.Enter); // Update escape key IsEscapeDown = UtilityClass.SingleActivationKey(Keys.Escape); }
// Edited by Noble 12-10 /// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || UtilityClass.SingleActivationKey(Keys.End)) { this.Exit(); } UtilityClass.Update(); switch (GameState) { case GameStates.MainMenu: MainMenu.Update(); break; case GameStates.InGame: InGame.Update(gameTime); break; case GameStates.Tutorial: Tutorial.Update(gameTime); break; case GameStates.Credits: Credits.Update(gameTime); break; case GameStates.Exit: this.Exit(); break; case GameStates.HighScore: break; case GameStates.GameOver: break; default: throw new ArgumentOutOfRangeException(); } if (UtilityClass.SingleActivationKey(Keys.Escape)) { LoadContent(); } base.Update(gameTime); }
// Created by Noble 11-07, edited by Alexander 12-06 private void UpdateControls(GameTime gameTime) { // Update keyboard keyboard = Keyboard.GetState(); // Reset walking walking = false; // if player hits the ground //or the top of a platform if (collidableObject.Position.Y >= InGame.groundRectangle.Top - collidableObject.origin.Y) { onGround = true; direction.Y = 0; } else { onGround = false; } // If W or Up arrow key is pressed down And jump is not complete TODO: Fix jumping if ((keyboard.IsKeyDown(Keys.W) || keyboard.IsKeyDown(Keys.Up)) && !jumpComplete) { // Continue jump // Jump has already started if (jumpTime > 0) { Jump(gameTime); } // Start jump // If jumpTime is reset and is on ground if (jumpTime == 0 && onGround) { Jump(gameTime); } } else { // key was released, therefore set jump to complete jumpComplete = true; // if both keys are up and player is on ground if (keyboard.IsKeyUp(Keys.W) && keyboard.IsKeyUp(Keys.Up) && onGround) { // Reset jump jumpTime = 0; jumpComplete = false; } // Fall Fall(gameTime); } // If A or Left arrow key is pressed down AND right keys are not down as to prevent pressing both directions at once if (keyboard.IsKeyDown(Keys.A) || keyboard.IsKeyDown(Keys.Left) && !(keyboard.IsKeyDown(Keys.D) || keyboard.IsKeyDown(Keys.Right))) { // Move left MoveLeft(); } // If D or Right arrow key is pressed down AND left keys are not down as to prevent pressing both directions at once if (keyboard.IsKeyDown(Keys.D) || keyboard.IsKeyDown(Keys.Right) && !(keyboard.IsKeyDown(Keys.A) || keyboard.IsKeyDown(Keys.Left))) { // Move Right MoveRight(); } // If Space or Z key are pressed down if ((UtilityClass.SingleActivationKey(Keys.Space) && !UtilityClass.SingleActivationKey(Keys.Z)) || (UtilityClass.SingleActivationKey(Keys.Z) && !UtilityClass.SingleActivationKey(Keys.Space))) { // If not already attacking if (!attacking) { // Start a new attack StartAttack(); } } }