我设法制作了一个查看每个矩形角的算法:
def rectsCollideSimple (rect1, surf1, rect2, surf2):
collide = False
try:
if surf1.get_at((rect2.left - rect1.left, rect2.top - rect1.top)) != surf1.get_colorkey():
collide = True
except IndexError:
useless = None
try:
if surf1.get_at((rect2.right - rect1.left, rect2.top - rect1.top)) != surf1.get_colorkey():
collide = True
except IndexError:
useless = None
try:
if surf1.get_at((rect2.left - rect1.left, rect2.bottom - rect1.top)) != surf1.get_colorkey():
collide = True
except IndexError:
useless = None
try:
if surf1.get_at((rect2.right - rect1.left, rect2.bottom - rect1.top)) != surf1.get_colorkey():
collide = True
except IndexError:
useless = None
return collide
def rectsCollide (rect1, surf1, rect2, surf2):
if rectsCollideSimple(rect1, surf1, rect2, surf2) or rectsCollideSimple(rect2, surf2, rect1, surf1):
return True
else:
return False
可能不是最有效的方法,但它解决了我的问题:)