/// <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) { mouseState = Mouse.GetState(); switch (gameState) { case 0: // Title screen this.IsMouseVisible = true; gamePadState = GamePad.GetState(PlayerIndex.One); // Start the game if (title.isStartButtonPressed(mouseState)) { this.IsMouseVisible = false; MediaPlayer.Stop(); startingAnimation.Start(); gameState = 1; } if (title.isMuteButtonPressed(mouseState)) { if (MediaPlayer.IsMuted == false) MediaPlayer.IsMuted = true; else MediaPlayer.IsMuted = false; startingAnimation.ChangeMute(); endingAnimation.ChangeMute(); } break; case 1: // Starting animation if (startingAnimation.isFinished() || mouseState.LeftButton == ButtonState.Pressed) { startingAnimation.Stop(); MediaPlayer.Play(gameplayMusic); gameState = 2; } break; case 2: // Game Started // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // Take care of the fade from black first if (!FadeInAnimation.IsFadeCompleted()) break; if (!LevelChangeAnimation.IsAnimationCompleted()) { funnel.Update(); border.Update(totalDropsCaught); break; } // Update all objects to new positions funnel.Update(); nozzle.Update(); water.Update(); border.Update(totalDropsCaught); // Release a drop during every specified interval seconds += gameTime.ElapsedGameTime.TotalSeconds; // seconds += Elapsed time since last update if (seconds > waterInterval) { seconds = 0.0; water.releaseDrop(nozzle.GetBounds()); } // Increase counters for any water-funnel collisions. // From level 8 onward, return the entire funnel collision bounds because the water // droplets move too fast between frames for collisions to be detected. int collisions; if (currentLevel < 8) collisions = water.getFunnelCollisions(funnel.GetCollisionBounds()); else collisions = water.getFunnelCollisions(funnel.GetBounds()); totalDropsCaught += collisions; levelDropsCaught += collisions; // Update the tank threshold int misses = water.getFunnelMisses(); tank.updateThreshold(levelDropRequirement, misses); // Next level! if (levelDropsCaught == levelDropRequirement) { currentLevel += 1; levelDropRequirement += 5; levelDropsCaught = 0; // Increase speeds nozzle.increaseSpeed(speedMultiplier); water.increaseSpeed(speedMultiplier); waterInterval /= speedMultiplier; // Decrease the multiplier so that the speed increases per level don't become drastic. if (speedMultiplier > 1.0f) speedMultiplier *= 0.98f; LevelChangeAnimation.Reset(); } // Game Over if (tank.getTankLevel() == 3) { MediaPlayer.Stop(); endingAnimation.Start(); gameState = 3; } base.Update(gameTime); break; case 3: // Game Ended if (endingAnimation.isFinished() || mouseState.LeftButton == ButtonState.Pressed) { endingAnimation.Stop(); FadeInAnimation.Reset(); MediaPlayer.Play(gameplayMusic); highScores = new HighScores(totalDropsCaught); gameState = 4; } break; case 4: // High Scores this.IsMouseVisible = true; //keyboardState = Keyboard.GetState(); if ((mouseState.LeftButton == ButtonState.Pressed) && mouseState.X > retryButton.X && mouseState.X < retryButton.X + retryButton.Width && mouseState.Y > retryButton.Y && mouseState.Y < retryButton.Y + retryButton.Height) { MediaPlayer.Stop(); gameState = 0; ResetValues(); } break; } }
/// <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) { mouseState = Mouse.GetState(); switch (gameState) { case 0: // Title screen this.IsMouseVisible = true; gamePadState = GamePad.GetState(PlayerIndex.One); // Start the game if (title.isStartButtonPressed(mouseState)) { this.IsMouseVisible = false; MediaPlayer.Stop(); startingAnimation.Start(); gameState = 1; } if (title.isMuteButtonPressed(mouseState)) { if (MediaPlayer.IsMuted == false) { MediaPlayer.IsMuted = true; } else { MediaPlayer.IsMuted = false; } startingAnimation.ChangeMute(); endingAnimation.ChangeMute(); } break; case 1: // Starting animation if (startingAnimation.isFinished() || mouseState.LeftButton == ButtonState.Pressed) { startingAnimation.Stop(); MediaPlayer.Play(gameplayMusic); gameState = 2; } break; case 2: // Game Started // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } // Take care of the fade from black first if (!FadeInAnimation.IsFadeCompleted()) { break; } if (!LevelChangeAnimation.IsAnimationCompleted()) { funnel.Update(); border.Update(totalDropsCaught); break; } // Update all objects to new positions funnel.Update(); nozzle.Update(); water.Update(); border.Update(totalDropsCaught); // Release a drop during every specified interval seconds += gameTime.ElapsedGameTime.TotalSeconds; // seconds += Elapsed time since last update if (seconds > waterInterval) { seconds = 0.0; water.releaseDrop(nozzle.GetBounds()); } // Increase counters for any water-funnel collisions. // From level 8 onward, return the entire funnel collision bounds because the water // droplets move too fast between frames for collisions to be detected. int collisions; if (currentLevel < 8) { collisions = water.getFunnelCollisions(funnel.GetCollisionBounds()); } else { collisions = water.getFunnelCollisions(funnel.GetBounds()); } totalDropsCaught += collisions; levelDropsCaught += collisions; // Update the tank threshold int misses = water.getFunnelMisses(); tank.updateThreshold(levelDropRequirement, misses); // Next level! if (levelDropsCaught == levelDropRequirement) { currentLevel += 1; levelDropRequirement += 5; levelDropsCaught = 0; // Increase speeds nozzle.increaseSpeed(speedMultiplier); water.increaseSpeed(speedMultiplier); waterInterval /= speedMultiplier; // Decrease the multiplier so that the speed increases per level don't become drastic. if (speedMultiplier > 1.0f) { speedMultiplier *= 0.98f; } LevelChangeAnimation.Reset(); } // Game Over if (tank.getTankLevel() == 3) { MediaPlayer.Stop(); endingAnimation.Start(); gameState = 3; } base.Update(gameTime); break; case 3: // Game Ended if (endingAnimation.isFinished() || mouseState.LeftButton == ButtonState.Pressed) { endingAnimation.Stop(); FadeInAnimation.Reset(); MediaPlayer.Play(gameplayMusic); highScores = new HighScores(totalDropsCaught); gameState = 4; } break; case 4: // High Scores this.IsMouseVisible = true; //keyboardState = Keyboard.GetState(); if ((mouseState.LeftButton == ButtonState.Pressed) && mouseState.X > retryButton.X && mouseState.X < retryButton.X + retryButton.Width && mouseState.Y > retryButton.Y && mouseState.Y < retryButton.Y + retryButton.Height) { MediaPlayer.Stop(); gameState = 0; ResetValues(); } break; } }