Python2.6,pygame,pong ball无法正确运行

Python2.6,pygame,pong ball无法正确运行,python,pygame,python-2.6,pong,Python,Pygame,Python 2.6,Pong,试图让球沿着y坐标移动,这是行不通的,更多的解释在底部 from livewires import games, color games.init(screen_width = 640, screen_height = 480, fps = 50) points = games.Text(value = 0, size = 25, color = color.green, bottom = games.screen.height -

试图让球沿着y坐标移动,这是行不通的,更多的解释在底部

from livewires import games, color
games.init(screen_width = 640, screen_height = 480, fps = 50)
points = games.Text(value = 0, size = 25, color = color.green,
                                bottom = games.screen.height - 5, left = 10)
games.screen.add(points)

class Paddle(games.Sprite):
    image = games.load_image("paddle.bmp")
    def __init__(self):
        super(Paddle, self).__init__(image = Paddle.image, y = games.mouse.y, right = games.screen.width)

    def update(self):
        """ Move to mouse x position. """
        self.y = games.mouse.y
        if self.top < 0:
            self.top = 0
        if self.bottom > games.screen.height:
            self.bottom = games.screen.height
        self.check_bounce()

    def check_bounce(self):
        for bouncingBall in self.overlapping_sprites:
            bouncingBall.handle_bounce()

class BouncingBall(games.Sprite):
    image = games.load_image("ball.bmp")
    def __init__(self, x, y, dx, dy):
        super(BouncingBall, self).__init__(image = BouncingBall.image, x = x, y = y, dx = dx, dy = dy)

    def update(self):
        """ Check if bottom edge has reached screen bottom. """
        if self.top > 0 or self.bottom < games.screen.height:
            self.dy = -self.dy
        if self.left < 0:
            self.dx = -self.dx
        if self.right > games.screen.width:
            self.end_game()

    def handle_bounce(self):
        global points
        points.value += 10
        points.left = 10
        self.dx = -self.dx

    def end_game(self):
        end_message = games.Message(value = "GAME OVER",
                                    size = 90,
                                    color = color.red,
                                    x = games.screen.width/2,
                                    y = games.screen.height/2,
                                    lifetime = 10 * games.screen.fps,
                                    after_death = games.screen.quit)
        games.screen.add(end_message)


def main():
    background_image = games.load_image("background.png", transparent = False)
    games.screen.background = background_image
    the_paddle = Paddle()
    games.screen.add(the_paddle)
    games.mouse.is_visible = False
    new_ball = BouncingBall(x = games.screen.width/2, y = games.screen.height/2, dx = 2, dy = 2) #<-believe it is right here im messing up
    games.screen.add(new_ball)
    games.screen.mainloop()

main()
从livewires导入游戏,颜色
games.init(屏幕宽度=640,屏幕高度=480,fps=50)
点数=游戏。文本(值=0,大小=25,颜色=color.green,
底部=games.screen.height-5,左侧=10)
游戏。屏幕。添加(点数)
班级桨(游戏.精灵):
image=games.load\u图像(“blade.bmp”)
定义初始化(自):
超级(划桨,自我)。\uuuu初始(image=palle.image,y=games.mouse.y,right=games.screen.width)
def更新(自我):
“”“移动到鼠标x位置。”“”
self.y=games.mouse.y
如果self.top<0:
self.top=0
如果self.bottom>games.screen.height:
self.bottom=games.screen.height
self.check_bounce()
def检查_反弹(自):
对于self.lapping_精灵中的弹跳球:
bouncingBall.handle_bounce()
班级弹跳球(游戏.精灵):
image=games.load\u图像(“ball.bmp”)
定义初始化(self,x,y,dx,dy):
super(BouncingBall,self)。\uuuu初始化(image=BouncingBall.image,x=x,y=y,dx=dx,dy=dy)
def更新(自我):
“”“检查下边缘是否已到达屏幕底部。”“”
如果self.top>0或self.bottomgames.screen.width:
self.end_game()
def手柄_反弹(自):
全局点
点数。数值+=10
点左=10
self.dx=-self.dx
def结束_游戏(自我):
结束消息=games.message(value=“游戏结束”,
尺寸=90,
颜色=color.red,
x=games.screen.width/2,
y=games.screen.height/2,
寿命=10*games.screen.fps,
死亡后=游戏。屏幕。退出)
games.screen.add(结束消息)
def main():
背景图片=游戏。加载图片(“background.png”,transparent=False)
games.screen.background=背景图片
桨
游戏。屏幕。添加(划桨)
games.mouse.is_visible=False

新建球=弹跳球(x=games.screen.width/2,y=games.screen.height/2,dx=2,dy=2)#确保这条线

if self.top > 0 or self.bottom < games.screen.height:
    self.dy = -self.dy
如果self.top>0或self.bottom

不是经常计算为
True
。如果是这样,您的y速度将不断切换,球将永远不会改变y坐标。

此外,球x坐标工作正常。球更新功能实际上不会移动球,它只会改变速度?@Aesthete我知道,但下面的行不应该在y坐标中开始2像素/帧的移动吗?新建球=弹跳球(x=games.screen.width/2,y=games.screen.height/2,dx=2,dy=2)如果self.top>0或self.bottom
不经常被击中,请确保此行
。在里面印个字什么的。@Aesthete哇,我怎么没看到,谢谢。问题解决了