import pygame, random import math, sys class Dot(object): """Dot object""" def __init__(self): self.surf = pygame.Surface((25, 25)) self.surf.fill((255*random.random(), 255*random.random() ,255*random.random())) self.rect = self.surf.get_rect() class Game(object): def __init__(self): self.screen = pygame.display.set_mode((800, 600)) self.screen.fill((0, 255, 255)) self.game_over = False self.clock = pygame.time.Clock() #self.dot = pygame.image.load("up1.png").convert_alpha() self.dot_list = [Dot() for x in range(10)] for dot in self.dot_list: dot.rect.topleft = (775*random.random(), 575*random.random()) #self.dot.rect.bottomright = (345, 200) def process_input(self): for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.game_over = True if event.key == pygame.K_d: #self.dot_rect.move_ip(10, 0) for dot in self.dot_list: #dot.rect.move_ip(10,0) future_dot = dot.rect.move(10, 0) if self.screen.get_rect().contains(future_dot): dot.rect = future_dot else: dot.rect.right = 800 def update(self): pass def draw(self): self.screen.fill((0, 255, 255)) #self.screen.blit(self.dot, self.dot_rect) for dot in self.dot_list: self.screen.blit(dot.surf, dot.rect) pygame.init() g = Game() while not g.game_over: g.clock.tick(30) g.process_input() g.update() g.draw() pygame.display.flip() sys.exit()