#coding=utf-8 import pygame import random class gameSprite(pygame.sprite.Sprite): def __init__(self, image_name, speed=1): super().__init__() font = pygame.font.SysFont('Consolas',40) rtext = font.render(bytes(image_name, encoding='utf-8'), False, (random.randint(1, 254), random.randint(0, 255), random.randint(0, 255))) self.image = rtext self.speed = speed self.rect = self.image.get_rect() def update(self, *args): self.rect.y += self.speed def setSpeed(self, speed): self.speed = speed
#coding=utf-8 import pygame import random from plane_sprites import * pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN) listSprite = [] for nIndex in range(1000): spriteTemp = gameSprite(chr(random.randint(48, 122)),random.randint(5, 100)) spriteTemp.rect.x = random.randint(0, 1920) listSprite.append(spriteTemp) char_group = pygame.sprite.Group(listSprite) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: pygame.quit() for nIndex in range(1000): spriteTemp = listSprite[nIndex] if spriteTemp.rect.y > 1080 : spriteTemp.rect.x = random.randint(0, 1920) spriteTemp.rect.y = 0 spriteTemp.setSpeed(random.randint(5, 100)) screen.fill((0, 0, 0)) char_group.update() char_group.draw(screen) pygame.display.update() clock.tick(60)