在我的游戏中玩家有避免小行星,当小行星撞击屏幕底部时它被摧毁并且分数增加十,但我希望小行星速度在玩家达到一定分数后增加但每次我这样做我使用小行星的代码只是出现故障,分数开始迅速增加,有人可以帮我吗?
Asteroid 类,代码在 update 方法中。
class Asteroid(games.Sprite):
global lives
global score
global inventory
"""
A asteroid which falls through space.
"""
image = games.load_image("asteroid_med.bmp")
speed = 2
def __init__(self, x,image, y = 10):
""" Initialize a asteroid object. """
super(Asteroid, self).__init__(image = image,
x = x, y = y,
dy = Asteroid.speed)
def update(self):
""" Check if bottom edge has reached screen bottom. """
if self.bottom>games.screen.height:
self.destroy()
score.value+=10
if score.value == 100:
Asteroid.speed+= 1
分数变量(如果需要)
score = games.Text(value = 0, size = 25, color = color.green,
top = 5, right = games.screen.width - 10)
games.screen.add(score)