/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> public void UpdateGame() { #region select which primitive to work on if (InputWrapper.Buttons.A == ButtonState.Pressed) { mWorkPrim = mBall; } else if (InputWrapper.Buttons.B == ButtonState.Pressed) { mWorkPrim = mUWBLogo; } #endregion select which primitive to work on #region update the work primitive float rotation = 0; if (InputWrapper.Buttons.X == ButtonState.Pressed) { rotation = MathHelper.ToRadians(1f); //1 degree pre-press } if (InputWrapper.Buttons.Y == ButtonState.Pressed) { rotation = MathHelper.ToRadians(-1f); //1 degree pre-press } mWorkPrim.Update(InputWrapper.ThumbSticks.Left, InputWrapper.ThumbSticks.Right, rotation); #endregion }
/// <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 (InputWrapper.Buttons.Back == ButtonState.Pressed) { this.Exit(); } #region Control the UWB Logo position with left thumb stick mUWBLogo.Update(InputWrapper.ThumbSticks.Left, Vector2.Zero); #endregion #region Let the SoccerBall update itself, and let user control its size with the right thumb stick mBall.Update(); mBall.Update(Vector2.Zero, InputWrapper.ThumbSticks.Right); if (InputWrapper.Buttons.A == ButtonState.Pressed) { mBall = new SoccerBall(mSoccerPosition, mSoccerBallRadius * 2f); } #endregion base.Update(gameTime); }
/// <summary> /// Update game sate: /// 1. Tell all Gameobjects to update themselves /// 2. Cause (call) all intractable objects to interact /// </summary> /// <param name="gameTime"></param> public void UpdateGame(GameTime gameTime) { #region Step a. if (null != mFinal) // done!! { return; } #endregion #region Step b. go through all game object and tell each to update themselves // hero movement: right thumb stick mHero.Update(InputWrapper.ThumbSticks.Right); // Basketball ... for (int b = mBBallList.Count - 1; b >= 0; b--) { if (mBBallList[b].UpdateAndExplode()) { mBBallList.RemoveAt(b); mBBallMissed++; mScore += kBballMissedScore; } } #endregion #region Step c. Call GameObject interaction functions to cause interaction between game objects /// Notice we could have integrated the following loop into the above for-loop. /// In this implementation we separated out the following loop to highlight the /// fact that, Hero->Ball interaction is inter-gameObject interaction and /// this happened separately from individual updates of game objects. for (int b = mBBallList.Count - 1; b >= 0; b--) { if (mHero.PrimitivesTouches(mBBallList[b])) { mBBallList.RemoveAt(b); mBBallHit++; mScore += kBballTouchScore; } } #endregion #region Step d. final checking of game winning // Check for new basketball condition TimeSpan timePassed = gameTime.TotalGameTime; timePassed = timePassed.Subtract(mCreationTimeStamp); if (timePassed.TotalMilliseconds > kBballMSecInterval) { mCreationTimeStamp = gameTime.TotalGameTime; BasketBall b = new BasketBall(); mTotalBBallCreated++; mBBallList.Add(b); } #endregion #region Step e. // Check for winning condition ... if (mScore > kWinScore) { mFinal = new TexturedPrimitive("Winner", new Vector2(75, 50), new Vector2(30, 20)); } else if (mScore < kLossScore) { mFinal = new TexturedPrimitive("Loser", new Vector2(75, 50), new Vector2(30, 20)); } #endregion }