本文整理汇总了Python中ball.Ball.set_yspeed方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.set_yspeed方法的具体用法?Python Ball.set_yspeed怎么用?Python Ball.set_yspeed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ball.Ball
的用法示例。
在下文中一共展示了Ball.set_yspeed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1:
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import set_yspeed [as 别名]
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)