def load_animation(cls, resource_class, name): """ Loads animation :param resource_class: :param name: :return: """ with open(cls.get_path(resource_class, name)) as file_data: data = json.load(file_data) image_path = cls.get_path(resource_class, data["image"]) if "rects" in data: rects = list(map(tuple, data["rects"])) images = pyganim.getImagesFromSpriteSheet(image_path, rects=rects) else: rows = data["rows"] cols = data["cols"] images = pyganim.getImagesFromSpriteSheet(image_path, rows=rows, cols=cols, rects=[]) speed = [data.get('speed', 100)] frames = list(zip(images, speed * len(images))) animation = pyganim.PygAnimation(frames) animation.loop = data.get('loop', True) return animation
def specialAttack(self): specialAttack = pyganim.getImagesFromSpriteSheet( self.rData, rects=self.specialAttackRect) specialAttackFrame = list( zip(specialAttack, [100] * len(specialAttack))) specialAttackAnim = pyganim.PygAnimation(specialAttackFrame) return specialAttackAnim
def get_dirt(width: int, height: int) -> pygame.Surface: tiles = [ (140, 45, 44, 44), (128, 35, 36, 33), (158, 35, 36, 33), (129, 63, 36, 35), (157, 63, 36, 35), (127, 46, 35, 35), (147, 35, 33, 33), (160, 51, 33, 33), (145, 65, 33, 33) ] dirt_tile = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, 'foliage4.png'), rects=tiles) for tile in dirt_tile: tile.convert_alpha() dirt = pygame.Surface((width, height), pygame.SRCALPHA, 32).convert_alpha() for i in range(0, width, 33): for j in range(0, height, 33): dirt.blit(dirt_tile[5], (0, i)) dirt.blit(dirt_tile[0], (i, j)) dirt.blit(dirt_tile[7], (width-33, j)) dirt.blit(dirt_tile[6], (i, 0)) dirt.blit(dirt_tile[8], (i, height-30)) dirt.blit(dirt_tile[1], (0,0)) dirt.blit(dirt_tile[2], (width-33, 0)) dirt.blit(dirt_tile[3], (0, height-33)) dirt.blit(dirt_tile[4], (width-33, height-33)) return dirt
def __init__(self, size, bufferzone): self.squaresize = size self.rect = pygame.Rect(120, 120, size, size) self.images = pyganim.getImagesFromSpriteSheet( "assets/images/test player1.png", rects=self.rects) self.rescale_sprites(size) self.bufferzone = bufferzone
def get_garden(width, height): tiles = [ (3, 227, 31, 28), (32, 255, 31, 28), (65, 255, 35, 33), (66, 259, 62, 64), (8, 269, 53, 52), (132, 288, 59, 35), ] garden_tile = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, 'foliage1.png'), rects=tiles) for tile in garden_tile: tile.convert_alpha() garden = pygame.Surface( (width, height), pygame.SRCALPHA, 32).convert_alpha() # for top edge for i in range(0, width, 60): garden.blit(random.choice(garden_tile), (i+random.randint(0, 5), 0+random.randint(0, 10))) garden.blit(random.choice(garden_tile), (i+random.randint(0, 5), 0+random.randint(0, 10))) for j in range(0, height, 60): garden.blit(random.choice(garden_tile), (0+random.randint(0, 10), j+random.randint(0, 5))) garden.blit(random.choice(garden_tile), (width-60+random.randint(0, 10), j+random.randint(0, 5))) return garden
def build_animations(self): images = pyganim.getImagesFromSpriteSheet( resources.get('examples/placeholder_player_ani.png'), rows=4, cols=3, rects=[]) self.animations = { 'idle_up': [(images[0], 100)], 'idle_down': [(images[3], 100)], 'idle_left': [(images[6], 100)], 'idle_right': [(images[9], 100)], 'walk_up': zip([images[x] for x in [1, 0, 2, 0]], [200] * 4), 'walk_down': zip([images[x] for x in [4, 3, 5, 3]], [200] * 4), 'walk_left': zip([images[x] for x in [7, 6, 8, 6]], [200] * 4), 'walk_right': zip([images[x] for x in [10, 9, 11, 9]], [200] * 4), } self.idle_transitions = { 'walk_up': 'idle_up', 'walk_down': 'idle_down', 'walk_left': 'idle_left', 'walk_right': 'idle_right', } for k, v in self.animations.items(): self.animations[k] = pyganim.PygAnimation(list(v)) self.animate('idle_up')
def __init__(self, resolution): super().__init__(resolution) self.bg = pygame.image.load("images/road bg.png") self.texts = [ Text("Drive the delivery van to the exit", (255, 255, 255), self._center_text) ] self.van = Van() self.shot_original = pyganim.PygAnimation([ ("images/wifi signals.png", 200), ]) self.shots = [] self.barrier = pyganim.PygAnimation([ ("images/car.png", 200), ]) self.barriers = [ #Collidable(self.barrier, [20, 20]) ] rects = [ [64 * 1, 0, 64, 64], [64 * 2, 0, 64, 64], [64 * 3, 0, 64, 64], [64 * 0, 0, 64, 64], ] exit = pyganim.getImagesFromSpriteSheet("images/door2.png", rects=rects) frames = list(zip(exit, [1000, 400, 400, 400])) exit_anim = pyganim.PygAnimation(frames) self.exit = Collidable(exit_anim, [700, 100]) self.reset()
def __init__(self, resolution): super().__init__(resolution) self.texts = [ Text("CROWD SURFING", (255, 255, 255), self._center_text) ] self.bg = pygame.image.load( "images/2013_Woodstock_144_crowd_surfing.jpg") self.crowd = pyganim.PygAnimation([("images/button1.png", 10), ("images/button 2.png", 10)]) self.player = pyganim.PygAnimation([ ("images/surfer.png", 10), ]) rects = [ [64 * 1, 0, 64, 64], [64 * 2, 0, 64, 64], [64 * 3, 0, 64, 64], [64 * 0, 0, 64, 64], ] exit = pyganim.getImagesFromSpriteSheet("images/door2.png", rects=rects) frames = list(zip(exit, [1000, 400, 400, 400])) self.exit = pyganim.PygAnimation(frames) self.exit.scale2x() self.crowd.play() self.player.play() self.exit.play() self.reset()
def get_demon_fire(): tiles = [ (0, 0, 100, 100), (0, 100, 100, 100), (0, 200, 100, 100), (0, 300, 100, 100), (0, 400, 100, 100), (0, 500, 100, 100), (0, 600, 100, 100), (0, 700, 100, 100), (100, 0, 100, 100), (100, 100, 100, 100), (100, 200, 100, 100), (100, 300, 100, 100), (100, 400, 100, 100), (100, 500, 100, 100), (100, 600, 100, 100), (100, 700, 100, 100), (200, 0, 100, 100), (200, 100, 100, 100), (200, 200, 100, 100), (200, 300, 100, 100), (200, 400, 100, 100), ] demon_tiles = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, "sunburst.png"), rects=tiles) frames = list(zip(demon_tiles, [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100])) animdemon = pyganim.PygAnimation(frames) animdemon.play() return animdemon
def load_animation(self, file, rows, cols): images = pyganim.getImagesFromSpriteSheet(os.path.join(self.assets_dir, file), rows=rows, cols=cols, rects=[]) # TODO: customizable delay frames = list(zip(images, [100] * len(images))) anim = pyganim.PygAnimation(frames) anim.play() return anim
def __init__(self, source_file, source_grid, size, pos, frame_start, frame_finish, loop=False, rotation=0, shadow=False, frame_speed=80): image_list = pyganim.getImagesFromSpriteSheet( source_file, cols=source_grid[0], rows=source_grid[1])[frame_start:frame_finish] frame_count = frame_finish - frame_start self.animation = pyganim.PygAnimation( list(zip(image_list, [frame_speed] * frame_count)), loop) self.animation.scale(size) self.animation.rotate(rotation) self.animation.convert_alpha() self.animation.play() self.position = pos self._rotation = rotation self._size = size self._shadow = shadow
def __init__(self, img, position=(16, 16), width=32, height=32, num=3, st=0): self.img_width = width self.img_height = height anim_types = ['front', 'left', 'right', 'back'] self.anim_objs = {} self.standing = {} i = 0 for anim_type in anim_types: rects = [(num * width, i * height, width, height) for num in range(num)] all_images = pyganim.getImagesFromSpriteSheet(img, rects=rects) self.standing[anim_type] = all_images[st] frames = list(zip(all_images, [100] * len(all_images))) self.anim_objs[anim_type] = pyganim.PygAnimation(frames) i += 1 self.move_conductor = pyganim.PygConductor(self.anim_objs) self.pos_x, self.pos_y = position self.pos_x -= self.standing['front'].get_width() / 2 self.pos_y -= self.standing['front'].get_height() / 2
def lspecialAttack(self): lspecialAttack = pyganim.getImagesFromSpriteSheet( self.lData, rects=self.lspecialAttackRect) lspecialAttackFrame = list( zip(lspecialAttack, [100] * len(lspecialAttack))) lspecialAttackAnim = pyganim.PygAnimation(lspecialAttackFrame) return lspecialAttackAnim
def __init__(self, screen): super(SpawnAnimation, self).__init__() self.screen = screen images = pyganim.getImagesFromSpriteSheet('res/spawn_anim.bmp', rects=[(0, 0, 64, 64), (64, 0, 64, 64), (128, 0, 64, 64), (192, 0, 64, 64), (256, 0, 64, 64), (320, 0, 64, 64), (384, 0, 64, 64), (448, 0, 64, 64), (512, 0, 64, 64), (0, 64, 64, 64), (64, 64, 64, 64), (128, 64, 64, 64), (192, 64, 64, 64), (256, 64, 64, 64), (320, 64, 64, 64), (384, 64, 64, 64), (448, 64, 64, 64), (512, 64, 64, 64)]) frames = list(zip(images, [64] * len(images))) self.animationObj = pyganim.PygAnimation(frames) self.animationObj.play() self.pt = (0, 0)
def get_animation_sheet(file, rows=1, cols=1): images = pyganim.getImagesFromSpriteSheet(file, rows=rows, cols=cols, rects=[[TILE_SIZE] * 2 + [47, 60]]) frames = list(zip(images, [1] + ([100] * len(images)))) return pyganim.PygAnimation(frames)
def get_walls(width): wall_tile = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, 'walls2.png'), rects=[(64, 0, 64, 64)])[0].convert() wall = pygame.Surface((width, 64), pygame.SRCALPHA, 32).convert() for i in range(0, width, 64): wall.blit(wall_tile, (i, 0)) return wall
def get_walls_edge(height): wall_tile = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, 'walls2.png'), rects=[(64, 0, 12, 64)])[0].convert() wall = pygame.Surface((12, height), pygame.SRCALPHA, 32).convert() for i in range(0, height, 64): wall.blit(wall_tile, (0, i)) return wall
def get_npc5(direction=None): tiles = [ (98, 0, 30, 32), # forward (130, 0, 30, 32), (161, 0, 30, 32), (98, 34, 30, 32), # left (130, 34, 30, 32), (161, 34, 30, 32), (98, 65, 30, 32), # right (130, 65, 30, 32), (161, 65, 30, 32), (98, 98, 30, 32), # right (130, 98, 30, 32), (161, 98, 30, 32), ] char_tiles = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, "chars2.png"), rects=tiles) character = pygame.Surface( (30, 32), pygame.SRCALPHA, 32).convert_alpha() if direction == 'forward': dir_tiles = [ char_tiles[0], char_tiles[1], char_tiles[0], char_tiles[2], ] elif direction == 'backward': dir_tiles = [ char_tiles[9], char_tiles[10], char_tiles[9], char_tiles[11], ] elif direction == 'right': dir_tiles = [ char_tiles[6], char_tiles[7], char_tiles[6], char_tiles[8], ] elif direction == 'left': dir_tiles = [ char_tiles[3], char_tiles[4], char_tiles[3], char_tiles[5], ] else: dir_tiles = [ char_tiles[0] ] frames = list(zip(dir_tiles, [150, 150, 150, 150])) animChar = pyganim.PygAnimation(frames) animChar.play() return animChar
def get_npc_pink_robes(direction=None): tiles = [ (1, 128, 30, 32), # forward (33, 128, 30, 32), (66, 128, 30, 32), (1, 160, 30, 32), # left (33, 160, 30, 32), (66, 160, 30, 32), (1, 192, 30, 32), # right (33, 192, 30, 32), (66, 192, 30, 32), (0, 224, 30, 32), # backward (33, 224, 30, 32), (66, 224, 30, 32) ] char_tiles = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, "pink_chars.png"), rects=tiles) character = pygame.Surface( (30, 32), pygame.SRCALPHA, 32).convert_alpha() if direction == 'forward': dir_tiles = [ char_tiles[0], char_tiles[1], char_tiles[0], char_tiles[2], ] elif direction == 'backward': dir_tiles = [ char_tiles[9], char_tiles[10], char_tiles[9], char_tiles[11], ] elif direction == 'right': dir_tiles = [ char_tiles[6], char_tiles[7], char_tiles[6], char_tiles[8], ] elif direction == 'left': dir_tiles = [ char_tiles[3], char_tiles[4], char_tiles[3], char_tiles[5], ] else: dir_tiles = [ char_tiles[0] ] frames = list(zip(dir_tiles, [150, 150, 150, 150])) animChar = pyganim.PygAnimation(frames) animChar.play() return animChar
def get_animation_sheet(file, rows=1, cols=1): images = pyganim.getImagesFromSpriteSheet( file, rows=rows, cols=cols, rects=[[TILE_SIZE] * 2 + [SPRITE_DIMENSIONS_WIDTH, SPRITE_DIMENSIONS_HEIGHT]]) frames = list(zip(images, [1] + ([100] * len(images)))) return pyganim.PygAnimation(frames)
def get_npc4(direction=None): tiles = [ (99, 2, 27, 31), (131, 2, 27, 31), (163, 2, 27, 31), (99, 34, 27, 31), (131, 34, 27, 31), (163, 34, 27, 31), (99, 66, 27, 31), (131, 66, 27, 31), (163, 66, 27, 31), (99, 98, 27, 31), (131, 98, 27, 31), (163, 98, 27, 31) ] char_tiles = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, "chars6.png"), rects=tiles) character = pygame.Surface( (30, 32), pygame.SRCALPHA, 32).convert_alpha() if direction == 'forward': dir_tiles = [ char_tiles[0], char_tiles[1], char_tiles[2] ] elif direction == 'backward': dir_tiles = [ char_tiles[9], char_tiles[10], char_tiles[11] ] elif direction == 'right': dir_tiles = [ char_tiles[6], char_tiles[7], char_tiles[8] ] elif direction == 'left': dir_tiles = [ char_tiles[3], char_tiles[4], char_tiles[5] ] else: dir_tiles = [ char_tiles[0] ] frames = list(zip(dir_tiles, [100, 100, 100])) animChar = pyganim.PygAnimation(frames) animChar.play() return animChar
def get_npc_cat(direction=None): tiles = [ (435, 12, 42, 42), (483, 12, 42, 42), (530, 12, 42, 42), (435, 63, 42, 42), (483, 63, 42, 42), (530, 63, 42, 42), (435, 110, 42, 42), (483, 110, 42, 42), (530, 110, 42, 42), (435, 156, 42, 42), (483, 156, 42, 42), (530, 156, 42, 42), ] char_tiles = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, "cats1.png"), rects=tiles) character = pygame.Surface( (30, 32), pygame.SRCALPHA, 32).convert_alpha() if direction == 'forward': dir_tiles = [ char_tiles[0], char_tiles[1], char_tiles[2] ] elif direction == 'backward': dir_tiles = [ char_tiles[9], char_tiles[10], char_tiles[11] ] elif direction == 'right': dir_tiles = [ char_tiles[6], char_tiles[7], char_tiles[8] ] elif direction == 'left': dir_tiles = [ char_tiles[3], char_tiles[4], char_tiles[5] ] else: dir_tiles = [ char_tiles[0] ] frames = list(zip(dir_tiles, [100, 100, 100])) animChar = pyganim.PygAnimation(frames) animChar.play() return animChar
def makeAnim(entity, i, pathName): anim = [] if entity.type == EntityType.PLAYER: images = pyganim.getImagesFromSpriteSheet('assets/' + pathName + '.png', rects=beamSprites) frames = list(zip(images, [100] * len(images))) animation = pyganim.PygAnimation(frames) animation.play() anim.append(animation) return (anim)
def __init__(self, rect): super(Switch, self).__init__() self.rect = rect images = pyganim.getImagesFromSpriteSheet( resources.get("assets/stonepad.png"), rows=1, cols=2, rects=[]) self._sound = pygame.mixer.Sound("assets/step_concrete.wav") self.image = images[0] self.released_image = images[0] self.pressed_image = images[1] self.active = False
def load_sprite_sheet(name, rows, cols, colorkey=None): filename = os.path.join(data_dir, name) all_images = pyganim.getImagesFromSpriteSheet(filename, rows=rows, cols=cols) for image in all_images: image = image.convert() if colorkey is not None: if colorkey is -1: colorkey = image.get_at((0, 0)) image.set_colorkey(colorkey, pygame.RLEACCEL) return all_images
def buildBG(self,sprite): i = pyganim.getImagesFromSpriteSheet( sprite, rows = 10, cols = 10, rects = [(0,0,3200,2400)] ) i = [ pygame.transform.scale(x, (self.window_x, self.window_y)) for x in i ] bg_index = zip([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 ]) bg_anim = [(i[t[0]],t[1]) for t in list(bg_index)] self.bg = pyganim.PygAnimation(bg_anim)
def buildBG(self, sprite): i = pyganim.getImagesFromSpriteSheet(sprite, rows=10, cols=10, rects=[(0, 0, 3200, 2400)]) i = [ pygame.transform.scale(x, (self.window_x, self.window_y)) for x in i ] bg_index = zip([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) bg_anim = [(i[t[0]], t[1]) for t in list(bg_index)] self.bg = pyganim.PygAnimation(bg_anim)
def __init__(self, *args, **kwargs): images = pyganim.getImagesFromSpriteSheet(self.TANK_IMAGE, rows=1, cols=4, rects=[]) frames = list(zip(images[:3], [200, 200, 200])) self.animObj = pyganim.PygAnimation(frames) self.animObj.play() kwargs['image'] = frames[0][0] kwargs['life'] = 20 kwargs['speed'] = Tank.SPEED super(Tank, self).__init__(*args, **kwargs)
def get_demon(): tiles = [ (290, 129, 30, 34), (322, 129, 30, 34), (355, 129, 30, 34) ] demon_tiles = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, "chars6.png"), rects=tiles) frames = list(zip(demon_tiles, [100, 100, 100])) animdemon = pyganim.PygAnimation(frames) animdemon.play() return animdemon
def __init__(self, world): images = pyganim.getImagesFromSpriteSheet(SPARK_IMAGE_FILENAME, rows=1, cols=2, rects=[]) frames = list(zip(images, [100, 100])) self.animObj = pyganim.PygAnimation(frames) self.animObj.play() sprite = pygame.image.load(SPARK_IMAGE_FILENAME).convert_alpha() super(Spark, self).__init__(world, 'spark', sprite) self.loading = 0 self.shoot = False
def __init__(self, rect): super(Keystone, self).__init__() self._floor_listeners = set() self.rect = rect self.images = pyganim.getImagesFromSpriteSheet(resources.get('examples/keystone.png'), rows=1, cols=5, rects=[]) self.animation = pyganim.PygAnimation(zip([self.images[x] for x in [0, 1, 2, 3, 4, 3, 2, 1]], [200] * 8)) self.animate() self.image = self.images[0] self.won = False self.font = pygame.font.SysFont('Courier', 48, True, True)
def AddSprite(self, name, rows, cols, begin, end): """Make a sprite (animated or not) from a sheet Output: obj - a sprite""" fullname = join('res', 'sprite', 'effect', name) perso = pyganim.getImagesFromSpriteSheet(fullname,cols=cols,rows=rows)[begin:end] if end > begin+1: frames = list(zip(perso, [100]*(end-begin))) obj = pyganim.PygAnimation(frames) obj.play() else: obj = perso[0] return obj
def get_floor(width: int, height: int) -> pygame.Surface: # load the floor tile from the sprite sheet floor_tile = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, 'floors1.png'), rects=[(0, 0, 16, 16)])[0].convert() # create a blank surface to tile floor = pygame.Surface((width, height), pygame.SRCALPHA, 32).convert() # tile the floor for i in range(0, height, 16): for j in range(0, width, 16): floor.blit(floor_tile, (i, j)) return floor
def get_fire(): tiles = [ (0, 20, 64, 64), (64, 20, 64, 64), (128, 20, 64, 64) ] fire_tiles = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, "fire3.png"), rects=tiles) frames = list(zip(fire_tiles, [100, 100, 100])) animFire = pyganim.PygAnimation(frames) animFire.play() return animFire
def get_grass(width: int, height: int) -> pygame.Surface: # load the grass tile from the sprite sheet grass_tile = pyganim.getImagesFromSpriteSheet( os.path.join(settings.SPRITES_DIR, 'foliage4.png'), rects=[(269, 333, 16, 16)])[0].convert() # create a blank surface to paint with grass grass = pygame.Surface((width, height), pygame.SRCALPHA, 32).convert() # paint grass tiles onto surface for i in range(0, width, 16): for j in range(0, height, 16): grass.blit(grass_tile, (i, j)) return grass
def buildMoves(self): # Pull in the imagesheet i = pyganim.getImagesFromSpriteSheet("sprites/full_image/navinew.png", rows = 7, cols = 7, rects = [(0,0,490,490)]) if self.player_two: # Player 2 faces the opposite direction i = [ pygame.transform.flip(x, True, False) for x in i ] # Pique Player 2's color for x in i: #x.fill((0, 0, 0, 100), None, pygame.BLEND_RGBA_MULT) # Blanks out all values (looks like a shadow) x.fill((00,0,60) + (0,), None, pygame.BLEND_RGBA_ADD) # Blends that color into image # Resize images to make sense in environment. All players should be some fraction of height of screen i = [ pygame.transform.scale(x, (int(self.window_y/self.char_y_fraction), int(self.window_x/self.char_y_fraction))) for x in i ] # This is the hard part, unfortunately. # Generate the animations for all projectiles. p = { 'p1' : { 'anim' : zip([ 26, 33, 40, 47, 48 ], [ 200, 200, 200, 200, 200 ]), 'velocity' : 10 } } for k, v in p.iteritems(): v['anim'] = [(i[t[0]],t[1]) for t in list(v['anim'])] p[k]['anim'] = pyganim.PygAnimation(v['anim']) self.projectiles = p # This part matches each attack to a sequence of frames and a time for each. move_list = { 'fight_start' : zip([ 49, 9, 16, 23, 30 ], [ 200, 200, 200, 200, 200 ]), 'stand' : zip([ 30, 32 ], [ 900, 100 ]), 'attack_damage' : zip([ 37, 44, 3, 10 ], [ 300, 200, 200, 300 ]), 'attack_defended' : zip([ 37, 44, 3, 10, 2 ], [ 300, 200, 200, 600, 200 ]), 'attack_both_damage' : zip([ 37, 44, 3, 10, 23 ], [ 200, 100, 100, 400, 200 ]), 'attack_while_comboed' : zip([ 49, 9, 16, 23, 30, 2 ], [ 200, 200, 200, 200, 200, 300 ]), 'defends' : zip([ 24, 45, 4, 5, 12, 19, 12, 19, 12, 19, 12, 19, 12, 5, 4 ], [ 76, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66 ]), 'defends_blocks' : zip([ 24, 45, 4, 5, 12, 19, 12, 19, 12, 19, 12, 19, 12, 5, 4 ], [ 76, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66 ]), 'defends_while_comboed' : zip([ 24, 45, 4, 5, 12, 19, 12, 19, 12, 19, 12, 19, 2 ], [ 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 100 ]), 'combo_initiate' : zip([ 31, 38, 45, 4 ], [ 200, 200, 200, 400 ]), 'combo_init_and_damaged' : zip([ 31, 38, 45, 4, 2 ], [ 200, 200, 200, 200, 200 ]), 'combo_init_while_comboed' : zip([ 31, 38, 45, 4, 2 ], [ 200, 200, 200, 200, 200 ]), 'execute_combo' : zip([ 4, 5, 43, 36, 29, 22, 15, 8, 38, 31 ], [ 75, 75, 75, 75, 75, 75, 100, 100, 100, 100 ]), 'execute_combo_while_defended' : zip([ 4, 5, 43, 36, 29, 22, 15, 8, 38, 31, 2 ], [ 75, 75, 75, 75, 75, 75, 75, 125, 100, 100, 100 ]), 'failed_combo' : zip([ 4, 5, 4, 5, 4, 17, 4, 17, 30, 23 ], [ 50, 50, 50, 50, 50, 50, 100, 200, 300, 100 ]), 'failed_combo_and_damaged' : zip([ 4, 5, 4, 5, 4, 17, 4, 17, 30, 23, 2 ], [ 50, 50, 50, 50, 50, 50, 100, 100, 200, 100, 200 ]), 'failed_combo_while_comboed' : zip([ 4, 5, 4, 5, 4, 17, 4, 17, 30, 23, 2 ], [ 50, 50, 50, 50, 50, 50, 100, 100, 200, 100, 200 ]), 'interrupted' : zip([ 30, 23 ], [ 100, 100 ]), 'KO' : zip([ 30, 23, 16, 9, 49, 9, 49 ], [ 200, 200, 200, 200, 200, 100, 100 ]) } for k, v in move_list.iteritems(): # Here I take that first row and actually make them the image objects v = [(i[t[0]],t[1]) for t in list(v)] #wol if k in [ "stand", "interrupted", "KO" ]: self.moves[k] = pyganim.PygAnimation(v) else: self.moves[k] = pyganim.PygAnimation(v, loop=False)
# set up the window windowSurface = pygame.display.set_mode((320, 240), 0, 32) pygame.display.set_caption('Sprite Sheet Demo') # create the animation objects rects = [( 0, 154, 94, 77), ( 94, 154, 94, 77), (188, 154, 94, 77), (282, 154, 94, 77), (376, 154, 94, 77), (470, 154, 94, 77), (564, 154, 94, 77), (658, 154, 94, 77), (752, 154, 94, 77),] allImages = pyganim.getImagesFromSpriteSheet('terrex_0.png', rects=rects) frames = list(zip(allImages, [100] * len(allImages))) dinoAnim = pyganim.PygAnimation(frames) dinoAnim.play() # there is also a pause() and stop() method mainClock = pygame.time.Clock() BGCOLOR = (100, 50, 50) while True: windowSurface.fill(BGCOLOR) for event in pygame.event.get(): if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): pygame.quit() sys.exit() dinoAnim.blit(windowSurface, (100, 50))