/// <summary> /// Runs one frame of update for the game. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; // Check it one of the players reached 5 and stop the game if ((player.Catapult.GameOver || computer.Catapult.GameOver) && (gameOver == false)) { gameOver = true; if (player.Score > computer.Score) { AudioManager.PlaySound("gameOver_Win"); } else { AudioManager.PlaySound("gameOver_Lose"); } return; } // If Reset flag raised and both catapults are not animating - // active catapult finished the cycle, new turn! if ((player.Catapult.CurrentState == CatapultState.Reset || computer.Catapult.CurrentState == CatapultState.Reset) && !(player.Catapult.AnimationRunning || computer.Catapult.AnimationRunning)) { changeTurn = true; if (player.IsActive == true) //Last turn was a human turn? { player.IsActive = false; computer.IsActive = true; isHumanTurn = false; player.Catapult.CurrentState = CatapultState.Idle; computer.Catapult.CurrentState = CatapultState.Aiming; } else //It was an AI turn { player.IsActive = true; computer.IsActive = false; isHumanTurn = true; computer.Catapult.CurrentState = CatapultState.Idle; player.Catapult.CurrentState = CatapultState.Idle; } } if (changeTurn) { // Update wind wind = new Vector2(random.Next(-1, 2), random.Next(minWind, maxWind + 1)); // Set new wind value to the players and player.Catapult.Wind = computer.Catapult.Wind = wind.X > 0 ? wind.Y : -wind.Y; changeTurn = false; } // Update the players player.Update(gameTime); computer.Update(gameTime); // Updates the clouds position UpdateClouds(elapsed); base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); }
/// <summary> /// Runs one frame of update for the game. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; // Check it one of the players reached 5 and stop the game if ((player.Catapult.GameOver || computer.Catapult.GameOver) && (gameOver == false)) { gameOver = true; if (player.Score > computer.Score) { AudioManager.PlaySound("gameOver_Win"); } else { AudioManager.PlaySound("gameOver_Lose"); } return; } if (isFlying) { if (ScreenCenter == flightDestination) { isFlying = false; } else { // Find the direction in which we need to move to get from the // screen center to our flight destination Vector2 flightVector = flightDestination - ScreenCenter; Vector2 flightMovementVector = flightVector; flightMovementVector.Normalize(); flightMovementVector *= 10; flightMovementVector *= (float)(0.25 * (2 + Math.Log((flightVector.Length() + 0.2)))); if (flightMovementVector.Length() > flightVector.Length()) { DrawOffset -= flightVector; } else { DrawOffset -= flightMovementVector; } CorrectScreenPosition(40, 30); } } else { CorrectScreenPosition(0, 0); } // If Reset flag raised and both catapults are not animating - // active catapult finished the cycle, new turn! if ((player.Catapult.CurrentState == CatapultState.Reset || computer.Catapult.CurrentState == CatapultState.Reset) && !(player.Catapult.AnimationRunning || computer.Catapult.AnimationRunning)) { changeTurn = true; if (player.IsActive == true) // Last turn was a human turn? { CenterOnPosition(computer.Catapult.Position - catapultCenterOffset); player.IsActive = false; computer.IsActive = true; isHumanTurn = false; player.Catapult.CurrentState = CatapultState.Idle; computer.Catapult.CurrentState = CatapultState.Aiming; } else //It was an AI turn { isCameraMoving = true; player.IsActive = true; computer.IsActive = false; isHumanTurn = true; computer.Catapult.CurrentState = CatapultState.Idle; player.Catapult.CurrentState = CatapultState.Idle; } } if (changeTurn) { // Update wind wind = new Vector2(random.Next(-1, 2), random.Next(minWind, maxWind + 1)); // Set new wind value to the players and player.Catapult.Wind = computer.Catapult.Wind = wind.X > 0 ? wind.Y : -wind.Y; changeTurn = false; } // Update the players player.Update(gameTime); computer.Update(gameTime); // Updates the clouds position UpdateClouds(elapsed); base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); }