X hits on this document

402 views

0 shares

0 downloads

0 comments

65 / 102

   arrow = curGame.Content.Load<Texture2D>("Textures/HUD/arrow");

   Catapult.Initialize();

   base.Initialize();

}

143.

Create a new method in the Human class called HandleInput. This method will be used to react to the user’s drag gestures, which in turn will be used to shoot at the computer player. It is worth mentioning that this method will not be invoked automatically, we will invoke it later from the GameplayScreen.

C#

public void HandleInput(GestureSample gestureSample)

{

   // Process input only if in Human's turn

   if (IsActive)

   {

       // Process any Drag gesture

       if (gestureSample.GestureType == GestureType.FreeDrag)

       {

           // If drag just began save the sample for future

           // calculations and start Aim "animation"

           if (null == firstSample)

           {

               firstSample = gestureSample;

               Catapult.CurrentState = CatapultState.Aiming;

           }

           // save the current gesture sample

           prevSample = gestureSample;

           // calculate the delta between first sample and current

           // sample to present visual sound on screen

           Vector2 delta = prevSample.Value.Position -

               firstSample.Value.Position;

Catapult.ShotStrength = delta.Length() / maxDragDelta;

           float baseScale = 0.001f;

           arrowScale = baseScale * delta.Length();

           isDragging = true;

       }

else if (gestureSample.GestureType == GestureType.DragComplete)

       {

           // calc velocity based on delta between first and last

Page | 65

Document info
Document views402
Page views402
Page last viewedTue Jan 24 23:34:55 UTC 2017
Pages102
Paragraphs3115
Words17333

Comments