Advertisement
ZEdKasat

JumperGamePlatforms

Sep 25th, 2021
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import pygame
  2. import random
  3.  
  4. Red = (255,0,0)
  5. Black = (0,0,0)
  6. Blue = (0,255,0)
  7.  
  8. HEIGHT = 900
  9. WIDTH = 500
  10.  
  11. pygame.init()
  12. window = pygame.display.set_mode ((WIDTH, HEIGHT))
  13.  
  14. class Platform(pygame.sprite.Sprite):
  15. def __init__(self, y, sizex = 100):
  16. super().__init__()
  17. self.size_x = sizex
  18. self.size_y = 15
  19. self.image = pygame.Surface((self.size_x,self.size_y))
  20. self.image.fill(Blue)
  21. self.rect = self.image.get_rect()
  22. self.rect.left = (random.randrange(0, WIDTH-self.size_x+1))
  23. self.rect.centery = y
  24.  
  25. run = True
  26. clock = pygame.time.Clock()
  27. elements = pygame.sprite.Group()
  28. platforms = pygame.sprite.Group()
  29.  
  30. for x in range(5):
  31. p = Platform((x+1)*150)
  32. elements.add(p)
  33. platforms.add(p)
  34.  
  35. base = Platform(HEIGHT-20, WIDTH)
  36. elements.add(base)
  37. platforms.add(base)
  38.  
  39. score = 0
  40. while run:
  41. window.fill(Black)
  42. clock.tick(60)
  43. for event in pygame.event.get():
  44. if event.type == pygame.QUIT:
  45. run = False
  46.  
  47. if len(platforms) < 6:
  48. p = Platform(-5)
  49. platforms.add(p)
  50. elements.add(p)
  51.  
  52.  
  53. elements.update()
  54. elements.draw(window)
  55. pygame.display.update()
  56. pygame.quit()
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement