Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import pygame
  2. pygame.init()
  3.  
  4. win = pygame.display.set_mode((500, 500))
  5.  
  6. pygame.display.set_caption("amaan dheere")
  7. screenwidht = 500
  8. x = 50
  9. y = 425
  10. width = 40
  11. vel = 5
  12. height = 6
  13.  
  14. isJump = False
  15. jumpCount = 10
  16.  
  17. run = True
  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. keys = pygame.key.get_pressed()
  25. if keys[pygame.K_LEFT] and x > vel:
  26. x -= vel
  27. if keys[pygame.K_RIGHT] and x < 500 - width - vel:
  28. x += vel
  29. if not(isJump):
  30. if keys[pygame.K_UP] and y > vel:
  31. y -= vel
  32. if keys[pygame.K_DOWN] and y < 500 - height - vel:
  33. y += vel
  34. if keys[pygame.K_SPACE]:
  35. isJump = True
  36. else:
  37. if jumpCount >= -10:
  38. neg = 1
  39. if jumpCount < 0:
  40. neg = -1
  41. y -= (jumpCount ** 2) * 0.5 * neg
  42. jumpCount -= 1
  43. else:
  44. isjump = False
  45. jumpCount = 10
  46.  
  47. win.fill((0, 0, 0))
  48.  
  49. pygame.draw.rect(win, (255,0,0),(x, y, width, height))
  50. pygame.display.update()
  51. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement