pygame flapy bird随机管道生成

2024-05-16 07:32:27 发布

您现在位置:Python中文网/ 问答频道 /正文

对于一个学校项目,我正在制作flappy bird,并尝试在管道到达某个点时随机生成管道,以获得新管道

top = [pipe(start, -550, False), pipe (start , 300, True )]
mid = [pipe(start , -400, False), pipe(start , 400, True)]
bod = [pipe(start, -300, False), pipe(start , 500, True)]
obsitcal = mid








def obsit(obsitcal):
    for pipe in obsitcal:
        if pipe.x <= 50:
            pipenum = random.randint(1, 3)
            if pipenum == 1:
                obsitcal.append([pipe(start, -550, False), pipe(start , 300, True )])
            elif pipenum == 2:
                obsitcal = mid
            elif pipenum == 3:
                obsitcal = bod

管道到达应生成新管道的点后,游戏停止,错误:

 obsitcal.append([pipe(start, -550, False), pipe(start , 300, True )])

TypeError: 'pipe' object is not callable

任何帮助都将不胜感激


Tags: 项目falsetrueif管道start学校pipe
1条回答
网友
1楼 · 发布于 2024-05-16 07:32:27

您正在循环中重新分配pipe,隐藏您的def pipe():(这不是问题,但我们可以看到它是一个函数)

我建议将pipe函数重命名为带有动词的函数,例如make_pipe()

相关问题 更多 >