Advertisement
metalx1000

PyGame - Very Basic Jumper

Jan 31st, 2012
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #created by Kris Occhipinti (AKA Metalx1000)
  3. #http://filmsbykris.com
  4. #Oct. 16th 2010
  5. #GPLv3  http://www.gnu.org/licenses/gpl-3.0.html
  6.  
  7. import pygame, sys
  8. from pygame.locals import *
  9.  
  10. pygame.init()
  11.  
  12. screen = pygame.display.set_mode((600,400))
  13.  
  14. image = pygame.image.load("tux.png")
  15. tux = pygame.transform.scale(image, (64,64))
  16.  
  17. clock = pygame.time.Clock()
  18.  
  19. gravity = 10
  20. x = -100
  21. y = 300
  22. yr = 0
  23. yl = 0
  24. speed = 4
  25. force = 0
  26. jmp = 0
  27.  
  28. def jump():
  29.     global x,y,force
  30.     if force > 0:
  31.        x -= force
  32.        force -= 1
  33.  
  34. def move_right():
  35.     global y,speed
  36.     y += speed
  37.  
  38. def move_left():
  39.     global y,speed
  40.     y -= speed
  41.  
  42. while 1:
  43.     clock.tick(60)
  44.     x+=gravity
  45.     screen.fill((0,0,0))
  46.     screen.blit(tux,(y,x))
  47.     pygame.display.update()
  48.     if x > 400-64:
  49.        x = 400-64
  50.  
  51.     for event in pygame.event.get():
  52.        if event.type == pygame.QUIT:
  53.            sys.exit()
  54.        elif event.type == KEYDOWN and event.key == K_ESCAPE:
  55.            sys.exit()
  56.        elif event.type == KEYDOWN and event.key == K_SPACE:
  57.            force = 25
  58.        elif event.type == KEYDOWN and event.key == K_RIGHT:
  59.            yr = 1
  60.        elif event.type == KEYUP and event.key == K_RIGHT:
  61.            yr = 0
  62.        elif event.type == KEYDOWN and event.key == K_LEFT:
  63.            yl = 1
  64.        elif event.type == KEYUP and event.key == K_LEFT:
  65.            yl = 0
  66.  
  67.     jump()
  68.     if yr == 1:
  69.        move_right()
  70.     if yl == 1:
  71.        move_left()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement