/// <summary> /// Updates all objects in the world, performs collision between them, /// and handles the time limit with scoring. /// </summary> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { // Pause while the player is dead or time is expired. // Pause while the player is dead or time is expired. if (!Player.IsAlive || TimeRemaining == TimeSpan.Zero) { // Still want to perform physics on the player. Player.ApplyPhysics(gameTime); } else if (ReachedExit) { // Animate the time being converted into points. int seconds = (int)Math.Round(gameTime.ElapsedGameTime.TotalSeconds * 100.0f); seconds = Math.Min(seconds, (int)Math.Ceiling(TimeRemaining.TotalSeconds)); timeRemaining -= TimeSpan.FromSeconds(seconds); score += seconds * PointsPerSecond; } else { timeRemaining -= gameTime.ElapsedGameTime; Player.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation); UpdateMovableTiles(gameTime); UpdateGems(gameTime); // Falling off the bottom of the level kills the player. if (Player.BoundingRectangle.Top >= Height * Tile.Height) { OnPlayerKilled(null); } UpdateEnemies(gameTime); // The player has reached the exit if they are standing on the ground and // his bounding rectangle contains the center of the exit tile. They can only // exit when they have collected all of the gems. if (Player.IsAlive && Player.IsOnGround && Player.BoundingRectangle.Contains(exit)) { OnExitReached(); } } // Clamp the time remaining at zero. if (timeRemaining < TimeSpan.Zero) { timeRemaining = TimeSpan.Zero; } }
/// <summary> /// Updates all objects in the world, performs collision between them, /// and handles the time limit with scoring. /// </summary> public void Update( GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, DisplayOrientation orientation) { if (IsLoading) { return; } if (!initializedLevelStartTime) { totalTimeLevelStarted = gameTime.TotalGameTime; initializedLevelStartTime = true; } // record high score at the end of level if (Player.PlayerStates[0] == PlayerState.ReachedExit && TimeRemaining == TimeSpan.Zero) { Player.ReplayData.HighScore = this.Score; } // Pause while the player is dead or time is expired. if (!Player.IsAlive || TimeRemaining == TimeSpan.Zero) { // Still want to perform physics on the player. Player.ApplyPhysics(gameTime); } else if (ReachedExit) { // Animate the time being converted into points. int milliSeconds = (int)Math.Round(gameTime.ElapsedGameTime.TotalMilliseconds * 100.0f); milliSeconds = Math.Min(milliSeconds, (int)Math.Ceiling(TimeRemaining.TotalMilliseconds)); timeRemaining -= TimeSpan.FromMilliseconds(milliSeconds); score += (int)Math.Round(milliSeconds * (PointsPerSecond / 1000.0)); } else { timeRemaining -= gameTime.ElapsedGameTime; Player.Update(gameTime, keyboardState, gamePadState, orientation); UpdateGems(gameTime); // Falling off the bottom of the level kills the player. for (int i = 0; i < Player.PlayerPositions.Count; i++) { if (Player.GetBoundingRectangle(Player.PlayerPositions[i]).Top >= Height * Tile.Height) { OnPlayerKilled(i, null); } } UpdateEnemies(gameTime); // The player has reached the exit if they are standing on the ground and // his bounding rectangle contains the center of the exit tile. They can only // exit when they have collected all of the gems. for (int i = 0; i < Player.PlayerPositions.Count; i++) { if (Player.PlayerStates[i] == PlayerState.Alive && Player.IsOnGround && Player.GetBoundingRectangle(Player.PlayerPositions[i]).Contains(exit)) { OnExitReached(i); } } } // Clamp the time remaining at zero. if (timeRemaining < TimeSpan.Zero) { timeRemaining = TimeSpan.Zero; } }