X hits on this document

290 views

0 shares

0 downloads

0 comments

60 / 102

130.

Implement the “CheckHit” method, which appears in the Update method above. This method is responsible for determining whether a projectile has hit one of the catapults:

C#

private bool CheckHit()

{

   bool bRes = false;

   // Build a sphere around the 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

   // TODO: Take asset size into account

   Vector3 min = new Vector3(catapultPosition, 0);

   Vector3 max = new Vector3(catapultPosition + new Vector2(75, 60), 0);

   BoundingBox selfBox = new BoundingBox(min, max);

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

   // TODO: Take asset size into account

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

   max = new Vector3(enemy.Catapult.Position + new Vector2(75, 60), 0);

   BoundingBox enemyBox = new BoundingBox(min, max);

   // Check self hit

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

   {

       // TODO: Play self hit sound

       // Launch hit animation sequence on self

       Hit();

       enemy.Score++;

       bRes = true;

   }

   // Check if enemy was hit

   else if (sphere.Intersects(enemyBox)

       && enemy.Catapult.CurrentState != CatapultState.Hit

       && enemy.Catapult.CurrentState != CatapultState.Reset)

   {

       // TODO: Play enemy hit sound

       // Launch enemy hit animaton

Page | 60

Document info
Document views290
Page views290
Page last viewedSat Dec 10 17:14:47 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments