Advertisement
Guest User

Why the error

a guest
Aug 22nd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. import pygame
  2. pygame.init()
  3.  
  4. scrWidth = 640
  5. scrHeight = 480
  6. left = False
  7. right = False
  8. walkCount = 0
  9. x = 1
  10. y = 400
  11. width = 75
  12. height = 80
  13. vel = 5
  14. isJump = False
  15. jumpCount = 10
  16. clock = pygame.time.Clock()
  17.  
  18. window = pygame.display.set_mode((scrWidth,scrHeight))
  19. pygame.display.set_caption("Game")
  20. walkRight = [pygame.image.load('DefaultWalk1.png'),pygame.image.load('DefaultWalk2.png')]
  21. walkLeft = [pygame.image.load('Default2Walk1.png'),pygame.image.load('Default2Walk2.png')]
  22. bg = pygame.image.load("background.png")
  23. char = pygame.image.load ("Default.png")
  24.  
  25.  
  26.  
  27. def Draw():
  28.     global walkCount
  29.     window.blit(bg,(0,0))
  30.     if walkCount +1 > 20:
  31.        walkCount = 0
  32.     if left:
  33.         walkCount += 1
  34.         window.blit[walkLeft(x,y)]
  35.     elif right:
  36.         walkCount += 1
  37.         window.blit[walkRight(x,y)]
  38.     else:
  39.         window.blit(char,(x,y))
  40.     pygame.display.update()
  41.  
  42.  
  43. run = True
  44. while run:
  45.     clock.tick(20)
  46.    
  47.     for event in pygame.event.get():
  48.         if event.type == pygame.QUIT:
  49.             run = False
  50.     keys = pygame.key.get_pressed()
  51.     if keys [pygame.K_a]and x > vel:
  52.         x -= vel
  53.         left = True
  54.         right = False
  55.  
  56.     elif keys [pygame.K_d]and x < 600:
  57.         x+= vel
  58.         right = True
  59.         left = False
  60.     else:
  61.         right = False
  62.         left = False
  63.         walkCount = 0
  64.     if not(isJump):
  65.         if keys [pygame.K_SPACE]:
  66.            isJump = True
  67.            right = False
  68.            left = False
  69.            walkCount = 0
  70.     else:
  71.         if jumpCount >= -10:
  72.             neg = 1
  73.             if jumpCount < 0:
  74.                 neg = -1
  75.             y -= (jumpCount ** 2)* 0.5 * neg
  76.             jumpCount -= 1
  77.         else:
  78.             isJump = False
  79.             jumpCount = 10
  80.            
  81.     Draw()
  82. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement