Take the 2-minute tour ×

What would be the best way to cause the spriteimg jump. I want to have the sprite glide up and then back down when K_UP is pressed. What would be the best approach to this?

while running:
    spriteimg = plumberright

    screen.blit(spriteimg,(x1, y1))
    keys = pygame.key.get_pressed()
    for event in pygame.event.get():
         if event.type == pygame.QUIT:
             running = False

    if keys[pygame.K_UP]:
              y1 -= 2
    elif keys[pygame.K_RIGHT]:
              x1 += 2
    elif keys[pygame.K_LEFT]:
               x1 -= 2

share|improve this question

2 Answers 2

up vote 4 down vote accepted

I suggest you model the movement of your character as a velocity vector. The keys accelerate in a certain direction. Gravity and friction (and collisions) bring the player to stop.

I found this here (it's not python but the ideas are the same), maybe it helps: http://www.rodedev.com/tutorials/gamephysics/

share|improve this answer
You could also save the sequence of jump movements as a list and iterate through the movements in the list. Not as flexible, but another option. –  Joel Cornett Apr 1 '12 at 18:29

My cohort covered this during our tutorial at PyCon this year:


You'll want to start at 31:00 if you don't want to listen me to talk about game design :)

share|improve this answer

Your Answer


