1

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

我想让它跳得越来越高怎么办?

4

1 回答 1

1

跳跃的高度取决于vjump_v为 的初始值定义一个变量 ( ) 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
于 2021-06-24T17:47:54.867 回答