Python 球与对象的碰撞隐藏

Python 球与对象的碰撞隐藏,python,collision-detection,turtle-graphics,Python,Collision Detection,Turtle Graphics,我正在尝试做一个拦网游戏,但不知道如何正确地对球和设置在上面的盒子进行碰撞检测。基本上它应该做什么当球碰到这个盒子时,盒子必须隐藏,球必须反弹回来 from time import sleep from turtle import Turtle, Screen, Shape BALL_RADIUS = 5 FONT = ("Arial", 24, "normal") ball_move_horizontal = 1 ball_move_vertical

我正在尝试做一个拦网游戏,但不知道如何正确地对球和设置在上面的盒子进行碰撞检测。基本上它应该做什么当球碰到这个盒子时,盒子必须隐藏,球必须反弹回来

from time import sleep
from turtle import Turtle, Screen, Shape

BALL_RADIUS = 5
FONT = ("Arial", 24, "normal")
ball_move_horizontal = 1 
ball_move_vertical = 1 

def draw_ball():
    # BALL
    ball = Turtle()
    ball.penup()
    ball.shape("circle") 
    ball.shapesize(BALL_RADIUS / 10, BALL_RADIUS / 10)  
    ball.sety(BORDER_BOTTOM + 32)
    return ball

def draw_boxes(rows, cols, x, y, w, h):
    color_list = ["cyan", "pink"]
    boxes_list = []
    for i in range(rows):
        for j in range(cols):
            box = Turtle("square")
            box.penup()
            box.shapesize(w, h, 3) 
            box.color("white", color_list[(j + i) % 2]) 
            box.goto(x + h * 20 * j, y + w * 20 * i)
            boxes_list.append(box)
    return boxes_list
    boxes_list = draw_boxes(3, 9, -245, 230, 1, 3)
    pass

我希望在这方面能得到一些帮助。

我很确定您应该能够使用
海龟距离
功能来完成这项工作。所以你可以这样做:

如果球距(盒)<50:
#球反弹,矩形隐藏代码