def main(): pygame.init() screen = pygame.display.set_mode(screen_size) all_sprites = pygame.sprite.RenderUpdates() stars = pygame.sprite.RenderUpdates() debris = pygame.sprite.RenderUpdates() Star.containers = [stars, all_sprites] Debris.containers = [debris, all_sprites] for z in range(1): make_star() # Star((200,200), 45, 0, size=200) counter = SpriteCounter() try: while not pygame.event.peek(pygame.QUIT): # pygame.event.poll() for event in pygame.event.get(pygame.KEYDOWN): if event.unicode == "s": make_star() pygame.event.clear() screen.fill((0, 0, 0)) # stars.update() # stars.draw(screen) # # debris.update() # debris.draw(screen) # if pygame.mouse.get_pressed()[0]: # mouse_pos = pygame.mouse.get_pos() # for star in stars: # dx = mouse_pos[0] - star.rect.centerx # dy = mouse_pos[1] - star.rect.centery # angle = math.degrees(math.atan2(dy, dx)) # dangle = angle - star.angle # star.set_angle(star.angle + dangle * 0.01) all_sprites.update() all_sprites.draw(screen) counter.update_counts({ "debris": len(debris), "stars": len(stars), "all": len(all_sprites) }) counter.update() screen.blit(counter.image, counter.rect) pygame.display.flip() except KeyboardInterrupt: pass print("Quitting...")
def main(): pygame.init() screen_rect = pygame.Rect((0, 0, 800, 600)) screen = pygame.display.set_mode(screen_rect.size) background = pygame.Surface(screen_rect.size) background.fill((0, 0, 0)) hills_back = pygame.image.load("hills_back.png").convert_alpha() hills_mid = pygame.image.load("hills_mid.png").convert_alpha() hills_front = pygame.image.load("hills_front.png").convert_alpha() counter = SpriteCounter() plane1 = Plane(hills_back, screen_rect) plane2 = Plane(hills_mid, screen_rect) plane3 = Plane(hills_front, screen_rect) autoscroll = True while 1: if pygame.event.peek(pygame.QUIT): pygame.quit() raise SystemExit() if pygame.key.get_pressed()[pygame.K_d] or autoscroll: plane1.set_offset(plane1.offset + 0.25) plane2.set_offset(plane2.offset + 0.5) plane3.set_offset(plane3.offset + 1) elif pygame.key.get_pressed()[pygame.K_a]: plane1.set_offset(plane1.offset - 0.25) plane2.set_offset(plane2.offset - 0.5) plane3.set_offset(plane3.offset - 1) # for event in pygame.event.get(pygame.KEYDOWN): # if event.unicode == "d": # plane1.set_offset(plane1.offset + 1) pygame.event.clear() screen.fill(pygame.Color("#7ec0ee")) for plane in [plane1, plane2, plane3]: # plane.clear(screen, background) plane.update() plane.draw(screen) counter.update() screen.blit(counter.image, counter.rect) pygame.display.flip()
def main(): pygame.init() screen = pygame.display.set_mode(screen_size) all_sprites = pygame.sprite.RenderUpdates() # stars = pygame.sprite.RenderUpdates() fworks = pygame.sprite.RenderUpdates() debris = pygame.sprite.RenderUpdates() # Star.containers = [stars, all_sprites] Emitter.containers = [fworks, all_sprites] Debris.containers = [debris, all_sprites] # Emitter((200,200), -90) counter = SpriteCounter() start_point = (0, 0) try: while not pygame.event.peek(pygame.QUIT): # pygame.event.poll() for event in pygame.event.get(pygame.KEYDOWN): if event.unicode == "s": make_star() for event in pygame.event.get(pygame.MOUSEBUTTONDOWN): if event.button == 1: start_point = event.pos for event in pygame.event.get(pygame.MOUSEBUTTONUP): if event.button == 1: dx = event.pos[0] - start_point[0] dy = event.pos[1] - start_point[1] max_speed = int(math.sqrt(dy**2 + dx**2)) * 10 Emitter((start_point), math.degrees(math.atan2(dy, dx)), emit_speed_range=(max_speed // 5, max_speed)) pygame.event.clear() screen.fill((0, 0, 0)) all_sprites.update() all_sprites.draw(screen) if pygame.mouse.get_pressed()[0]: pygame.draw.aaline(screen, (255, 0, 255), start_point, pygame.mouse.get_pos()) counter.update_counts({ "debris": len(debris), "stars": len(fworks), "all": len(all_sprites) }) counter.update() screen.blit(counter.image, counter.rect) pygame.display.flip() except KeyboardInterrupt: pass print("Quitting...")