在pygame上进行Pong,尽管不与球拍碰撞,球始终会弹跳

问题描述

总体而言,我对编程并不陌生,这是我的第二场比赛,因此提前对不起。 我现在只用一个球拍打了一个乒乓球比赛,但是即使不打球,球也会不断弹跳。 这是我的抽奖球功能:

    def draw_ball(self): 
        self.sc.blit(ball,(self.bx,self.by))
        self.bx += self.speedx
        self.by += self.speedy

        if self.bx >= 1000:#check goals
            self.bx = 250
            self.by = 340

        if self.bx <= 38: #check coalision
            self.speedx *= -1
        if self.by<= 12: 
            self.speedy *= -1
        if  self.by>= 725: 
            self.speedy *= -1
        
        #check coalision with the paddle 
        #px and py are the coordinates of the paddle 
        if self.bx > (self.px - 35) and (self.by < (self.py + 196) and  (self.by + 38) > self.py) : 
            self.speedx *= -1

这是主循环:

#global variables
WIN_HEIGHT = 1024 
WIN_WIDTH = 768 
SPEED = 5 
PX = 956
PY  = 320 
MOVEMENT = 5
BALL = Ball(550,60,screen,.5,.4,PX,PY)


running = True 
while running: 

  redraw_screen()

  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      running = False
    mouse_pos = pygame.mouse.get_pos()
    if event.type == pygame.MOUSEBUTTONDOWN and START_BUTTON.is_clicked(mouse_pos):
      running = False
      playing = True

     while playing: 
        screen.fill((0,0))
        BALL.draw_ball()
        PLAYER.draw_player()
        pygame.display.flip()

        for event in pygame.event.get():
          if event.type == pygame.QUIT:
            running = False
            playing = False 

感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)