所以我试着让我的车停在屏幕的开头,同时把其他东西移到左边,但我没有成功。 我的车不需要玩家的任何输入,它总是以相同的速度行驶。 这是我目前所做的-
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是道路。 这个代码产生了一些问题-第一个问题是车轮穿过道路,第二个问题是移动不是很平稳。你知道吗
感谢您的帮助:)
目前没有回答
相关问题 更多 >
编程相关推荐