所以我一直在制作一个小游戏来测试自己,但我似乎根本无法更新分数,我能帮忙吗?编辑:很抱歉这个问题没有具体说明,当小行星经过屏幕时,第一个给出十分但之后分数没有上升时,问题是什么?我认为这是这段代码的问题,我希望在小行星从屏幕下方通过后,小行星被删除,然后得分增加 10 分。我也是 Livewires 模块。
class Asteroid(games.Sprite):
"""
A asteroid which falls through space.
"""
image = games.load_image("asteroid_med.bmp")
speed = 1
def __init__(self, x, y = 10):
""" Initialize a asteroid object. """
super(Asteroid, self).__init__(image = Asteroid.image,
x = x, y = y,
dy = Asteroid.speed)
self.score = games.Text(value = 0, size = 25, color = color.green,
top = 5, right = games.screen.width-10)
games.screen.add(self.score)
def update(self):
""" Check if bottom edge has reached screen bottom. """
self.add_score()
def add_score(self):
if self.bottom > games.screen.height:
self.score.value+=10
self.score.right = games.screen.width - 10
self.destroy()