我的碰撞在矩形上方和下方都有效。 有时在侧面,但在大多数情况下,球的行为很奇怪: -在矩形的顶部和底部之间跳动
碰撞中出了什么问题或我可以改善什么?
if(ballX >= rectX1 and ballX <= rectX1 + rectWidth and ballY + ballRadius >= rectY1 and ballY - ballRadius <= rectY1 + rectHeight):
ballMoveY = -ballMoveY
if(ballY >= rectY1 and ballY <= rectY1 + rectHeight and ballX + ballRadius >= rectX1 and ballX- ballRadius <= rectX1 + rectWidth):
ballMoveX = -ballMoveX