X hits on this document

267 views

0 shares

0 downloads

0 comments

87 / 102

   animations["Fire"].PlayFromFrameIndex(startFrame);

}

The above method takes the current aim animation frame, translating it to the corresponding firing animation frame and activating the firing animation.

183.

Now that the final version of the Catapult’s Update method is ready, replace the Draw method with the following:

C#

public override void Draw(GameTime gameTime)

{

   if (gameTime == null)

       throw new ArgumentNullException("gameTime");

   // Using the last update state makes sure we do not draw

   // before updating animations properly

   switch (lastUpdateState)

   {

       case CatapultState.Idle:

           DrawIdleCatapult();

           break;

       case CatapultState.Aiming:

       case CatapultState.Stalling:

           animations["Aim"].Draw(spriteBatch, catapultPosition,

               spriteEffects);

           break;

       case CatapultState.Firing:

animations["Fire"].Draw(spriteBatch, catapultPosition,

               spriteEffects);

           break;

case CatapultState.Firing | CatapultState.ProjectileFlying:

       case CatapultState.ProjectileFlying:

animations["Fire"].Draw(spriteBatch, catapultPosition,

               spriteEffects);

           projectile.Draw(gameTime);

           break;

       case CatapultState.ProjectileHit:

           // Draw the catapult

           DrawIdleCatapult();

           // Projectile Hit animation

           animations["fireMiss"].Draw(spriteBatch,

               projectile.ProjectileHitPosition, spriteEffects);

           break;

       case CatapultState.Hit:

Page | 87

Document info
Document views267
Page views267
Page last viewedThu Dec 08 03:18:52 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments