【发布时间】:2014-12-04 05:53:59
【问题描述】:
所以在之前询问过碰撞检测之后,Collision Detection in a List, 我在
find_overlapping
功能。碰撞检测工作正常,但由于我正在创建一个破砖器风格的游戏,我必须根据球击中砖块的哪一侧来更改方向变量。被击中的砖块保存在变量“砖块”中,但是当我尝试运行程序时出现错误,“ValueError:需要多于 0 个值才能解包”。我猜这意味着它正在尝试查找“砖”的坐标,但由于没有砖变量但它无法运行?谁能帮忙解释一下。
overlap = drawpad.find_overlapping(x1,y1,x2,y2)
length = len(overlap)
if length > 1:
listPlace = overlap[1] - 3
brick = bricklist[listPlace]
drawpad.delete(brick)
bx1,by1,bx2,by2 = drawpad.coords(brick)
if x1 <= bx1 or x2 >= bx2:
angle = -angle
if y1 <= by1 or by2 >= y2:
direction = -direction
我也将代码重写到下面,但是我认为我只是因为出现了相同的错误消息而将其复杂化。
overlap = drawpad.find_overlapping(x1,y1,x2,y2)
length = len(overlap)
if length > 1:
listPlace = overlap[1] - 3
brick = bricklist[listPlace]
drawpad.delete(brick)
for x in bricklist:
if x == brick:
bx1,by1,bx2,by2 = drawpad.coords(x)
if x1 <= bx1 or x2 >= bx2:
angle = -angle
if y1 <= by1 or by2 >= y2:
direction = -direction
【问题讨论】:
标签: python tkinter coordinates collision-detection