我在此乒乓球比赛中划了一个边界,但球拍可以划过边界。如何停止呢?

我在此乒乓球比赛中划了一个边界,但球拍可以划过边界。如何停止呢?,第1张

我在此乒乓球比赛中划了一个边界,但球拍可以划过边界。如何停止呢?

为了使球拍保持在场地上,请在游戏循环中添加一个复选标记,以在球拍到达边缘时阻止球拍移动。

.......if pong.rect.x < 10:    pong.rect.x, pong.rect.y = 375, 250    pong.dx = 1    paddle2.points += 1# keep paddles in correct range     # add this sectionif paddle1.rect.y < 0 : paddle1.rect.y = 0if paddle3.rect.y < 0 : paddle3.rect.y = 0if paddle2.rect.y < 200 : paddle2.rect.y = 200if paddle4.rect.y < 200 : paddle4.rect.y = 200if paddle1.rect.y > 200 - 75 : paddle1.rect.y = 200 - 75if paddle3.rect.y > 200 - 75 : paddle3.rect.y = 200 - 75if paddle2.rect.y > 500 - 75 : paddle2.rect.y = 500 - 75if paddle4.rect.y > 500 - 75 : paddle4.rect.y = 500 - 75#if the ball and paddle collide, bounce off itif paddle1.rect.colliderect(pong.rect):    pong.dx = 1if paddle2.rect.colliderect(pong.rect):    pong.dx = -1.....


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5645689.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存