def make_chair_images(): """Create different colored variations of chairlift rider images.""" #colors for each potential rider in the original image original_colors = { "hat": [(0, 38, 255), (72, 0, 255), (255, 0, 220)], "hair": [(255, 189, 0), (76, 255, 0), (0, 255, 33)], "skin": [(191, 84, 33), (255, 178, 127), (104, 41, 0)], "shirt": [(1, 127, 15), (255, 0, 0), (255, 106, 0)], "pants": [(0, 148, 255), (0, 74, 127), (0, 127, 127)], "board": [(127, 0, 0), (127, 51, 0), (127, 106, 0)]} chairs = [] skin_tones = tools.strip_from_sheet(GFX["skin-palette"], (0, 0), (16, 16), 3) skin_colors = [img.get_at((0, 0)) for img in skin_tones] hair_tones = tools.strip_from_sheet(GFX["hair-palette"], (0, 0), (16, 16), 4) hair_colors = [hair.get_at((0, 0)) for hair in hair_tones] elf_tones = tools.strip_from_sheet(GFX["elf-palette"], (0, 0), (16, 16), 15) elf_colors = [elf.get_at((0, 0)) for elf in elf_tones] originals = [GFX["upchair{}".format(x)] for x in range(1, 4)] names = ("skin", "hair", "hat", "shirt", "pants", "board") for original in originals: for _ in range(10): swap_dict = {} for i in range(3): old_colors = [original_colors[name][i] for name in names] new_colors = [choice(skin_colors), choice(hair_colors)] new_colors.extend(sample(elf_colors, 4)) swap_dict.update(zip(old_colors, new_colors)) chairs.append(tools.color_swap(original, swap_dict)) return chairs
def load_images(sheet, strip_size, num_columns, num_rows, sprite_size, sprites_per_row): """Load sprite component images into a dict of dicts.""" d = {} strips = strip_from_sheet(sheet, (0, 0), strip_size, num_columns, num_rows) for i, strip in enumerate(strips): d[i] = {} imgs = strip_from_sheet(strip, (0, 0), sprite_size, sprites_per_row) for j, img in enumerate(imgs): d[i][j] = img return d
CURSOR1_IMAGE = GFX['mouse0'] CURSOR2_IMAGE = GFX['mouse3'] cursor_dict={ 'default' : pg.mouse.get_cursor(), 'hand' : cursor_from_image(CURSOR1_IMAGE,16,(8,4)), 'move' : cursor_from_image(CURSOR2_IMAGE,16,(8,4))} def change_cursor(name): pg.mouse.set_cursor(*cursor_dict[name]) return name #Sprite component image loading HATS = load_images(GFX["hats"], (816, 116), 1, 34, (68, 116), 12) SPECIAL_HATS = strip_from_sheet(GFX["special-hats"],(0,0),(68,116),5) HAIR = load_images(GFX["hair"], (1020, 116), 1, 5, (68, 116), 15) SKIN = strip_from_sheet(GFX["skin"], (0, 0), (68, 112), 12) EYES = strip_from_sheet(GFX["eyes"], (0, 0), (68, 112), 17) FACIAL_HAIR = load_images(GFX["facial-hair"], (1088, 116), 1, 5, (68, 116), 16) TOPS = load_images(GFX["tops"], (1496, 116), 1, 34, (68, 116), 22) BOTTOMS = load_images(GFX["bottoms"], (544, 116), 1, 34, (68, 116), 8) SHOES = strip_from_sheet(GFX["shoes"], (0, 0), (68, 114), 17, 2) MASKS = load_images(GFX["masks"], (408, 116), 1, 34, (68, 116), 6) SPECIAL_MASKS = strip_from_sheet(GFX["special-masks"], (0, 0), (68, 116), 12, 2) BUTTON_HELP = pg.Rect(60,420,80,40) BUTTON_RESET = pg.Rect(150,420,100,40) BUTTON_SHOW = pg.Rect(270,420,90,40) BUTTON_SAVE = pg.Rect(380,420,80,40) BUTTON_QUIT = pg.Rect(480,420,80,40)
d[i][j] = img return d SCREEN_SIZE = (1280, 720) ORIGINAL_CAPTION = "Sprite Builder" pg.mixer.pre_init(44100, -16, 1, 512) pg.init() os.environ['SDL_VIDEO_CENTERED'] = "TRUE" pg.display.set_caption(ORIGINAL_CAPTION) SCREEN = pg.display.set_mode(SCREEN_SIZE) SCREEN_RECT = SCREEN.get_rect() GFX = load_all_gfx(os.path.join("resources", "graphics")) #Sprite component image loading HATS = load_images(GFX["hats"], (816, 116), 1, 34, (68, 116), 12) SPECIAL_HATS = strip_from_sheet(GFX["special-hats"], (0, 0), (68, 116), 5) HAIR = load_images(GFX["hair"], (1020, 116), 1, 5, (68, 116), 15) SKIN = strip_from_sheet(GFX["skin"], (0, 0), (68, 112), 12) EYES = strip_from_sheet(GFX["eyes"], (0, 0), (68, 112), 17) FACIAL_HAIR = load_images(GFX["facial-hair"], (1088, 116), 1, 5, (68, 116), 16) TOPS = load_images(GFX["tops"], (1496, 116), 1, 34, (68, 116), 22) BOTTOMS = load_images(GFX["bottoms"], (544, 116), 1, 34, (68, 116), 8) SHOES = strip_from_sheet(GFX["shoes"], (0, 0), (68, 114), 17, 2) MASKS = load_images(GFX["masks"], (408, 116), 1, 34, (68, 116), 6) SPECIAL_MASKS = strip_from_sheet(GFX["special-masks"], (0, 0), (68, 116), 12, 2)