如何解决Python没有检测到我的一个对象发生碰撞
if ball.colliderect(border_up_rect):
border_up_collide = True
elif ball.colliderect(border_down_rect):
border_down_collide = True
elif ball.colliderect(goal_attack_rect):
my_score += 1
elif ball.colliderect(goal_def_rect):
ai_score += 1
if border_up_collide == True:
if where_did_it_come_from == True:
ball_x -= 7
ball_y += 2
pboard_shoot1 = False
pboard_shoot2 = False
pboard_shoot3 = False
elif where_did_it_come_from == False:
ball_x -= 3
ball_y += 2
ai_shoot1 = False
ai_shoot2 = False
ai_shoot3 = False
elif border_down_collide == True:
if where_did_it_come_from == True:
ball_x -= 7
ball_y -= 2
pboard_shoot1 = False
pboard_shoot2 = False
pboard_shoot3 = False
elif where_did_it_come_from == False:
ball_x -= 3
ball_y -= 2
ai_shoot1 = False
ai_shoot2 = False
ai_shoot3 = False
elif goal_attack_collide == True:
if where_did_it_come_from == True:
ball_x = 600
ball_y = 220
pboard_shoot1 = False
pboard_shoot2 = False
pboard_shoot3 = False
elif where_did_it_come_from == False:
ball_x = 600
ball_y = 220
ai_shoot1 = False
ai_shoot2 = False
ai_shoot3 = False
在这里,它可以与border_up_rect
以及其他所有collide.rect
一起正常使用,但不能与border_down_rect
一起使用。它只是让球通过。
我该如何解决?
解决方法
border_down_rect
不起作用的原因是,border_up_rect
仍然为真,并且在border_up_rect
为真之前,它不会切换elif
语句。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。