在pygame的破砖游戏中,任何增加速度的方法



我正在制作一款破砖游戏,每次它碰到球拍时我都想提高速度。但当我出于某种原因在速度上加1时,它会增加很多倍。这是我的代码

if ball.colliderect(paddle):
y_positive = False
y_negative = True
ball_speed += 1

这是因为它们的碰撞框重叠的每个时钟周期都会发生这种情况

volley = False  ##  only allow increment once ball crosses midpoint of screen
if ball.x > screen_width /2: volley = True
if ball.colliderect( paddle ) and volley:
y_positive = False
y_negative = True
ball_speed += 1
volley = False

或者,一旦球碰到,将球推离球拍足够远,以确保他们的碰撞盒不会碰到。

if ball.colliderect( paddle ):
y_positive = False
y_negative = True
ball_speed += 1
ball.x += ball.width /2

不管它需要多大的力量。

最新更新