def init(): animated_effects["jump"] = util.SheetAnimation( util.get_sheet("{}{}.png".format(PARTICLE_FOLDER, "jump")), (0, 0, 32, 32), 8, False).set_fpi(4) animated_effects["hit"] = util.SheetAnimation( util.get_sheet("{}{}.png".format(PARTICLE_FOLDER, "hit")), (0, 0, 8, 8), 5, False).set_fpi(4) particle_effects["bullet"] = util.load_alpha_image("{}\\gun\\bullet\\1.png".format(util.SPRITES_FOLDER))
def init(): animated_effects["jump"] = util.SheetAnimation( util.get_sheet("{}{}.png".format(PARTICLE_FOLDER, "jump")), (0, 0, 32, 32), 8, False).set_fpi(4) animated_effects["hit"] = util.SheetAnimation( util.get_sheet("{}{}.png".format(PARTICLE_FOLDER, "hit")), (0, 0, 8, 8), 5, False).set_fpi(4) particle_effects["bullet"] = util.load_alpha_image( "{}\\gun\\bullet\\1.png".format(util.SPRITES_FOLDER))
def create_image(self, file, rect): """Create, set and return an image for the sprite. :param file: string file containing the image :param rect: rect of the location in file :return: pygame.Image """ self.image = util.get_sheet(file).get_image(rect) _, _, self.rect[2], self.rect[3] = pygame.Rect(self.image.get_rect()) self.rect.size = self.image.get_rect().width - 1, self.image.get_rect().height - 1 return self.image
def create_animation(self, file, rect, frames=8, loop=True): """Create, set and return an animation for the sprite. :param file: string file containing the sheet of animation frames :param rect: rect of the first sprite :param frames: int amount of frames in the animation :param loop: bool whether to loop or not :return: SheetAnimation object """ try: sheet = util.get_sheet(file) self.strips = util.SheetAnimation(sheet, rect, frames, loop) self.image = self.strips.next() self.rect.size = self.image.get_rect().width - 1, self.image.get_rect().height - 1 return self.strips except: print("Failed to load animation at {0} in {1}".format(rect, file)) traceback.print_exc()
def load_map(name): file = util.read("{}{}_info.txt".format(util.MAPS_FOLDER, name)) tiles = {} for line in file: if line.startswith("#"): continue # Define keyword # Defines a map char to a tile coordinate on the sprite sheet, # and determines whether to collide or not def_match = re.match(DEF_PATTERN, line) if def_match: clip = def_match.group(1) != "^" char = def_match.group(2) sheet = def_match.group(3) sheet_x = int(def_match.group(4)) sheet_y = int(def_match.group(5)) rect = pygame.Rect(sheet_x * TILE_SIZE, sheet_y * TILE_SIZE, TILE_SIZE, TILE_SIZE) tiles[char] = util.get_sheet( "tile\\{}.png".format(sheet)).get_image(rect) for i in range(3): text_map = util.read("{}{}_map_layer{}.txt".format( util.MAPS_FOLDER, name, i)) map_surface = pygame.Surface( (len(text_map[0]) * TILE_SIZE, len(text_map) * TILE_SIZE)) map_surface.fill((0, 0, 255)) map_surface.set_colorkey((0, 0, 255), pygame.RLEACCEL) x = y = 0 for line in text_map: for char in line: if char != " ": map_surface.blit(tiles[char], (x, y)) x += TILE_SIZE y += TILE_SIZE x = 0 map.append(Map(i == 1, map_surface))
def load_map(name): file = util.read("{}{}_info.txt".format(util.MAPS_FOLDER, name)) tiles = {} for line in file: if line.startswith("#"): continue # Define keyword # Defines a map char to a tile coordinate on the sprite sheet, # and determines whether to collide or not def_match = re.match(DEF_PATTERN, line) if def_match: clip = def_match.group(1) != "^" char = def_match.group(2) sheet = def_match.group(3) sheet_x = int(def_match.group(4)) sheet_y = int(def_match.group(5)) rect = pygame.Rect(sheet_x * TILE_SIZE, sheet_y * TILE_SIZE, TILE_SIZE, TILE_SIZE) tiles[char] = util.get_sheet("tile\\{}.png".format(sheet)).get_image(rect) for i in range(3): text_map = util.read("{}{}_map_layer{}.txt".format(util.MAPS_FOLDER, name, i)) map_surface = pygame.Surface((len(text_map[0]) * TILE_SIZE, len(text_map) * TILE_SIZE)) map_surface.fill((0, 0, 255)) map_surface.set_colorkey((0, 0, 255), pygame.RLEACCEL) x = y = 0 for line in text_map: for char in line: if char != " ": map_surface.blit(tiles[char], (x, y)) x += TILE_SIZE y += TILE_SIZE x = 0 map.append(Map(i == 1, map_surface))
def __init__(self, position, font): Sprite.__init__(self, position) self.font = font template = util.get_sheet("other/gui.png").get_image((32, 0, 12, 12)) self.background = util.GUIBackground(template) self.image = None