问题描述
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
语句。