if rightPaddle.bottom() < HEIGHT: rightPaddle.move_down() #handling ball motion if ball.x <= 0: ball.x, ball.y = WIDTH/2, HEIGHT/2 rightScore += 1 scored = True elif ball.x >= WIDTH - ball.radius: ball.x, ball.y = WIDTH/2, HEIGHT/2 leftScore += 1 scored = True if ball.y <= ball.radius or ball.y >= HEIGHT - ball.radius: ball.set_yspeed( -ball.yspeed ) #ball - paddle collision detection if ( rightPaddle.left() < (ball.x + ball.radius) and rightPaddle.right() > (ball.x - ball.radius) ) and ( rightPaddle.top() < (ball.y + ball.radius) and rightPaddle.bottom() > (ball.y - ball.radius) ): ball.bounce( rightPaddle.top(), rightPaddle.bottom(), rightPaddle.height ) if ( leftPaddle.left() < (ball.x + ball.radius) and leftPaddle.right() > (ball.x - ball.radius) ) and ( leftPaddle.top() < (ball.y + ball.radius) and leftPaddle.bottom() > (ball.y - ball.radius) ): ball.bounce( leftPaddle.top(), leftPaddle.bottom(), leftPaddle.height ) #render half-field line pygame.draw.line( SURFACE, WHITE, ( WIDTH/2, 0 ), ( WIDTH/2, HEIGHT ) ) #render the paddles leftPaddle.render(SURFACE) rightPaddle.render(SURFACE)