【发布时间】:2020-11-03 12:15:14
【问题描述】:
我有这个代码
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。它只是让球穿过它。
我该如何解决这个问题?
【问题讨论】:
标签: python pygame rectangles