class Powerup(object): def __init__(self, i, j): global powerups init_powerups() self.i = i self.j = j self.timer = globals.pw_timer self.powerup = choice(powerups) index = powerups.index(self.powerup) player = globals.squares[i][j].owner.player_number-1 self.animation = Animation(globals.pw_images[index][player]) def update(self): self.timer -= globals.clock.get_time() if self.timer < 0: globals.powerups.remove(self) self.animation.update() def pickup(self, player): self.powerup(player) globals.powerups.remove(self) def render(self): self.animation.render( self.i * globals.square_size, self.j * globals.square_size, )
def __init__(self, mobject1, mobject2, run_time = DEFAULT_TRANSFORM_RUN_TIME, interpolation_function = straight_path, black_out_extra_points = False, *args, **kwargs): self.interpolation_function = interpolation_function count1, count2 = mobject1.get_num_points(), mobject2.get_num_points() if count2 == 0: mobject2 = Point((SPACE_WIDTH, SPACE_HEIGHT, 0)) count2 = mobject2.get_num_points() Mobject.align_data(mobject1, mobject2) Animation.__init__(self, mobject1, run_time = run_time, *args, **kwargs) self.ending_mobject = mobject2 self.mobject.SHOULD_BUFF_POINTS = \ mobject1.SHOULD_BUFF_POINTS and mobject2.SHOULD_BUFF_POINTS self.reference_mobjects.append(mobject2) self.name += "To" + str(mobject2) if black_out_extra_points and count2 < count1: #Ensure redundant pixels fade to black indices = np.arange( 0, count1-1, float(count1) / count2 ).astype('int') temp = np.zeros(mobject2.points.shape) temp[indices] = mobject2.rgbs[indices] mobject2.rgbs = temp self.non_redundant_m2_indices = indices
class Medbay(Building): def __init__(self): self.ico_pic = pygame.image.load("sprites/generator_ico.png") self.image = Animation() self.image.setup("medbay") self.ico_medic = pygame.image.load("sprites/icons/mup.png") self.ico_medshop = pygame.image.load("sprites/icons/mup.png") self.size = 50 def draw_hud(self, target): target.screen.blit(self.ico_pic, (230, 500)) target.draw_hudbuttons(2) target.screen.blit(self.ico_medic, target.hud.all_coords[0]) target.screen.blit(self.ico_medshop, target.hud.all_coords[1]) def detectact(self, target, curpos): if curpos.get_distance(vec2d(646, 456)) <= 15: if target.buildings[0].inventory[1][1] > 20000: target.buildings[0].inventory[1][1] -= 20000 print("Medic ready for duty!") else: print("You need 20 000 ore to buy this unit!") if curpos.get_distance(vec2d(696, 456)) <= 15: if target.buildings[0].inventory[1][1] > 40000: target.buildings[0].inventory[1][1] -= 40000 print("Battery truck ready for duty!") else: print("You need 40 000 ore to buy this unit!")
class UpgradeFactory(Building): def __init__(self): self.ico_pic = pygame.image.load("sprites/factory_ico.png") self.image = Animation() self.image.setup("factory") self.supic = pygame.image.load("sprites/icons/spu.png") self.mupic = pygame.image.load("sprites/icons/mup.png") self.size = 50 def draw_hud(self, target): target.screen.blit(self.ico_pic, (230, 500)) target.draw_hudbuttons(2) target.screen.blit(self.supic, target.hud.all_coords[0]) target.screen.blit(self.mupic, target.hud.all_coords[1]) def detectact(self, target, curpos): if curpos.get_distance(vec2d(646, 456)) <= 15: if target.buildings[0].inventory[1][1] > 40000: target.buildings[0].inventory[1][1] -= 40000 Drone.speed = 6 print("Drone speed upgraded by 20%.") for drone in target.drones: drone.speed = 6 else: print("You need 40 000 ore to buy speed upgrade!") if curpos.get_distance(vec2d(696, 456)) <= 15: if target.buildings[0].inventory[1][1] > 40000: target.buildings[0].inventory[1][1] -= 40000 Drone.mining_speed = 2 print("Drone mining speed increased by 100%") for drone in target.drones: drone.mining_speed = 2 else: print("You need 40 000 ore to buy mining speed upgrade!")
def update_config(self, **kwargs): Animation.update_config(self, **kwargs) if "path_arc" in kwargs: self.path_func = path_along_arc( kwargs["path_arc"], kwargs.get("path_arc_axis", OUT) )
def startup(self, persistent): self.persist = persistent self.shade_alpha = 255 ani = Animation(shade_alpha=0, duration=3000, round_values=True, transition="linear") ani.start(self) self.animations.add(ani)
def __init__(self, AnimationClass, mobjects, **kwargs): centers = [mob.get_center() for mob in mobjects] kwargs["mobject"] = Mobject().add_points(centers) self.centers_container = AnimationClass(**kwargs) kwargs.pop("mobject") Animation.__init__(self, Mobject(*mobjects), **kwargs) self.name = str(self) + AnimationClass.__name__
def shoot(self, bullets, turkeys, all_sprites, animations): """ Fire a bullet if the player has enough ammo and enough time has passed since the last shot. """ if self.cooldown_timer >= self.cooldown_time: self.stop_walking() if self.shells <= 0: prepare.SFX["gunclick"].play() else: self.shells -= 1 prepare.SFX["gunshot"].play() pos = project(self.pos, (self.angle - .1745) % (2 * pi), 42) #end of rifle at 96x96 bullet = Bullet(pos, self.angle, bullets, all_sprites) distance = 2000. x, y = project(pos, self.angle, distance) ani = Animation(centerx=x, centery=y, duration=distance/bullet.speed, round_values=True) ani.callback = bullet.kill ani.start(bullet.rect) animations.add(ani) scare_rect = self.collider.inflate(1200, 1200) scared_turkeys = [t for t in turkeys if scare_rect.colliderect(t.collider)] for scared in scared_turkeys: task = Task(scared.flee, 750, args=(self,)) self.animations.add(task) task = Task(self.flip_state, 120, args=("idle",)) animations.add(task) self.cooldown_timer = 0 self.flip_state("shoot")
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 Bomb(object): def __init__(self, i, j, player): self.i = i self.j = j self.player = player self.timer = globals.b_timer self.animation = Animation(globals.b_images[player.player_number-1]) def update(self): self.timer -= globals.clock.get_time() if self.timer < 0: self.explode() self.animation.update() def explode(self): self.remove() # rewrite for loops for i in range( max(0, int(self.i - self.player.bomb_radious)), min(globals.squares_per_line, int(self.i+1 + self.player.bomb_radious))): for j in range( max(0, int(self.j - self.player.bomb_radious)), min(globals.squares_per_line, int(self.j+1 + self.player.bomb_radious))): center = (self.i, self.j) square = (i, j) if utils.distance(center, square) <= self.player.bomb_radious: # delete powerup in that square, if any for powerup in globals.powerups: if powerup.i == square[0] and \ powerup.j == square[1]: globals.powerups.remove(powerup) break # delete bomb in that square, if any for bomb in globals.bombs: if bomb.i == square[0] and \ bomb.j == square[1]: bomb.remove() break if globals.squares[i][j].owner != self.player: globals.squares[i][j].change_owner(self.player) globals.explosions.append(Explosion(i, j)) def remove(self): globals.bombs.remove(self) self.player.current_bombs -= 1 def render(self): self.animation.render( self.i * globals.square_size, self.j * globals.square_size, )
def __init__(self): super(Splash, self).__init__() self.next_state = "SHOOTING" self.animations = pg.sprite.Group() with open(os.path.join("resources", "clay_spots.json"), "r") as f: skeet_spots = json.load(f) self.all_sprites = pg.sprite.LayeredUpdates() self.clays = pg.sprite.OrderedUpdates() delay = 0 duration = 500 depth = 5000 for spot in skeet_spots: clay = ClayPigeon((640, 750), 7, 0, False, self.clays, self.all_sprites) clay.rect.center = 640, 750 clay.z = depth x, y = spot ani = Animation(centerx=x, centery=y, duration=duration, delay=delay, round_values=True) ani.start(clay.rect) self.animations.add(ani) delay += 15 depth -= 1 self.world = World(False) for s in self.all_sprites: self.all_sprites.change_layer(s, -s.z) try: with open(os.path.join("resources", "high_scores.json"), "r") as f: high_scores = json.load(f) except IOError: with open(os.path.join("resources", "high_scores.json"), "w") as f: json.dump([], f)
def upgrade(self): self.level = 1 self.target = self.pos self.fire_target = self.pos tempimage = Animation() tempimage.setup("upoutpost") self.image = tempimage
class Outpost(Building): def __init__(self): self.ico_pic = pygame.image.load("sprites/generator_ico.png") self.up_ico = pygame.image.load("sprites/icons/up_ico.png") self.image = Animation() self.image.setup("outpost") self.size = 35 self.level = 0 self.target = vec2d(0, 0) self.fire_target = vec2d(0, 0) def draw_hud(self, target): target.screen.blit(self.ico_pic, (230, 500)) target.draw_hudbuttons(1) target.screen.blit(self.up_ico, target.hud.all_coords[0]) def detectact(self, target, curpos): if curpos.get_distance(vec2d(646, 456)) <= 15: self.upgrade() def upgrade(self): self.level = 1 self.target = self.pos self.fire_target = self.pos tempimage = Animation() tempimage.setup("upoutpost") self.image = tempimage
def update_mobject(self, alpha): Animation.update_mobject(self, alpha) axes = [self.axis] if self.axis is not None else self.axes if self.in_place: method = self.mobject.rotate_in_place else: method = self.mobject.rotate method(alpha*self.radians, axes = axes)
def __init__(self, value_function, **kwargs): """ Value function should return a real value depending on the state of the surrounding scene """ digest_config(self, kwargs, locals()) self.update_mobject() Animation.__init__(self, self.mobject, **kwargs)
def __init__(self, animation, **kwargs): digest_locals(self) self.num_mobject_points = animation.mobject.get_num_points() kwargs.update(dict([ (attr, getattr(animation, attr)) for attr in Animation.CONFIG ])) Animation.__init__(self, animation.mobject, **kwargs) self.name = str(self) + str(self.animation)
def __init__(self, *animations, **kwargs): if "run_time" in kwargs: run_time = kwargs.pop("run_time") else: run_time = sum([anim.run_time for anim in animations]) self.num_anims = len(animations) self.anims = animations mobject = animations[0].mobject Animation.__init__(self, mobject, run_time = run_time, **kwargs)
def __init__(self, homotopy, mobject, **kwargs): """ Homotopy a function from (x, y, z, t) to (x', y', z') """ def function_at_time_t(t): return lambda p : homotopy(p[0], p[1], p[2], t) self.function_at_time_t = function_at_time_t digest_config(self, kwargs) Animation.__init__(self, mobject, **kwargs)
def __init__(self, mobject, **kwargs): self.intermediate = Mobject(color = self.color) self.intermediate.add_points([ point + (x, y, 0) for point in self.mobject.points for x in [-1, 1] for y in [-1, 1] ]) Animation.__init__(self, mobject, **kwargs)
def draw_atk2(self, screen): #slash rate = 3 Animation(screen, self, 0, 0, self.anim_atk2, rate).animate() Animation(screen, self, self.width, self.slash_effect, rate).animate() if self.anim_atk2[-2] == len( self.anim_atk2) - 3 and self.anim_atk2[-1] == rate - 1: Animation(screen, self, 0, 0, self.anim_atk2, 5).animate() self.anim_atk2[-2] = 0 self.attack_status = "none"
def __init__(self, homotopy, mobject, **kwargs): """ Homotopy a function from (x, y, z, t) to (x', y', z') """ def function_at_time_t(t): return lambda p: homotopy(p[0], p[1], p[2], t) self.function_at_time_t = function_at_time_t digest_config(self, kwargs) Animation.__init__(self, mobject, **kwargs)
def __init__(self, *animations, **kwargs): if "run_time" in kwargs: run_time = kwargs.pop("run_time") else: run_time = sum([anim.run_time for anim in animations]) self.num_anims = len(animations) self.anims = (animations) mobject = Mobject(*[anim.mobject for anim in self.anims]) self.last_index = 0 Animation.__init__(self, mobject, run_time = run_time, **kwargs)
def __init__(self, mobject, target_mobject, **kwargs): #Copy target_mobject so as to not mess with caller self.original_target_mobject = target_mobject target_mobject = target_mobject.copy() digest_config(self, kwargs, locals()) mobject.align_data(target_mobject) self.init_path_func() Animation.__init__(self, mobject, **kwargs) self.name += "To" + str(target_mobject)
def __init__(self, matrix, mobject, **kwargs): matrix = np.array(matrix) if matrix.shape == (2, 2): self.matrix = np.identity(3) self.matrix[:2, :2] = matrix elif matrix.shape == (3, 3): self.matrix = matrix else: raise "Matrix has bad dimensions" Animation.__init__(self, mobject, **kwargs)
def draw_atk1(self, screen): #Stab rate = 1 Animation(screen, self, 0, 0, self.anim_atk1, rate).animate() #Animation(screen, self, self.width, self.stab_effect, rate).animate() if self.anim_atk1[-2] == len( self.anim_atk1) - 3 and self.anim_atk1[-1] == rate - 1: Animation(screen, self, 0, 0, self.anim_atk1, 5).animate() self.anim_atk1[-2] = 0 self.attack_status = "none"
def __init__(self, mobject, ending_mobject, **kwargs): #Copy ending_mobject so as to not mess with caller ending_mobject = ending_mobject.copy() digest_config(self, kwargs, locals()) mobject.align_data(ending_mobject) self.init_path_func() Animation.__init__(self, mobject, **kwargs) self.name += "To" + str(ending_mobject) self.mobject.stroke_width = ending_mobject.stroke_width
def draw_warn1(self, screen): #Stab rate = 10 Animation(screen, self, 0, 0, self.anim_warn1, rate).animate() #Animation(screen, self, self.width, self.stab_effect, rate).animate() if self.anim_warn1[-2] == len( self.anim_warn1) - 3 and self.anim_warn1[-1] == rate - 1: Animation(screen, self, 0, 0, self.anim_warn1, 5).animate() self.anim_warn1[-2] = 0 self.attack_status = "one" self.dmg_dealt = False
def __init__(self, game, settings, screen, grid_pts, foods, sb): super().__init__(settings, screen, grid_pts) self.color = self.settings.pacman_color self.food_list = foods.food_list self.set_start_position() self.game = game self.sb = sb self.image = self.settings.get_image(4, 0, 32, 32) self.animation = None self.animations = {} Animation.set_up_pacman_animation(self, self.settings)
def draw_atk1(self, screen): #Stab self.dmg_dealt = False rate = 1 Animation(screen, self, 0,0, self.anim_atk, 1).animate() Animation(screen, self, 550, 0, self.deathbeam_effect, rate).animate() if self.deathbeam_effect[-2] == len(self.deathbeam_effect) - 3 and self.deathbeam_effect[-1] == rate-1: Animation(screen, self, 550,0, self.deathbeam_effect, 5).animate() self.deathbeam_effect[-2] = 0 self.attack_status = "none" self.dmg_dealt = True
def update_mobject(self, alpha): Animation.update_mobject(self, alpha) axes = self.axes if self.axes else [self.axis] about_point = None if self.about_point is not None: about_point = self.about_point elif self.in_place: #This is superseeded self.about_point = self.mobject.get_center() self.mobject.rotate(alpha * self.radians, axes=axes, about_point=self.about_point)
def __init__(self, AnimationClass, mobjects, **kwargs): full_kwargs = AnimationClass.CONFIG full_kwargs.update(kwargs) full_kwargs["mobject"] = Mobject(*[ mob.get_point_mobject() for mob in mobjects ]) self.centers_container = AnimationClass(**full_kwargs) full_kwargs.pop("mobject") Animation.__init__(self, Mobject(*mobjects), **full_kwargs) self.name = str(self) + AnimationClass.__name__
def clean_up(self): Animation.clean_up(self) if hasattr(self, "non_redundant_m2_indices"): #Reduce mobject (which has become identical to mobject2), as #well as mobject2 itself for mobject in [self.mobject, self.ending_mobject]: for attr in ['points', 'rgbs']: setattr( mobject, attr, getattr(self.ending_mobject, attr)[self.non_redundant_m2_indices])
def create_animations(self): left = pygame.image.load("assets/character.png").convert_alpha() right = pygame.transform.flip(left, True, False) self.left_animation = Animation([ Frame(left, [0, 4*self.unit], 4), Frame(left, [0, 0], 4) ]) self.right_animation = Animation([ Frame(right, [0, 4*self.unit], 4), Frame(right, [0, 0], 4) ])
def create_animations(self): image = pygame.image.load("assets/character.png") # create the frames for the "walking left" animation frames = [ Frame(image=image, position=[0, 4 * self.unit], duration=4), Frame(image=image, position=[0, 0], duration=4), ] # and with that create the "walking left" animation self.animation = Animation(frames)
def __init__(self, actor, start, dest, time, snap=False): Animation.__init__(self, actor, permanent=False) self.position = Vector(0, 0) self.vector = Vector(dest) self.vector.sub(Vector(start)) self.vector.div(time) self.tick = 0 self.time = time self.snap = snap
def __init__(self, handler, assets, health, max_health, damage, velocity, health_bar_offset): super().__init__() self.handler = handler self.health = health self.max_health = max_health self.damage = damage self.velocity = velocity self.maxVelocity = velocity * 1.5 self.moveRight = False self.moveLeft = False self.moveUp = False self.moveDown = False self.rightCollide = False self.leftCollide = False self.topCollide = False self.downCollide = False self.orderedToAttack = False self.rightIdleAnimation = Animation(assets[0], 0.07) self.leftIdleAnimation = Animation(assets[1], 0.07) self.rightRunAnimation = Animation(assets[2], 0.07) self.leftRunAnimation = Animation(assets[3], 0.07) self.rightAttackAnimation = Animation(assets[4], 0.05) self.leftAttackAnimation = Animation(assets[5], 0.05) self.rightHurtAnimation = Animation(assets[6], 0.07) self.leftHurtAnimation = Animation(assets[7], 0.07) self.rightDeathAnimation = Animation(assets[8], 0.07) self.leftDeathAnimation = Animation(assets[9], 0.07) self.currentAnimation = self.rightIdleAnimation self.pos_float = [200.0, 250.0] self.rect = self.rightRunAnimation.frames[0].get_rect() self.rect.x = int(self.pos_float[0]) #player starting x (and y) self.rect.y = int(self.pos_float[1]) self.side = 'right' self.isAttacking = False self.notOrdered = True self.WIN = self.handler.game.WIN self.image = self.currentAnimation.frames[0] self.collided = False self.rect_collision_side = [] self.name = '' self.hittingList = [] self.getHurt = False self.dead = False self.controller = None self.sprint = False self.visual_rad = 200 self.attack_rad = 50 self.health_bar_offset = health_bar_offset self.animationOffset = (0, 0) self.rightMovingZone = False self.leftMovingZone = False self.toptMovingZone = False self.downtMovingZone = False
def __init__(self, settings, screen, grid_pts): super().__init__(settings, screen, grid_pts) self.color = self.settings.clyde_color self.image = self.settings.get_image(2, 5, 32, 32) Animation.set_up_ghost_animation(self, self.settings, 5) self.animation = self.animations["down"] self.set_start_position() self.pellets_for_release = 60 self.released = False self.banned_directions = [gf.direction["UP"]] self.spawn_pt = self.current_grid_pt
def __init__(self, pixels): super().__init__(pixels) rand_color_pos_1 = random.randint(0, 255) rand_pixel_1 = random.randint(0, len(self.pixels)) rand_pixel_2 = random.randint(0, len(self.pixels) - 1) self.state = {'base_color_pos': rand_color_pos_1, 'lerp_start_pixel': rand_pixel_1, 'lerp_end_pixel': rand_pixel_2, 'lerp_start_time': Animation.rand_past(), 'lerp_end_time': Animation.rand_future(), 'counter': 0}
def __init__(self, actor, peak, duration): Animation.__init__(self, actor, permanent=False) self.duration = duration peak = -float(peak) duration = float(duration) - 1 self.a = self.get_a(peak, duration) self.func = self.get_func(duration) self.vector = Vector() self.t = 0
def __init__(self, *sub_anims, **kwargs): sub_anims = filter(lambda x: not (x.empty), sub_anims) digest_config(self, locals()) self.update_config(**kwargs) # Handles propagation to self.sub_anims if len(sub_anims) == 0: self.empty = True self.run_time = 0 else: self.run_time = max([a.run_time for a in sub_anims]) everything = Mobject(*[a.mobject for a in sub_anims]) Animation.__init__(self, everything, **kwargs)
def __init__(self, *sub_anims, **kwargs): digest_config(self, kwargs, locals()) sub_anims = filter (lambda x : not(x.empty), sub_anims) if len(sub_anims) == 0: self.empty = True self.run_time = 0 else: # Should really make copies of animations, instead of messing with originals... sync_animation_run_times_and_rate_funcs(*sub_anims, **kwargs) self.run_time = max([a.run_time for a in sub_anims]) everything = Mobject(*[a.mobject for a in sub_anims]) Animation.__init__(self, everything, **kwargs)
def __init__(self, center, shot_from, player, velocity=euclid.Vector2(0.0, 0.0), gravity=euclid.Vector2(0.0, 0.0)): ServerPredatorMissile.__init__(self, center, shot_from, player, velocity, gravity) Projectile.__init__(self, center, shot_from, player, velocity, gravity) self.explosion_animation = Animation( self.shot_from.bullet_image_list[1:6], self, .15)
def __init__(self,pixelstart,pixelstop,direction,name="Sparkle",color=Color(128,128,128)): self.__name = name self.__color = color self.__pixelstart=pixelstart self.__pixelstop=pixelstop self.__duration = 3 self.__pos = 0 if direction: #Prevent low>high error in numpy randint self.__pixelstart=pixelstop self.__pixelstop=pixelstart Animation.__init__(self,self.__name,self.__pixelstart,self.__pixelstop,direction,pixelstart,color)
def __init__(self, decimal_number_mobject, number_update_func, **kwargs): digest_config(self, kwargs, locals()) if self.num_decimal_points is None: self.num_decimal_points = decimal_number_mobject.num_decimal_points decimal_number_mobject.add(*[ VectorizedPoint(decimal_number_mobject.get_corner(DOWN + LEFT)) for x in range(self.spare_parts) ]) if self.tracked_mobject: self.diff_from_tracked_mobject = \ decimal_number_mobject.get_center() - self.tracked_mobject.get_center() Animation.__init__(self, decimal_number_mobject, **kwargs)
def __init__(self) -> None: super().__init__() self.animation = Animation(sprites=( (20 * 16, 42 * 16), (21 * 16, 42 * 16), (22 * 16, 42 * 16), (26 * 16, 40 * 16), ), width=16, height=32, speed=6, cycle=True)
def __init__(self, clock, **kwargs): digest_config(self, kwargs) assert (isinstance(clock, Clock)) rot_kwargs = {"axis": OUT, "about_point": clock.get_center()} hour_radians = -self.hours_passed * 2 * np.pi / 12 self.hour_rotation = Rotating(clock.hour_hand, radians=hour_radians, **rot_kwargs) self.minute_rotation = Rotating(clock.minute_hand, radians=12 * hour_radians, **rot_kwargs) Animation.__init__(self, clock, **kwargs)
def __init__(self) -> None: super().__init__() self.animation = Animation( sprites=((448, 288), (0, 27 * 16), (1 * 40, 27 * 16), (2 * 40, 27 * 16), (3 * 40, 27 * 16), (4 * 40, 27 * 16), (5 * 40, 27 * 16), (6 * 40, 27 * 16), (7 * 40, 27 * 16), (8 * 40, 27 * 16), (9 * 40, 27 * 16), (10 * 40, 27 * 16), (11 * 40, 27 * 16)), width=40, height=56, speed=10, cycle=False)
def __init__(self, *sub_anims, **kwargs): digest_config(self, kwargs, locals()) max_run_time = float(max([a.run_time for a in sub_anims])) for anim in sub_anims: #Use np.divide to that 1./0 = np.inf anim.alpha_multiplier = np.divide(max_run_time, anim.run_time) if "run_time" in kwargs: self.run_time = kwargs.pop("run_time") else: self.run_time = max_run_time everything = Mobject(*[a.mobject for a in sub_anims]) Animation.__init__(self, everything, **kwargs)
class Character: def __init__(self, screen_w, screen_h, unit): self.unit = unit self.create_animations() image_rect = self.animation.get_current_frame().image.get_rect() self.center = image_rect.width/2 self.position = [(screen_w - image_rect.width)/2, screen_h - image_rect.height] size_reduction = 10*unit self.collision_rect = pygame.Rect(image_rect.left + size_reduction, image_rect.top + size_reduction, image_rect.width - 2*size_reduction, image_rect.height - 4*size_reduction) self.screen_w = screen_w self.direction = [0, 0] def create_animations(self): image = pygame.image.load("assets/character.png") # create the frames for the "walking left" animation frames = [ Frame(image = image, position = [0, 4*self.unit], duration = 4), Frame(image = image, position = [0, 0], duration = 4), ] # and with that create the "walking left" animation self.animation = Animation(frames) def input(self, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: self.direction[0] = -1 elif event.key == pygame.K_RIGHT: self.direction[0] = 1 if event.type == pygame.KEYUP: if (event.key == pygame.K_LEFT and self.direction[0] == -1) or\ (event.key == pygame.K_RIGHT and self.direction[0] == 1): self.direction[0] = 0 def update(self): if self.direction[0] != 0: self.animation.update() self.position[0] = (self.position[0] + self.direction[0]*8*self.unit + self.center)\ %self.screen_w - self.center def draw(self, on_surface): self.animation.draw(on_surface, self.position) def collides_with(self, other): return self.get_absolute_rect().colliderect(other.get_absolute_rect()) def get_absolute_rect(self): return self.collision_rect.move(self.position)
def __init__(self, actor, radius, duration, start_angle=0, clockwise=True): Animation.__init__(self, actor, permanent=False) self.position = Vector(radius, 0) self.angle = float(start_angle) self.radius = radius self.duration = duration self.incr = 360.0 / self.duration if not clockwise: self.incr *= -1
class Character: def __init__(self, screen_w, screen_h, unit): self.unit = unit self.create_animations() image_rect = self.animation.get_current_frame().image.get_rect() self.center = image_rect.width / 2 self.position = [(screen_w - image_rect.width) / 2, screen_h - image_rect.height] size_reduction = 10 * unit self.collision_rect = pygame.Rect( image_rect.left + size_reduction, image_rect.top + size_reduction, image_rect.width - 2 * size_reduction, image_rect.height - 4 * size_reduction) self.screen_w = screen_w self.direction = [0, 0] def create_animations(self): image = pygame.image.load("assets/character.png") # create the frames for the "walking left" animation frames = [ Frame(image=image, position=[0, 4 * self.unit], duration=4), Frame(image=image, position=[0, 0], duration=4), ] # and with that create the "walking left" animation self.animation = Animation(frames) def input(self, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: self.direction[0] = -1 elif event.key == pygame.K_RIGHT: self.direction[0] = 1 if event.type == pygame.KEYUP: if (event.key == pygame.K_LEFT and self.direction[0] == -1) or\ (event.key == pygame.K_RIGHT and self.direction[0] == 1): self.direction[0] = 0 def update(self): if self.direction[0] != 0: self.animation.update() self.position[0] = (self.position[0] + self.direction[0]*8*self.unit + self.center)\ %self.screen_w - self.center def draw(self, on_surface): self.animation.draw(on_surface, self.position) def collides_with(self, other): return self.get_absolute_rect().colliderect(other.get_absolute_rect()) def get_absolute_rect(self): return self.collision_rect.move(self.position)
def __init__(self): super(E3Animation, self).__init__() image = images["E3"] offsetx, offsety = 57, 37 self.originalAnimation = "runsw" width, height = 118, 72 playeroffset = 504 y, m, n = 0, 1, 1 self.addAnimationFromSpriteSheetDir(image, 0, y, width, height, m, n, offsetx, offsety, playeroffset, "stand") y, m, n = 216, 6, 1 self.addAnimationFromSpriteSheetDir( image, 0, y, width, height, m, n, offsetx, offsety, playeroffset, "run", False, "stand" ) y, m, n = 288, 6, 1 self.addAnimationFromSpriteSheetDir( image, 0, y, width, height, m, n, offsetx, offsety, playeroffset, "crawl", False, "stand" ) y, m, n = 360, 6, 1 self.addAnimationFromSpriteSheetDir( image, 0, y, width, height, m, n, offsetx, offsety, playeroffset, "attack", False, "stand" ) y, m, n = 432, 6, 1 self.addAnimationFromSpriteSheetDir( image, 0, y, width, height, m, n, offsetx, offsety, playeroffset, "crawlattack", False, "stand" ) x, y, m, n = 2220, 144, 15, 1 self.addAnimationFromSpriteSheet( image, 0, y, width, height, m, n, offsetx, offsety, playeroffset, "die1", False ) x, y, m, n = 3330, 144, 15, 1 self.addAnimationFromSpriteSheet( image, 0, y, width, height, m, n, offsetx, offsety, playeroffset, "die2", False ) x, y, m, n = 1110, 72, 15, 1 for player in range(2): animation = Animation() animation.addImageSpriteSheet(image, x, y, width, height, m, n, offsetx, offsety) animation.loop = False animation.next = self.getAnimation("standsw_%d" % (player)) self.addAnimation("cheer_%d" % (player), animation) y += playeroffset x, y, m, n = 0, 72, 15, 1 for player in range(2): animation = Animation() animation.addImageSpriteSheet(image, x, y, width, height, m, n, offsetx, offsety) animation.loop = False animation.next = self.getAnimation("standsw_%d" % (player)) self.addAnimation("squeez_%d" % (player), animation) y += playeroffset
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 update_mobject(self, alpha): Animation.update_mobject(self, alpha) axes = self.axes if self.axes else [self.axis] about_point = None if self.about_point is not None: about_point = self.about_point elif self.in_place: #This is superseeded self.about_point = self.mobject.get_center() self.mobject.rotate( alpha*self.radians, axes = axes, about_point = self.about_point )
def clean_up(self): Animation.clean_up(self) if hasattr(self, "non_redundant_m2_indices"): #Reduce mobject (which has become identical to mobject2), as #well as mobject2 itself for mobject in [self.mobject, self.ending_mobject]: for attr in ['points', 'rgbs']: setattr( mobject, attr, getattr( self.ending_mobject, attr )[self.non_redundant_m2_indices] )
def __init__(self, word, **kwargs): self.path = Cycloid(end_theta = np.pi) word_mob = TextMobject(list(word)) end_word = word_mob.copy() end_word.shift(-end_word.get_bottom()) end_word.shift(self.path.get_corner(DOWN+RIGHT)) end_word.shift(3*RIGHT) self.end_letters = end_word.split() for letter in word_mob.split(): letter.center() letter.angle = 0 unit_interval = np.arange(0, 1, 1./len(word)) self.start_times = 0.5*(1-(unit_interval)) Animation.__init__(self, word_mob, **kwargs)