1

I am making a game in Pygame and this is my code to jump:

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

I want it to jump farther and higher. How can I do it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pixeled
  • 316
  • 3
  • 10

1 Answers1

1

The height of the jump depends on v. Define a variabel (jump_v) for the initial value of v. Use a higher value than 5, for a higher jump:

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
Rabbid76
  • 202,892
  • 27
  • 131
  • 174