所以我试图让我的车停留在屏幕的开头,同时将其他所有东西都向左移动,但我没有成功。我的车不需要玩家的任何输入,它总是以相同的速度运行。到目前为止,这是我的女仆 -
def update(dt):
global car_x
global CanIStart
space.step(0.02)
for shape in space.shapes:
if(shape.id == 1):
carRunNow = int(shape.body.position[0]) - car_x
car_x = int(shape.body.position[0])
CanIStart = True
if(CanIStart):
for shape in space.shapes:
if(shape.id == 15):
space.remove(shape)
shape.body.position = (int(shape.body.position.x)-carRunNow, int(shape.body.position.y))
space.add(shape)
这是我的道路代码-
def make_road(space, size, posOne, run):
if(run == 10):
part_shape = pymunk.Segment(space.static_body, (0, 150), (300, 150), 2)
part_shape.body.position = 0, 0 # Set the position of the body
part_shape.elasticity = 0.62
part_shape.friction = 0.62
part_shape.id = 15
space.add(part_shape)
make_road(space, size, (300, 150), run-1)
return
elif(run > 0):
modifier = random.randint(-80,80)
while(posOne[1] + modifier < 0):
modifier = random.randint(-80,80)
part_shape = pymunk.Segment(space.static_body, posOne, (posOne[0] + size, posOne[1] + modifier), 2)
part_shape.elasticity = 0.62
part_shape.friction = 0.62
part_shape.id = 15
space.add(part_shape)
print(posOne)
make_road(space, size, (posOne[0] + size, posOne[1] + modifier), run - 1)
return
else:
return
形状 id 15 是道路。这段代码产生了一些问题——第一个是汽车的车轮穿过马路,第二个是运动不是很顺畅。
谢谢您的帮助 :)