我正试图在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