def __init__(self, *args): _Enemy.__init__(self, *args) self.anims = { "walk": tools.Anim(self.frames[:2], 7), "hit": tools.Anim(self.frames[2:4], 20), "die": None } # Set die in specific class declaration. self.image = self.get_anim().get_next_frame(pg.time.get_ticks())
def __init__(self, *args): _Enemy.__init__(self, *args) self.ai = LinearAI(self) walk = { "front": tools.Anim(self.frames[:2], 7), "back": tools.Anim(self.frames[2:4], 7), "left": tools.Anim([ pg.transform.flip(self.frames[4], 1, 0), pg.transform.flip(self.frames[5], 1, 0) ], 7), "right": tools.Anim(self.frames[4:6], 7) } hit = { "front": tools.Anim(self.frames[6:8], 20), "back": tools.Anim(self.frames[8:10], 20), "left": tools.Anim([ pg.transform.flip(self.frames[10], 1, 0), pg.transform.flip(self.frames[11], 1, 0) ], 20), "right": tools.Anim(self.frames[10:12], 20) } self.anims = {"walk": walk, "hit": hit, "die": None} self.image = self.get_anim().get_next_frame(pg.time.get_ticks())
def __init__(self, *args): _BasicFrontFrames.__init__(self, "cabbage", ENEMY_SHEET, *args) die_frames = self.frames[4:] + [self.frames[-1]] self.anims["die"] = tools.Anim(die_frames, 5, 1) self.health = 3 self.attack = 4 self.drops = ["heart"]
def make_death_animation(self): """Return a tools.Anim object with the player's death sequence.""" sheet = prepare.GFX["enemies"]["enemysheet"] cell_coords = [(3, 1), (4, 1), (5, 1), (6, 1), (6, 1)] args = (sheet, cell_coords, prepare.CELL_SIZE) death_cells = tools.strip_coords_from_sheet(*args) return tools.Anim(death_cells, 3, loops=1)
def __init__(self, *args): _BasicFrontFrames.__init__(self, "turtle", ENEMY_SHEET, *args) die_frames = self.frames[2:5] + [self.frames[5]] * 2 self.anims["die"] = tools.Anim(die_frames, 5, 1) self.health = 12 self.attack = 6 self.drops = [None]
def __init__(self, *args): _FourDirFrames.__init__(self, "red_oni", ENEMY_SHEET_2, *args) die_frames = self.frames[12:] self.anims["die"] = tools.Anim(die_frames, 10, 1) self.health = 10 self.attack = 15 self.drops = ["diamond", None, None]
def __init__(self, *args): _FourDirFrames.__init__(self, "frog", ENEMY_SHEET, *args) die_frames = self.frames[12:] self.anims["die"] = tools.Anim(die_frames, 5, 1) self.health = 6 self.attack = 6 self.drops = ["heart", None, None]
def __init__(self, *args): _FourDirFrames.__init__(self, "zombie", ENEMY_SHEET, *args) self.ai = LinearAI(self) die_frames = self.frames[12:] + self.frames[16:] self.anims["die"] = tools.Anim(die_frames, 5, 1) self.health = 10 self.attack = 8 self.drops = ["key"]
def __init__(self, *args): _BasicFrontFrames.__init__(self, "crab", ENEMY_SHEET, *args) die_frames = self.frames[4:7] + self.frames[7:] * 2 self.anims["die"] = tools.Anim(die_frames, 5, 1) self.ai = CrabWalk(self) self.health = 6 self.attack = 6 self.drops = [None, None, "diamond"]
def __init__(self, *args): _Enemy.__init__(self, "skeleton", ENEMY_SHEET, *args) self.ai = LinearAI(self) self.state = "spawn" walk = { "front": tools.Anim( [self.frames[3], pg.transform.flip(self.frames[3], 1, 0)], 7), "back": tools.Anim( [self.frames[2], pg.transform.flip(self.frames[2], 1, 0)], 7), "left": tools.Anim(self.frames[:2], 7), "right": tools.Anim([ pg.transform.flip(self.frames[0], 1, 0), pg.transform.flip(self.frames[1], 1, 0) ], 7) } hit = { "front": tools.Anim(self.frames[10:], 20), "back": tools.Anim(self.frames[8:10], 20), "left": tools.Anim(self.frames[6:8], 20), "right": tools.Anim([ pg.transform.flip(self.frames[6], 1, 0), pg.transform.flip(self.frames[7], 1, 0) ], 20) } die_frames = self.frames[3:5] + [self.frames[5]] * 2 self.anims = { "walk": walk, "hit": hit, "die": tools.Anim(die_frames, 5, 1), "spawn": tools.Anim(die_frames[::-1], 3, 1) } self.image = self.get_anim().get_next_frame(pg.time.get_ticks()) self.health = 6 self.attack = 6 self.drops = ["heart", None]
def __init__(self, *args): _BasicFrontFrames.__init__(self, "spider", ENEMY_SHEET, *args) die_frames = self.frames[4:6] + self.frames[6:] * 2 self.anims["die"] = tools.Anim(die_frames, 5, 1) self.ai = CrabWalk(self) self.health = 6 self.attack = 6 self.drops = ["diamond", None] self.shooting = pg.sprite.Group()
def __init__(self, *args): _Enemy.__init__(self, "daruma", ENEMY_SHEET_2, *args) self.anim_directions = ["front", "back"] self.anim_direction = random.choice(self.anim_directions) self.ai = BasicAI(self) walk = { "front": tools.Anim(self.frames[:2], 7), "back": tools.Anim(self.frames[4:6], 7) } hit = { "front": tools.Anim(self.frames[2:4], 20), "back": tools.Anim(self.frames[6:8], 20) } die = tools.Anim(self.frames[8:], 10, 1) self.anims = {"walk": walk, "hit": hit, "die": die} self.image = self.get_anim().get_next_frame(pg.time.get_ticks()) self.health = 6 self.attack = 6 self.drops = ["heart", None]
def get_attack_info(self, start, size, columns, fps=15.0): """Get attack frames from the attack sheet.""" sheet = prepare.GFX["equips"]["attacks1"] raw_frames = tools.strip_from_sheet(sheet, start, size, columns) anims = {} rects = {} for i, direct in enumerate(["right", "back", "left", "front"]): frames = [pg.transform.rotate(pic, i * 90) for pic in raw_frames] anims[direct] = tools.Anim(frames, fps, 1) rects[direct] = [pic.get_rect() for pic in frames] return anims, rects
def __init__(self, owner, *groups): size = prepare.CELL_SIZE _Particle.__init__(self, owner.rect.topleft, size, *groups) self.owner = owner self.vec = None self.speed = 5 self.attack = 5 self.frames = tools.strip_from_sheet(SHOOT_SHEET, (100, 250), size, 2) self.anim = tools.Anim(self.frames, 12) self.image = self.anim.get_next_frame(pg.time.get_ticks()) self.mask = pg.mask.from_surface(self.image)
def __init__(self): stats = (0, 3, 0) _Weapon.__init__(self, "labrys", stats, (0, 50)) self.title = "Mini-Labrys" self.descript = ["Foliage beware !"] self.display = DISPLAY_SHEET.subsurface(((0, 0), prepare.CELL_SIZE)) self.sprite = AttackSprite(prepare.SFX["whoosh"], (0, 20), (30, 50), 3) # Left frames need to be vertically flipped. left_frames = self.sprite.anims["left"].frames lefts = [pg.transform.flip(frame, 0, 1) for frame in left_frames] self.sprite.anims["left"] = tools.Anim(lefts, 15.0, 1)
def __init__(self, *args): _Enemy.__init__(self, *args) self.anim_directions = ["left", "right"] self.anim_direction = random.choice(self.anim_directions) self.ai = LinearAI(self) walk = { "left": tools.Anim(self.frames[:2], 7), "right": tools.Anim([ pg.transform.flip(self.frames[0], 1, 0), pg.transform.flip(self.frames[1], 1, 0) ], 7) } hit = { "left": tools.Anim(self.frames[2:4], 20), "right": tools.Anim([ pg.transform.flip(self.frames[2], 1, 0), pg.transform.flip(self.frames[3], 1, 0) ], 20) } die_frames = self.frames[4:] + [self.frames[-1]] flipped_die = [pg.transform.flip(frame, 1, 0) for frame in die_frames] die = { "left": tools.Anim(self.frames[4:], 5, 1), "right": tools.Anim(flipped_die, 5, 1) } self.anims = {"walk": walk, "hit": hit, "die": die} self.image = self.get_anim().get_next_frame(pg.time.get_ticks())
def __init__(self, _a, _b, target, mask, fps=4, frames=2, src=None): """ The frames argument is the number of frames in the animation, and fps is the desired framerate of the animation; src is the source location on the animation sheet (not the water sheet). _a and _b are dummy variables that are not actually needed. They are in the list of args so that the interface to Tile and AnimatedTile are the same. """ Tile.__init__(self, "animsheet", src, target, mask) size = prepare.CELL_SIZE frames = tools.strip_from_sheet(self.sheet, src, size, frames) self.anim = tools.Anim(frames, fps)
def __init__(self, *args): _Enemy.__init__(self, "evil_elf", ENEMY_SHEET_2, *args) self.ai = LinearAI(self) walk = { "front": tools.Anim(self.frames[:2], 7), "back": tools.Anim(self.frames[6:8], 7), "left": tools.Anim(self.frames[2:4], 7), "right": tools.Anim(self.frames[4:6], 7) } hit = { "front": tools.Anim(self.frames[:2], 20), "back": tools.Anim(self.frames[6:8], 20), "left": tools.Anim(self.frames[2:4], 20), "right": tools.Anim(self.frames[4:6], 20) } death_args = (ENEMY_SHEET, (150, 50), prepare.CELL_SIZE, 3) death_frames = tools.strip_from_sheet(*death_args) die = tools.Anim(death_frames, 3, loops=1) self.anims = {"walk": walk, "hit": hit, "die": die} self.image = self.get_anim().get_next_frame(pg.time.get_ticks()) self.health = 6 self.attack = 6 self.drops = ["heart", None]
def make_images(self, attack=False): """Create the player's animations any time he changes equipment.""" base = pg.Surface(prepare.CELL_SIZE).convert() base.set_colorkey(prepare.COLOR_KEY) base.fill(prepare.COLOR_KEY) anims = {} for direction in prepare.DIRECTIONS: frames = [] for frame in (0, 1): image = base.copy() if attack: get_part = self.get_part_image else: get_part = self.get_part_image blitting = get_part(direction, 'body', frame) if blitting: image.blit(blitting, (0, 0)) frames.append(image) anims[direction] = tools.Anim(frames, STANDARD_ANIMATION_FPS) return anims
def make_hit_images(self, from_dict): """ Create a dictionary of red and blue versions of the player's animations to use while getting hit. Uses a messy 8-bit palette conversion. """ anims = {} for direction in from_dict: frames = [] for i, frame in enumerate(from_dict[direction].frames): image = pg.Surface(prepare.CELL_SIZE) image.fill((85, 0, 85)) image.blit(frame, (0, 0)) image = image.convert(8) palette = image.get_palette() index, colorkey = (0, (235, 0, 85)) if i else (2, (85, 0, 235)) for color in palette: color[index] = min(color[index] + 150, 255) image.set_palette(palette) image.set_colorkey(colorkey) frames.append(image) anims[direction] = tools.Anim(frames, HIT_ANIMATION_FPS) return anims
def __init__(self, name, pos, duration, chest=False, ident=None, *groups): """ The argument name is the type of item corresponding to the ITEMS dict; pos is the location on the map the item is located; if the item is in a treasure chest, pass chest=True; if the player can only get this item once, pass a unique (to the map) ident string to be stored in the player's identifiers attribute. """ pg.sprite.Sprite.__init__(self, *groups) coords, size = ITEM_COORDS[name], prepare.CELL_SIZE self.frames = tools.strip_coords_from_sheet(ITEM_SHEET, coords, size) self.anim = tools.Anim(self.frames, 7) self.image = self.anim.get_next_frame(pg.time.get_ticks()) # Subtract 1 from y axis to make item drop appear behind death anim. self.rect = pg.Rect((pos[0], pos[1] - 1), prepare.CELL_SIZE) self.exact_position = list(self.rect.topleft) self.old_position = self.exact_position[:] self.mask = pg.Mask(prepare.CELL_SIZE) self.mask.fill() self.timer = tools.Timer(duration * 1000, 1) if duration else None self.from_chest = chest self.identifier = ident # Used to stop respawning of unique items. self.height = 0 # Used when item rises from chest. self.sound_effect = None