我正在学习《面向绝对初学者的 Python 编程》这本书,并决定通过制作自己的游戏来测试我的一些技能。游戏基本上是“不要被飞来的尖刺击中”,我遇到了一个问题。使用此代码运行时:
class Player(games.Sprite):
"""The player that must dodge the spikes."""
def update(self):
"""Move to the mouse."""
self.x = games.mouse.x
self.y = games.mouse.y
self.check_collide()
def check_collide(self):
"""Check for a collision with the spikes."""
for spike in self.overlapping_sprites:
spike.handle_collide()
def main():
pig_image = games.load_image("Mr_Pig.png")
the_pig = Player(image = pig_image,
x = games.mouse.x,
y = games.mouse.y)
games.screen.add(the_pig)
games.mouse.is_visible = False
games.screen.event_grab = True
games.screen.mainloop()
main()
Run Code Online (Sandbox Code Playgroud)
我没问题。但是当我想使用“ init ”时,就像在这段代码中一样:
class Player(games.Sprite):
"""The player that must dodge the spikes."""
def update(self):
"""Move to …Run Code Online (Sandbox Code Playgroud)