X hits on this document

350 views

0 shares

0 downloads

0 comments

81 / 102

The above code goes over the animation definition XML file, which is one of the assets contained in the project, and translates the animations defined in the file into instances of the Animation class we have defined.

Note: The animation definition XML is located in the CatapultGameContent project under Textures and then under Catapults.

176.

Replace the Catapult class’s CheckHit method. This version of the method takes the catapults size into account instead of using constants, and also plays back sounds when a catapult is hit by a projectile:

C#

private bool CheckHit()

{

   bool bRes = false;

   // Build a sphere around a projectile

   Vector3 center = new Vector3(projectile.ProjectilePosition, 0);

   BoundingSphere sphere = new BoundingSphere(center,

       Math.Max(projectile.ProjectileTexture.Width / 2,

       projectile.ProjectileTexture.Height / 2));

   // Check Self-Hit - create a bounding box around self

   Vector3 min = new Vector3(catapultPosition, 0);

   Vector3 max = new Vector3(catapultPosition +

       new Vector2(animations["Fire"].frameSize.X,

           animations["Fire"].frameSize.Y), 0);

   BoundingBox selfBox = new BoundingBox(min, max);

   // Check enemy - create a bounding box around the enemy

   min = new Vector3(enemy.Catapult.Position, 0);

   max = new Vector3(enemy.Catapult.Position +

       new Vector2(animations["Fire"].frameSize.X,

           animations["Fire"].frameSize.Y), 0);

   BoundingBox enemyBox = new BoundingBox(min, max);

   // Check self hit

if (sphere.Intersects(selfBox) && currentState != CatapultState.Hit)

   {

       AudioManager.PlaySound("catapultExplosion");

       // Launch hit animation sequence on self

       Hit();

       enemy.Score++;

       bRes = true;

   }

   // Check if enemy was hit

   else if (sphere.Intersects(enemyBox)

Page | 81

Document info
Document views350
Page views350
Page last viewedThu Jan 19 19:51:52 UTC 2017
Pages102
Paragraphs3115
Words17333

Comments