Pygame中跳跃
问题描述:
我想在pygame中制作一个像几何冲刺一样的游戏。除了跳跃部分之外,我已经完成了一切。我需要它,这样当角色在一个方块上时,他可以跳起来,但是不能在半空跳跃。现在我拥有它,这样角色就可以跳到地面上,但只要角色碰到一组块上的跳跃,他就会开始上下跳动,并且无法在滑块上跳跃。任何人都可以帮忙吗?Pygame中跳跃
onblock = False
for i in squares_list:
if player_rect.bottom <= 560 and player_rect.colliderect(i):
onblock = True
player_rect.bottom = i.top + 1
if player_rect.collidepoint((i.topleft[0], i.topleft[1]+1)):
print ('Game Over')
if event.type == KEYDOWN: # if space is pressed the character jumps
if event.key == K_SPACE:
print(onblock)
if onblock or player_rect.bottom == screen.get_rect().bottom : # prevents double jumps
vel_y = -20 # Makes the character jump up
player_rect.y -= 1
if onblock:
gravity = 0
vel_y = 0
current_angle = 0
else:
gravity = 1
vel_y += gravity
onblock = False
在跳跃时可能会将onblock设置为True?如'player_rect.y - = 1'后面的行 –