Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import pygame
  2. pygame.init()
  3.  
  4. win = pygame.display.set_mode((500,500))
  5. pygame.display.set_caption("First Game")
  6.  
  7. x = 50
  8. y = 50
  9. width = 40
  10. height = 60
  11. vel = 5
  12.  
  13. isJump = False
  14. jumpCount = 10
  15.  
  16. run = True
  17.  
  18. while run:
  19. pygame.time.delay(100)
  20.  
  21. for event in pygame.event.get():
  22. if event.type == pygame.QUIT:
  23. run = False
  24.  
  25. keys = pygame.key.get_pressed()
  26.  
  27. if keys[pygame.K_LEFT] and x > vel: # Making sure the top left position of our character is greater than our vel so we never move off the screen.
  28. x -= vel
  29.  
  30. if keys[pygame.K_RIGHT] and x < 500 - vel - width: # Making sure the top right corner of our character is less than the screen width - its width
  31. x += vel
  32.  
  33. if not(isJump): # Checks is user is not jumping
  34. if keys[pygame.K_UP] and y > vel: # Same principles apply for the y coordinate
  35. y -= vel
  36.  
  37. if keys[pygame.K_DOWN] and y < 500 - height - vel:
  38. y += vel
  39.  
  40. if keys[pygame.K_SPACE]:
  41. isJump = True
  42. else:
  43. # This is what will happen if we are jumping
  44.  
  45.  
  46. win.fill((0,0,0))
  47. pygame.draw.rect(win, (255,0,0), (x, y, width, height))
  48. pygame.display.update()
  49.  
  50. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement