Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- Red = (255,0,0)
- Black = (0,0,0)
- Blue = (0,255,0)
- HEIGHT = 900
- WIDTH = 500
- pygame.init()
- window = pygame.display.set_mode ((WIDTH, HEIGHT))
- class Platform(pygame.sprite.Sprite):
- def __init__(self, y, sizex = 100):
- super().__init__()
- self.size_x = sizex
- self.size_y = 15
- self.image = pygame.Surface((self.size_x,self.size_y))
- self.image.fill(Blue)
- self.rect = self.image.get_rect()
- self.rect.left = (random.randrange(0, WIDTH-self.size_x+1))
- self.rect.centery = y
- run = True
- clock = pygame.time.Clock()
- elements = pygame.sprite.Group()
- platforms = pygame.sprite.Group()
- for x in range(5):
- p = Platform((x+1)*150)
- elements.add(p)
- platforms.add(p)
- base = Platform(HEIGHT-20, WIDTH)
- elements.add(base)
- platforms.add(base)
- score = 0
- while run:
- window.fill(Black)
- clock.tick(60)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- if len(platforms) < 6:
- p = Platform(-5)
- platforms.add(p)
- elements.add(p)
- elements.update()
- elements.draw(window)
- pygame.display.update()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement