我正在尝试对小行星进行一些练习,当我尝试测试我的播放器(矩形)和我的小行星(圆圈)之间的碰撞时遇到了问题。我的圈子在类中定义,然后在函数中维护(如下所示)。我无法在 pygame 中找到任何方法来满足我的需要,在我开始深入尝试使用一些几何来解决点是否相交的问题之前,我想看看是否有人知道我可以使用的方法。
class asteroid:
def __init__(self, x_coord, y_coord, speed, deviation, size, offset):
self.x_coord = x_coord
self.y_coord = y_coord
self.speed = speed
self.size = size
self.deviation = deviation
self.offset = offset
def send_asteroid():
curr_size = random.randint(40, 80)
curr_asteroid = asteroid(-curr_size, random.randint(0, screen_height), random.randint(1, 10),random.randint(-3,3), curr_size, random.randint(0, 20) * 1000)
asteroids_array.append(curr_asteroid)
def maintain_asteroid(asteroid):
pygame.draw.circle(screen, "grey", (asteroid.x_coord, asteroid.y_coord), asteroid.size)
if curr_ast.collidedict
asteroid.x_coord += asteroid.speed
asteroid.y_coord += asteroid.deviation
def set_difficulty(rating):
for x in range(rating):
send_asteroid()
然后我在 asteroids_array 中的每个小行星上循环运行 maintain_asteroid。
我已经通读了 pygame 文档并一直在查看 .collidict 方法,但在阅读有关我的论点应该是什么样子的文档时我感到困惑。