X hits on this document

271 views

0 shares

0 downloads

0 comments

69 / 102

   {

       // 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);

}

This method is divided into several main segments. We first check whether the game is over, which happens when one of the players reaches a score of five points, and update a flag accordingly (in the upcoming exercise, we will also play appropriate sounds). We then check whether the current turn is over, and reset some fields for the next turn, depending on which type of player has just played (either the human player or the computer player). In addition, assuming a turn has ended, we update the wind. Finally, we ask both players to perform respective updates and change the position of the clouds inside the UpdateClouds helper which we will implement next.

148.

Add a method called UpdateClouds to the GameplayScreen class:

C#

private void UpdateClouds(float elapsedTime)

{

   // Move the clouds according to the wind

   var windDirection = wind.X > 0 ? 1 : -1;

   cloud1Position += new Vector2(24.0f, 0.0f) * elapsedTime *

       windDirection * wind.Y;

if (cloud1Position.X > ScreenManager.GraphicsDevice.Viewport.Width)

       cloud1Position.X = -cloud1Texture.Width * 2.0f;

   else if (cloud1Position.X < -cloud1Texture.Width * 2.0f)

cloud1Position.X = ScreenManager.GraphicsDevice.Viewport.Width;

Page | 69

Document info
Document views271
Page views271
Page last viewedThu Dec 08 18:40:06 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments