【问题标题】:Make one circle disappear and another appear使一个圆圈消失,另一个圆圈出现
【发布时间】:2014-03-15 17:09:18
【问题描述】:

所以我正在尝试为 iOS 重新创建 Flappy Fall 游戏,但我无法让一个圆圈消失而另一个圆圈出现。现在我把它作为主循环。

    while True:
        if newBall==True:
            x=rand(50,w-50)
            y=-7
            newBall=False
        if x in range(xBasket-length,xBasket+length) and y in range(yBasket-int(length/2),yBasket+int(length/2)):    #If the circle hit's the basket
            newBall=True        #Creates a new ball
            score+=1
        elif x in range(0,w) and y in range(700,751):    #If it hits the ground
            break
        if newBall==False:    #If there is no new ball yet
            y-=7
        win.fill(BLACK)
        font=pygame.font.Font(None,48)
        show=font.render(str(score),1,RED,None)
        win.blit(show,(200,150))
        pygame.draw.rect(win,RED,(0,700,w,h),0)    #ground
        for event in pygame.event.get():
            if event.type==QUIT:
               pygame.quit()
                sys.exit()
            if event.type==KEYDOWN:
                if event.key==K_LEFT and xBasket-length!=0:
                    xBasket-=5
                if event.key==K_RIGHT and xBasket+length!=w:
                    xBasket+=5
        pygame.draw.circle(win,BLUE,(x,y),7)    #ball that falls
        pygame.draw.polygon(win,WHITE,((xBasket-length,yBasket-int(length/2)),(xBasket+length,yBasket-int(length/2)),(xBasket+length,yBasket+int(length/2)),(xBasket-length,yBasket+int(length/2)),0))    #basket
        pygame.display.update()
        time.delay(5)
        s(0.001)

我不知道哪里出了问题,因为“篮子”显示得很好。

【问题讨论】:

  • “遇到麻烦” - 究竟是什么问题?
  • 球根本没有出现。这只是一个屏幕。

标签: python pygame recreate


【解决方案1】:

在第 12 行,您只有 y = -7,也许您还想在它之前包含 x = rand(50, 50-w) 行,以便您有一个 x 和一个 y 位置只是y 的位置。

x = rand(50, 50-w)

y = -7

【讨论】:

    【解决方案2】:

    试试

    print x,y
    

    就在您绘制圆圈以检查您的值之前。看起来您的 y 值是负数,我相信*您需要正坐标才能在画布上绘制。

    编辑:确认,我通过将 y=-7 更改为 y=300 使您的代码正常工作,屏幕上出现了一个小蓝球。此外,它可能不相关,但我必须编辑字体行才能阅读:

     show=font.render(str(score),1,RED)#,None)
    

    但我认为这与我的 python 和 pygame 版本有关。

    【讨论】:

      猜你喜欢
      • 2011-03-10
      • 2021-06-24
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 2019-04-25
      • 2018-06-22
      • 1970-01-01
      相关资源
      最近更新 更多