我正在制作 Pong 克隆以用于学习目的,并且需要在按下鼠标时让球从屏幕中间移动(当它经过桨时它被发送到那里)。我试过下面的代码,但它什么也没做,所以我可能不理解语法。请尽量保持简单,并解释一下,我宁愿没有 50 行代码(我想了解我在这里使用的所有内容)。我认为这是所有相关的代码,如果不是,对不起。谢谢。
def middle(self):
"""Restart the ball in the centre, waiting for mouse click. """
# puts ball stationary in the middle of the screen
self.x = games.screen.width/2
self.y = games.screen.height/2
self.dy = 0
self.dx = 0
# moves the ball if mouse is pressed
if games.mouse.is_pressed(1):
self.dx = -3