【发布时间】:2019-09-25 08:19:14
【问题描述】:
在我的 for 循环中,我有一个声明为 p.x -= p.vel。显然,这会导致对象对屏幕上的每个对象进行加速。如果我从列表中弹出对象,它不会加速太多,但它仍然会加速一点。我怎样才能解决这个问题?程序是用pygame写的
这个游戏基本上是一个飞扬的小鸟游戏,它是在加速的管道,但我希望它们始终以相同的速度移动
这是类和变量
def __init__(self, x, width):
self.bottom_height = random.randint(50, 400)
self.top_height = screen_height - 175 - self.bottom_height
self.width = width
self.bottom_y = screen_height - self.bottom_height
self.top_y = 0
self.x = x
self.vel = 2.5
self.pipes = []
这里是函数
def spawn(self):
for p in pipe.pipes:
if bird.x == p.x:
pipe.pipes.append(Pipe(pipe.x, pipe. width))
def move(self):
self.spawn()
for p in pipe.pipes:
if 0 - p.width < p.x < screen_width + 50:
p.x -= p.vel
else:
pipe.pipes.pop(pipe.pipes.index(p))
【问题讨论】:
-
什么加速?您正在使用的库(pygame?)将比“oop”和“loops”作为标签更有用
-
游戏中的管道(飞扬的小鸟)。
标签: python python-3.x loops pygame