X hits on this document

382 views

0 shares

0 downloads

0 comments

61 / 102

       enemy.Catapult.Hit();

       self.Score++;

       bRes = true;

       currentState = CatapultState.Reset;

   }

   return bRes;

}

This method simply uses intersection checks built into the XNA framework to determine whether the projectile intersects (i.e. hit) with a catapult. You will notice placeholders for sound playback and might notice that we once more use constants in place of sizes relative to the catapult asset. We do this as we will retrieve asset sizes using the Animation game class which we have yet to implement.

131.

Implement the “Hit” method used in the CheckHit method. This method simply updates a catapult to represent the fact it has been hit:

C#

public void Hit()

{

   AnimationRunning = true;

   // TODO: Start animations

   currentState = CatapultState.Hit;

}

132.

Now that the catapult has varying states, we will create a more sophisticated Draw override, which takes these states into account. Initially, however, it will not do much as most work will be animating the catapults, something we will not do until the next exercise. Remove the Draw override which currently exists and replace it with the following method:

C#

private void DrawIdleCatapult()

{

   spriteBatch.Draw(idleTexture, catapultPosition, null, Color.White,

       0.0f, Vector2.Zero, 1.0f,

       spriteEffects, 0);

}

133.

Now add the new Draw override:

C#

public override void Draw(GameTime gameTime)

{

   if (gameTime == null)

       throw new ArgumentNullException("gameTime");

   switch (lastUpdateState)

   {

Page | 61

Document info
Document views382
Page views382
Page last viewedSun Jan 22 10:47:50 UTC 2017
Pages102
Paragraphs3115
Words17333

Comments