X hits on this document

262 views

0 shares

0 downloads

0 comments

64 / 102

random.Next((int)MinShotStrength, (int)MaxShotStrength);

       Catapult.ShotStrength = (shotVelocity / MaxShotStrength);

       Catapult.ShotVelocity = shotVelocity;

   }

   base.Update(gameTime);

}

This concludes all work on the AI class and we can move on to the Human class. The Human class will present a new challenge, as this is where we will introduce input handling required to respond to the user’s actions.

140.

Open the Human.cs file and add the following fields to the Human class:

C#

// Drag variables to hold first and last gesture samples

GestureSample? prevSample;

GestureSample? firstSample;

bool isDragging;

// Constant for longest distance possible between drag points

readonly float maxDragDelta = (new Vector2(480, 800)).Length();

// Textures & position & spriteEffects used for Catapult

Texture2D arrow;

float arrowScale;

Vector2 catapultPosition = new Vector2(140, 332);

141.

Alter the Human class’s second constructor (the one which receives two arguments) to the following:

C#

public Human(Game game, SpriteBatch screenSpriteBatch)

   : base(game, screenSpriteBatch)

{

   Catapult = new Catapult(game, screenSpriteBatch,

                           "Textures/Catapults/Blue/blueIdle/blueIdle",

                           catapultPosition, SpriteEffects.None, false);

}

The only change is that we use the field added in the previous state to specify the catapult’s location.

142.

Revise the Initialize method. We will replace the comment beginning with “TODO” with code which loads the texture used to draw visual feedback for the user:

C#

public override void Initialize()

{

Page | 64

Document info
Document views262
Page views262
Page last viewedWed Dec 07 23:02:16 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments