Esempio n. 1
0
 private void checkTwoObjects(Objects.StaticObject obj1, Objects.StaticObject obj2)
 {
     if (obj1 is Objects.Projectile || obj2 is Objects.Projectile)
     {
         if (obj1 is Objects.Projectile)
         {
             if (obj2.Equals(((Objects.Projectile)obj1).parent))
                 return;
             obj1.doDamage(10000);
             obj2.doDamage(((Objects.Projectile)obj1).damage);
             if (obj2 is Objects.playerObject)
             {
                 if (numPlayers.Equals(Players.two))
                 {
                     explosion.Play();
                 }
                 else
                 {
                     if (obj2.Team.Equals(Team.Red))
                         explosion.Play();
                 }
             }
         }
         else
         {
             if (obj1.Equals(((Objects.Projectile)obj2).parent))
                 return;
             obj2.doDamage(10000);
             obj1.doDamage(((Objects.Projectile)obj2).damage);
             if (obj1 is Objects.playerObject)
             {
                 if (numPlayers.Equals(Players.two))
                 {
                     explosion.Play();
                 }
                 else
                 {
                     if (obj1.Team.Equals(Team.Red))
                         explosion.Play();
                 }
             }
         }
     }
     else
     {
         // add object collision settings
         if (obj1 is Objects.DynamicObject && obj2 is Objects.DynamicObject)
         {
             Objects.DynamicObject d1 = obj1 as Objects.DynamicObject;
             Objects.DynamicObject d2 = obj2 as Objects.DynamicObject;
             d1.bumpVelocity += Vector3.Normalize(Matrix.CreateFromQuaternion(d2.rotation).Forward) * d2.Mass * d2.ShipMovementInfo.speed / d1.Mass * COLLISION_SPEED_PRESERVATION;
             d2.bumpVelocity += Vector3.Normalize(Matrix.CreateFromQuaternion(d1.rotation).Forward) * d1.Mass * d1.ShipMovementInfo.speed / d2.Mass * COLLISION_SPEED_PRESERVATION;
         }
         else if (obj1 is Objects.DynamicObject)
         {
             Objects.DynamicObject d = obj1 as Objects.DynamicObject;
             d.bumpVelocity += Vector3.Normalize(Matrix.CreateFromQuaternion(d.rotation).Backward) * d.ShipMovementInfo.speed * COLLISION_SPEED_PRESERVATION;
         }
         else if (obj2 is Objects.DynamicObject)
         {
             Objects.DynamicObject d = obj2 as Objects.DynamicObject;
             d.bumpVelocity += Vector3.Normalize(Matrix.CreateFromQuaternion(d.rotation).Backward) * d.ShipMovementInfo.speed * COLLISION_SPEED_PRESERVATION;
         }
         obj1.ShipMovementInfo.speed = 0;
         obj2.ShipMovementInfo.speed = 0;
     }
 }