如何让 Pygame Sprite 跳得更高更远?

How do I make my Pygame Sprite jump higher and farther?

我正在 Pygame 制作游戏,这是我要跳转的代码:

keys = pygame.key.get_pressed()
if isjump == False:
    #Up arrow key
    if keys[pygame.K_UP]:
        isjump = True
        v = 5
else:
    m = 1 if v >= 0 else -1
    F = m * (v**2)
    player.rect.y -= F

    v -= 1
    if v == -6:
        isjump = False

我想让它跳得更远更高。我该怎么做?

跳跃的高度取决于v。为v的初始值定义一个变量(jump_v)。使用大于 5 的值,以获得更高的跳跃:

jump_v = 7 # try different values

keys = pygame.key.get_pressed()
if isjump == False:
    #Up arrow key
    if keys[pygame.K_UP]:
        isjump = True    
        v = jump_v              # <--- jump_v 
else:
    m = 1 if v >= 0 else -1
    F = m * (v**2)
    player.rect.y -= F
    
    v -= 1
    if v < -jump_v:             # <--- jump_v 
        isjump = False