Example #1
0
        /// <summary>
        /// �����Ͱ��Ƿ�����ײ����������͵���Collision()����
        /// </summary>
        /// <param name="ball">Ҫ������</param>
        /// <param name="paddle">Ҫ���İ�</param>
        private void DetectPaddleCollision(Ball ball, Paddle paddle)
        {
            if ((ball.Right + ball.XSpeed > paddle.Left) &&
                (ball.Left + ball.XSpeed < paddle.Right) &&
                (ball.Bottom + ball.YSpeed > paddle.Top) &&
                (ball.Top + ball.YSpeed < paddle.Bottom) &&
                ball.YSpeed >= 0) //ͬ�ϱ��жϣ�������ײ���
            {
                ball.Collide(paddle);
                paddleSound.Play();

            }
        }
Example #2
0
 /// <summary>
 /// Checks if a ball is about to hit the paddle and calls the Collide() method of the ball if it is
 /// </summary>
 /// <param name="ball">Ball object to check for collision</param>
 /// <param name="paddle">Paddle object to check for collision</param>
 private void DetectPaddleCollision(Ball ball, Paddle paddle)
 {
     if ((ball.Right + ball.XSpeed > paddle.Left) &&
         (ball.Left + ball.XSpeed < paddle.Right) &&
         (ball.Bottom + ball.YSpeed > paddle.Top) &&
         (ball.Top + ball.YSpeed < paddle.Bottom) &&
         ball.YSpeed >= 0) //is the ball about to hit the paddle
     {
         ball.Collide(paddle);
         paddleSound.Play();
     }
 }