Пример #1
0
    def fromFile(self, group_path, filename, per_pixel_alpha=False, dest=None, area=None, layer=0, *groups):
        """ load a sprite using a resources cache:
            the surfaces are shared and unique in memory
        """
        if filename in self._resources.keys():
            surf = self._resources[filename]
            # surf.convert()
        else:
            surf = loadImage(filename)
            surf = surf.convert_alpha() if per_pixel_alpha else surf.convert()
            self._resources[filename] = surf

        return self.fromSurface(group_path, surf, dest, area, layer, *groups)
Пример #2
0
def loadAnims(charName):
    "Gets all animations for the given character."
    animations = {}
    for anim in ANIMS:
        images = {}
        path = os.path.join(CHAR_PATH, charName, anim)
        tree = os.walk(path)
        tree.__next__()
        for dirpath, dirnames, filenames in tree:
            direction = os.path.basename(dirpath)
            loadedImgs = [loadImage(os.path.join(path, direction, image))
                          for image in sortImages(filenames)]
            images[os.path.basename(dirpath)] = loadedImgs
        animations[anim] = images
    return animations
Пример #3
0
 def __init__(self, name, position):
     pygame.sprite.Sprite.__init__(self)
     self.position = position
     self.health = 100
     self.direction = None
     self.speed = 300/1000
     self.obstructed = False
     baseimg = os.path.join(CHAR_PATH, name, INIT_IMG)
     anims = loadAnims(name)
     self.image = loadImage(baseimg)
     self.mask = pygame.mask.from_surface(self.image)
     self.rect = self.image.get_rect()
     # Load images for animation.
     self.walk = {}
     self.walk[K_RIGHT] = itertools.cycle(anims['Walk']['Right'])
     self.walk[K_LEFT] = itertools.cycle(anims['Walk']['Left'])
     self.walk[K_DOWN] = itertools.cycle(anims['Walk']['Down'])
     self.walk[K_UP] = itertools.cycle(anims['Walk']['Up'])
     self.walk[None] = itertools.cycle([self.image])
     self.images = self.walk[None]
     self.imageclock = 0  # Tracks how long an image is on the screen.
     self.imagerate = IMAGE_RATE  # Images per second.