Advertisement
mcneisvesten

Easy Python Game

Aug 15th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. import pygame
  2.  
  3. #Display resolution
  4. pygame.init()
  5. win = pygame.display.set_mode((500, 500))
  6.  
  7. #Game name
  8. pygame.display.set_caption('BAD GUY')
  9.  
  10. #Player
  11. x = 250
  12. y = 475
  13. width = 20
  14. height = 25
  15. speed = 20
  16.  
  17. #To close the game
  18. run = True
  19. while run:
  20.     pygame.time.delay(100)
  21.  
  22. for event in pygame.event.get():
  23.     if event.type == pygame.QUIT:
  24.         run = False
  25.  
  26. #Move rigth/left   
  27. keys = pygame.key.get_pressed()
  28. if keys[pygame.K_LEFT] and x > 5:
  29.     x -= speed
  30.    
  31. if keys[pygame.K_RIGHT] and x < 500 -width - 5:
  32.     x += speed
  33.    
  34. #Jump
  35. if not(isJump):
  36.     if keys[pygame.K_UP] and y > 5:
  37.         y -= speed
  38.    
  39. if keys[pygame.K_DOWN] and y < 500 -width - 5:
  40.     y += speed
  41.    
  42. if keys[pygame.K_SPACE]:
  43.     isJump = True
  44.  
  45. else:
  46.     if jumpCount >= 10:
  47.         if jumpCount < 0:
  48.             y += (jumpCount ** 2) / 2
  49.             y -= (jumpCount ** 2) / 2
  50.             jumpCount -= 1
  51.     else:
  52.         isJump = False
  53.         jumpCount = 10
  54.  
  55. #Background and hero color
  56. win.fill((0,0,0))
  57.  
  58. pygame.draw.rect(win, (0,0,255), (x, y, width, height))
  59.  
  60. pygame.display.update()
  61.  
  62. #Exit game
  63. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement