title: Calculate gravity/jump in pygame
body: <p>What is the best way to calculate gravity in pygame? I basically just need it so when the player pushes "Up", the character jumps. Here is my code so far (just a white screen with a red block that moves around)</p>
  
  <pre><code>import pygame
  import random
  
  # Define colors
  black    = (   0,   0,   0)
  white    = ( 255, 255, 255)
  green    = (   0, 255,   0)
  red      = ( 255,   0,   0)
  
  #Classes
  class Player(pygame.sprite.Sprite):
      def __init__(self, color, width, height):
          pygame.sprite.Sprite.__init__(self) 
          self.image = pygame.Surface([width, height])
          self.image.fill(color)
          self.rect = self.image.get_rect()
  
      def move(self, x_change, y_change):
          self.rect.x += x_change
          self.rect.y +=  y_change
  
  
  #Lists
  all_sprites_list = pygame.sprite.Group()
  
  #Spawn player
  player = Player(red,16,16) 
  all_sprites_list.add(player)
  player.rect.x = 0
  player.rect.y = 484
  
  #Initalize
  pygame.init()
  #Set the width and height of the screen [width,height]
  screen_height = 700
  screen_width = 500
  size=[screen_height,screen_width]
  screen=pygame.display.set_mode(size)
  #Name on top tab
  pygame.display.set_caption("My Game")
  
  #DONT CHANGE
  done = False
  clock=pygame.time.Clock()
  
  #MAIN LOOP
  while done == False:
      for event in pygame.event.get(): # User did something
          if event.type == pygame.QUIT: # If user clicked close
              done = True # Quit
  
          if event.type == pygame.KEYUP:
                      # If it is an arrow key, reset vector back to zero
                      if event.key == pygame.K_LEFT:
                          None      
  
      keyDown = pygame.key.get_pressed()
      if keyDown[pygame.K_RIGHT]:
          player.move(3, 0)   
      if keyDown[pygame.K_LEFT]:
          player.move(-3, 0)        
      if keyDown[pygame.K_DOWN]:
          player.move(0, 3)                        
      if keyDown[pygame.K_UP]:
          player.move(0,-3)
  
      #If player hits side of screen, do this
      if player.rect.x &lt; 0:
          player.rect.x = 0
      if player.rect.x &gt; 684:
          player.rect.x = 684
      if player.rect.y &lt; 0:
          player.rect.y = 0
      if player.rect.y &gt; 484:
          player.rect.y = 484    
  
  
      #Clear screen
      screen.fill(white)
  
      #Drawing
      all_sprites_list.draw(screen)
  
      #FPS Lock
      clock.tick(60)
  
      #Update screen
      pygame.display.flip()
  
  # Close the window and quit.
  pygame.quit()
  </code></pre>