def read_animation_def(filename, name, frame_klass=AnimationFrame): reader = ConfigObj(filename) animation = Animation(name) path = os.path.split(filename)[0] range_regex = re.compile(".*?(\d*)\s*-\s*(\d*)") # stores information that affects all frames in the animation animation_dict = {} try: animation_dict.update(reader['general']) except KeyError: pass for section, values in reader.items(): d = {} # update for the "globals" d.update(animation_dict) d.update(values) if section[:5].lower() == "frame": start = None end = None try: # frames can define a range of frames start, end = range_regex.match(section).groups() start = int(start) end = int(end) except AttributeError: pass # load a single frame if start == None: d['name'] = section[6:] frame = load_frame(path, d, frame_klass) animation.add_frame(frame) # load a range of frames else: prefix, suffix = get_frame_image_filename_prefix_suffix(d) for x in range(start, end + 1): # mangle the dict to reflect the right image_file d['file'] = prefix + str(x) + suffix d['name'] = str(x) frame = load_frame(path, d, frame_klass) animation.add_frame(frame) if section.lower() == "animation": # loop entire animation when held animation.hold_loop = handle_bool(d, 'hold loop') print animation, animation.hold_loop # play while held [stop when let go] animation.hold_play = handle_bool(d, 'hold play') print animation, animation.hold_play return animation
def read_animation_def(filename, name, frame_klass=AnimationFrame): reader = ConfigObj(filename) animation = Animation(name) path = os.path.split(filename)[0] range_regex = re.compile(".*?(\d*)\s*-\s*(\d*)") # stores information that affects all frames in the animation animation_dict = {} try: animation_dict.update(reader['general']) except KeyError: pass for section, values in reader.items(): d = {} # update for the "globals" d.update(animation_dict) d.update(values) if section[:5].lower() == "frame": start = None end = None try: # frames can define a range of frames start, end = range_regex.match(section).groups() start = int(start) end = int(end) except AttributeError: pass # load a single frame if start == None: d['name'] = section[6:] frame = load_frame(path, d, frame_klass) animation.add_frame(frame) # load a range of frames else: prefix, suffix = get_frame_image_filename_prefix_suffix(d) for x in range(start, end + 1): # mangle the dict to reflect the right image_file d['file'] = prefix + str(x) + suffix d['name'] = str(x) frame = load_frame(path, d, frame_klass) animation.add_frame(frame) if section.lower() == "animation": # loop entire animation when held animation.hold_loop = handle_bool(d, 'hold loop') # play while held [stop when let go] animation.hold_play = handle_bool(d, 'hold play') return animation
def make_banner(self): banner_x = 322 / 2 - (self.banner_image[1].width / 2) banner = SimpleAvatar() banner.position = (banner_x, 80) bf = AnimationFrame() bf.image, bf.rect = self.banner_image bf.ttl = 1500 ani = Animation() ani.add_frame(bf) banner.add_animation(ani) self.world.add(banner) banner.callback = (self.close_banner, []) return banner
def make_banner(self): banner_x = 322 / 2 - (self.banner_image[1].width / 2) banner = SimpleAvatar() banner.position = (banner_x, 80) bf = AnimationFrame() bf.image, bf.rect = self.banner_image bf.ttl = 1500 ani = Animation() ani.add_frame(bf) banner.add_animation(ani) self.world.add(banner) banner.callback = (self.close_banner, []) return banner
def __init__(self, speed, starting_position, texture, window_rectangle, collision_manager): self.window_rectangle = window_rectangle self.starting_position = starting_position self.speed = speed self.collision_manager = collision_manager self.direction = 1 if speed > 0 else -1 # Plane fly_anim = Animation() fly_anim.texture = texture fly_anim.add_frame(sf.Rectangle((0, 0), (88, 73))) fly_anim.add_frame(sf.Rectangle((88, 0), (88, 73))) fly_anim.add_frame(sf.Rectangle((176, 0), (88, 73))) fly_anim.add_frame(sf.Rectangle((88, 0), (88, 73))) self.plane = AnimatedSprite(sf.seconds(0.2), False, True) self.plane.play(fly_anim) self.plane.size = sf.Vector2(self.plane.global_bounds.width / 2, self.plane.global_bounds.height / 2) self.plane.origin = self.plane.global_bounds.width / 2.0, self.plane.global_bounds.height / 2.0 self.plane.scale((self.direction * 0.5, 0.5)) self.plane.position = self.starting_position self.plane_speed = sf.Vector2(speed, 0) self.is_dead = False self.jump_time = None self.plane_jumped = False self.immortal = None self.bullets = set() SoundManager.play_player_appear_sound()
def __init__(self, speed, starting_position, texture, window_rectangle, collision_manager): self.window_rectangle = window_rectangle self.starting_position = starting_position self.speed = speed self.collision_manager = collision_manager self.direction = 1 if speed > 0 else -1 # Plane fly_anim = Animation() fly_anim.texture = texture fly_anim.add_frame(sf.Rectangle((0, 0), (88, 73))) fly_anim.add_frame(sf.Rectangle((88, 0), (88, 73))) fly_anim.add_frame(sf.Rectangle((176, 0), (88, 73))) fly_anim.add_frame(sf.Rectangle((88, 0), (88, 73))) self.plane = AnimatedSprite(sf.seconds(0.2), False, True) self.plane.play(fly_anim) self.plane.size = sf.Vector2(self.plane.global_bounds.width / 2, self.plane.global_bounds.height / 2) self.plane.origin = self.plane.global_bounds.width / 2.0, self.plane.global_bounds.height / 2.0 self.plane.scale((self.direction * 0.5, 0.5)) self.plane.position = self.starting_position self.plane_speed = sf.Vector2(speed, 0) self.is_dead = False self.jump_time = None self.plane_jumped = False self.immortal = None self.bullets = set() SoundManager.play_player_appear_sound()
class AnimationSubView(SubView): def __init__(self, parent, rect_coords): super().__init__(parent, rect_coords, 'Animation View') self.animation = None self.is_playing = False self.loop = False def handle_event(self, event): super().handle_event(event) def tick(self): super().tick() if self.animation and self.is_playing: if self.animation.is_complete() and not self.loop: self.is_playing = False else: self.animation.step() def play_animation(self): if self.animation and not self.is_playing: self.is_playing = True self.animation.restart() def draw(self, surface): super().draw(surface) if self.animation: self.animation.draw(surface, self.view_rect.centerx, self.view_rect.centery) def reset(self): super().reset() self.animation = None self.play = False def add_frame(self, frame): if not self.animation: self.animation = Animation(self.spritesheet) self.animation.add_frame(frame) def remove_frame(self, index): if self.animation: frame = self.animation.remove_frame(index) self.animation.restart() if not frame: self.animation = None return frame
def define_animations(self, row): animation = Animation("up") animation.speed = 10 animation.add_frame(self.spritesheet.get_image(0, row, 32, 32)) animation.add_frame(self.spritesheet.get_image(1, row, 32, 32)) self.animate.add(animation) animation = Animation("down") animation.speed = 10 animation.add_frame(self.spritesheet.get_image(2, row, 32, 32)) animation.add_frame(self.spritesheet.get_image(3, row, 32, 32)) self.animate.add(animation) animation = Animation("left") animation.speed = 10 animation.add_frame(self.spritesheet.get_image(4, row, 32, 32)) animation.add_frame(self.spritesheet.get_image(5, row, 32, 32)) self.animate.add(animation) animation = Animation("right") animation.speed = 10 animation.add_frame(self.spritesheet.get_image(6, row, 32, 32)) animation.add_frame(self.spritesheet.get_image(7, row, 32, 32)) self.animate.add(animation) animation = Animation("freight") animation.speed = 10 for i in range(25): animation.add_frame(self.spritesheet.get_image(0, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(1, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(2, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(3, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(0, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(1, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(2, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(3, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(0, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(1, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(2, 6, 32, 32)) animation.add_frame(self.spritesheet.get_image(3, 6, 32, 32)) self.animate.add(animation) animation = Animation("spawnup") animation.speed = 10 animation.add_frame(self.spritesheet.get_image(4, 6, 32, 32)) self.animate.add(animation) animation = Animation("spawndown") animation.speed = 10 animation.add_frame(self.spritesheet.get_image(5, 6, 32, 32)) self.animate.add(animation) animation = Animation("spawnleft") animation.speed = 10 animation.add_frame(self.spritesheet.get_image(6, 6, 32, 32)) self.animate.add(animation) animation = Animation("spawnright") animation.speed = 10 animation.add_frame(self.spritesheet.get_image(7, 6, 32, 32)) self.animate.add(animation)
def define_animations(self): anim = Animation("left") anim.speed = 20 anim.add_frame(self.spritesheet.get_image(4, 0, 32, 32)) anim.add_frame(self.spritesheet.get_image(0, 0, 32, 32)) anim.add_frame(self.spritesheet.get_image(0, 1, 32, 32)) self.animate.add(anim) anim = Animation("right") anim.speed = 20 anim.add_frame(self.spritesheet.get_image(4, 0, 32, 32)) anim.add_frame(self.spritesheet.get_image(1, 0, 32, 32)) anim.add_frame(self.spritesheet.get_image(1, 1, 32, 32)) self.animate.add(anim) anim = Animation("down") anim.speed = 20 anim.add_frame(self.spritesheet.get_image(4, 0, 32, 32)) anim.add_frame(self.spritesheet.get_image(2, 0, 32, 32)) anim.add_frame(self.spritesheet.get_image(2, 1, 32, 32)) self.animate.add(anim) anim = Animation("up") anim.speed = 20 anim.add_frame(self.spritesheet.get_image(4, 0, 32, 32)) anim.add_frame(self.spritesheet.get_image(3, 0, 32, 32)) anim.add_frame(self.spritesheet.get_image(3, 1, 32, 32)) self.animate.add(anim) anim = Animation("death") anim.speed = 10 anim.add_frame(self.spritesheet.get_image(0, 7, 32, 32)) anim.add_frame(self.spritesheet.get_image(1, 7, 32, 32)) anim.add_frame(self.spritesheet.get_image(2, 7, 32, 32)) anim.add_frame(self.spritesheet.get_image(3, 7, 32, 32)) anim.add_frame(self.spritesheet.get_image(4, 7, 32, 32)) anim.add_frame(self.spritesheet.get_image(5, 7, 32, 32)) anim.add_frame(self.spritesheet.get_image(6, 7, 32, 32)) anim.add_frame(self.spritesheet.get_image(7, 7, 32, 32)) anim.add_frame(self.spritesheet.get_image(8, 7, 32, 32)) anim.add_frame(self.spritesheet.get_image(9, 7, 32, 32)) anim.add_frame(self.spritesheet.get_image(10, 7, 32, 32)) self.animate.add(anim)
def define_animations(self) -> None: """ This method sets up the animation. """ anim = Animation("ping") anim.speed = 20 anim.add_frame(self.sprite.get_sprite(4, 0, 32, 32)) anim.add_frame(self.sprite.get_sprite(0, 0, 32, 32)) anim.add_frame(self.sprite.get_sprite(0, 1, 32, 32)) self.animations["left"] = anim anim = Animation("ping") anim.speed = 20 anim.add_frame(self.sprite.get_sprite(4, 0, 32, 32)) anim.add_frame(self.sprite.get_sprite(1, 0, 32, 32)) anim.add_frame(self.sprite.get_sprite(1, 1, 32, 32)) self.animations["right"] = anim anim = Animation("ping") anim.speed = 20 anim.add_frame(self.sprite.get_sprite(4, 0, 32, 32)) anim.add_frame(self.sprite.get_sprite(2, 0, 32, 32)) anim.add_frame(self.sprite.get_sprite(2, 1, 32, 32)) self.animations["down"] = anim anim = Animation("ping") anim.speed = 20 anim.add_frame(self.sprite.get_sprite(4, 0, 32, 32)) anim.add_frame(self.sprite.get_sprite(3, 0, 32, 32)) anim.add_frame(self.sprite.get_sprite(3, 1, 32, 32)) self.animations["up"] = anim anim = Animation("once") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(0, 7, 32, 32)) anim.add_frame(self.sprite.get_sprite(1, 7, 32, 32)) anim.add_frame(self.sprite.get_sprite(2, 7, 32, 32)) anim.add_frame(self.sprite.get_sprite(3, 7, 32, 32)) anim.add_frame(self.sprite.get_sprite(4, 7, 32, 32)) anim.add_frame(self.sprite.get_sprite(5, 7, 32, 32)) anim.add_frame(self.sprite.get_sprite(6, 7, 32, 32)) anim.add_frame(self.sprite.get_sprite(7, 7, 32, 32)) anim.add_frame(self.sprite.get_sprite(8, 7, 32, 32)) anim.add_frame(self.sprite.get_sprite(9, 7, 32, 32)) anim.add_frame(self.sprite.get_sprite(10, 7, 32, 32)) self.animations["death"] = anim anim = Animation("static") anim.add_frame(self.sprite.get_sprite(4, 0, 32, 32)) self.animations["idle"] = anim
def define_animations(self, row: int) -> None: """ This method sets up the animation. """ anim = Animation("loop") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(0, row, 32, 32)) anim.add_frame(self.sprite.get_sprite(1, row, 32, 32)) self.animations["up"] = anim anim = Animation("loop") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(2, row, 32, 32)) anim.add_frame(self.sprite.get_sprite(3, row, 32, 32)) self.animations["down"] = anim anim = Animation("loop") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(4, row, 32, 32)) anim.add_frame(self.sprite.get_sprite(5, row, 32, 32)) self.animations["left"] = anim anim = Animation("loop") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(6, row, 32, 32)) anim.add_frame(self.sprite.get_sprite(7, row, 32, 32)) self.animations["right"] = anim anim = Animation("loop") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(0, 6, 32, 32)) anim.add_frame(self.sprite.get_sprite(1, 6, 32, 32)) self.animations["fear"] = anim anim = Animation("loop") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(2, 6, 32, 32)) anim.add_frame(self.sprite.get_sprite(3, 6, 32, 32)) self.animations["flash"] = anim anim = Animation("static") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(4, 6, 32, 32)) self.animations["spawnup"] = anim anim = Animation("static") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(5, 6, 32, 32)) self.animations["spawndown"] = anim anim = Animation("static") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(6, 6, 32, 32)) self.animations["spawnleft"] = anim anim = Animation("static") anim.speed = 10 anim.add_frame(self.sprite.get_sprite(7, 6, 32, 32)) self.animations["spawnright"] = anim