X hits on this document

258 views

0 shares

0 downloads

0 comments

86 / 102

   lastUpdateState = currentState;

   if (postUpdateStateChange != 0)

   {

       currentState = postUpdateStateChange;

   }

   base.Update(gameTime);

}

The above version of the method now contains code to support animation and sound playback. In some places, additional logic was added since we now have to wait for animations to finish playing back before advancing the state of the catapult. Additionally, the method now utilizes several helper methods, which we will implement.

Note: Take the time to go over the above method as it demonstrates how to take animation times into consideration.

180.

Create a new method called UpdateAimAccordingToShotStrength:

C#

private void UpdateAimAccordingToShotStrength()

{

   var aimAnimation = animations["Aim"];

   int frameToDisplay =

       Convert.ToInt32(aimAnimation.FrameCount * ShotStrength);

   aimAnimation.FrameIndex = frameToDisplay;

}

This method translates the current shot strength into a frame in the catapult’s aiming animation. This will make the catapult arm stretch further as the user increases the shot power.

181.

Create a new method called AimReachedShotStrength:

C#

private bool AimReachedShotStrength()

{

   return (animations["Aim"].FrameIndex ==

       (Convert.ToInt32(animations["Aim"].FrameCount * ShotStrength) - 1));

}

The above method complements the “UpdateAimAccordingToShotStrength” method, checking whether the current aim animation frame matches the shot strength.

182.

Create a new method called StartFiringFromLastAimPosition:

C#

private void StartFiringFromLastAimPosition()

{

   int startFrame = animations["Aim"].FrameCount -

       animations["Aim"].FrameIndex;

Page | 86

Document info
Document views258
Page views258
Page last viewedWed Dec 07 14:57:17 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments