我刚刚做了一个太空入侵游戏,东西会掉到地上,你必须避免坠毁,等等。
我成功地创建了两个物体同时下落,但我无法让它们以不同的速度执行此操作。
这是第一个对象的属性。
thing_startx = random.randrange(0, display_width-100)
thing_starty = -700
thing_speed = 4
现在它落下
thing_starty += thing_speed
在每个 while 循环迭代中。
对于下一个对象,我只是将随机数添加到原始 X 和 Y 坐标,以便它获得不同的位置。 (参见下面的函数,如果 mult == True 则创建两个矩形对象)
def things_mult(thingx, thingy, thingw, thingh, color, mult, xopt, yopt, wopt, col2):
if mult == False:
pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw, thingh])
else:
pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw , thingh])
pygame.draw.rect(gameDisplay, col2, [thingx + xopt, thingy + yopt, thingw + wopt, thingh])
现在,我假设我只需要定义
thingy_new = thing_starty + thing_yopt
thingy_new = thingy_new + thing_speed* someconstant #(to make it faster or slower)
不幸的是,事情并非如此。
有人可以向我解释一下为什么我在某种程度上缺乏这个简单的逻辑吗?