不再需要帮助
我遇到的错误是当球产生时,碰撞检测不会一直有效。
当我增加球速时(这是必要的),这似乎更常发生。如果您需要更多代码,请询问。
if ball_pos[1] > paddle1_pos-HALF_PAD_HEIGHT -2 and ball_pos[1]<paddle1_pos +HALF_PAD_HEIGHT +2 and ball_pos[0] - BALL_RADIUS <= PAD_WIDTH+2:
ball_vel[0] = -1.1*ball_vel[0]
ball_vel[1] = ball_vel[1]
elif ball_pos[1] > paddle2_pos-HALF_PAD_HEIGHT -2 and ball_pos[1] < paddle2_pos +HALF_PAD_HEIGHT+2 and WIDTH - (WIDTH - (ball_pos[0] + BALL_RADIUS)) >= (WIDTH - PAD_WIDTH) -2:
ball_vel[0] = -1.1*ball_vel[0]
ball_vel[1] = ball_vel[1]