Exemple #1
0
 private void CheckForCollisions(GameObject currentObject, GameObject collisionObject, bool both)
 {
     Rectangle collision = Rectangle.Intersect(currentObject.BoundingRectangle(), collisionObject.BoundingRectangle());
     if (collision.Width < collision.Height)
     {
         currentObject.OnSideCollision(collisionObject);
         if (both)
             collisionObject.OnSideCollision(currentObject);
     }
     else if (collision.Width > collision.Height)
     {
         if (currentObject.BoundingRectangle().Y > collisionObject.BoundingRectangle().Y)
         {
             currentObject.OnHeadbutt(collisionObject);
             if (both)
                 collisionObject.OnStomp(currentObject);
         }
         else if (currentObject.BoundingRectangle().Y < collisionObject.BoundingRectangle().Y)
         {
             currentObject.OnStomp(collisionObject);
             if (both)
                 collisionObject.OnHeadbutt(currentObject);
         }
     }
 }