我正在制作的游戏有另一个问题,我希望每次我由 spawner 类创建新的小行星时,小行星精灵都会随机化,但我不断收到此错误“非默认参数遵循默认参数”,我非常困惑该怎么做,实际的随机图像存储在生成器中,然后导入到 Asteroid 类。任何帮助将不胜感激,图像列表是一个全局变量。
images = [games.load_image("asteroid_small.bmp"),
games.load_image("asteroid_med.bmp"),
games.load_image("asteroid_big.bmp")]
def check_drop(self):
""" Decrease countdown or drop asteroid and reset countdown. """
if self.time_til_drop > 0:
self.time_til_drop -= 0.7
else:
asteroid_size = random.choice(images)
new_asteroid = Asteroid(x = self.x,image = asteroid_size)
games.screen.add(new_asteroid)
然后这是小行星类的一部分,随机图像将存储在其中
def __init__(self, x, y = 10,image):
""" Initialize a asteroid object. """
super(Asteroid, self).__init__(image = image,
x = x, y = y,
dy = Asteroid.speed)