Ejemplo n.º 1
0
 /// <summary>
 /// Solve collision between ball and another object. Return true
 /// if collision happens, false if not
 /// </summary>
 /// <param name="obj">object to check collision with</param>
 /// <returns>Determite if ball hit object</returns>
 public void HandleCollision(IInteractive obj)
 {
     if (Direction.X > 0 && IsTouchingLeft(obj))
     {
         ReflectHorizontally();
         obj.Hit(this);
     }
     else if (Direction.X < 0 && IsTouchingRight(obj))
     {
         ReflectHorizontally();
         obj.Hit(this);
     }
     else if (Direction.Y > 0 && IsTouchingTop(obj))
     {
         ReflectVertically();
         obj.Hit(this);
     }
     else if (Direction.Y < 0 && IsTouchingBottom(obj))
     {
         ReflectVertically();
         obj.Hit(this);
     }
 }