fork download
  1. import pygame
  2.  
  3. pygame.init()
  4.  
  5. win = pygame.display.set_mode((500, 500))
  6.  
  7. x = 50
  8. y = 250
  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(50)
  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:
  28. x -= vel
  29.  
  30. if keys[pygame.K_RIGHT] and x < 500 - vel - width:
  31. x += vel
  32.  
  33. if not (isJump):
  34. if keys[pygame.K_SPACE]:
  35. isJump = True
  36. else:
  37. if jumpCount >= -10:
  38. y -= (jumpCount * abs(jumpCount)) * 0.5
  39. jumpCount -= 1
  40. else:
  41. jumpCount = 10
  42. isJump = False
  43.  
  44. win.fill((0, 0, 0))
  45. pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
  46. pygame.display.update()
  47.  
  48. pygame.quit()
Runtime error #stdin #stdout #stderr 0.01s 7152KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 1, in <module>
ImportError: No module named pygame