本文整理汇总了Python中animation.Animation.callback方法的典型用法代码示例。如果您正苦于以下问题:Python Animation.callback方法的具体用法?Python Animation.callback怎么用?Python Animation.callback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类animation.Animation
的用法示例。
在下文中一共展示了Animation.callback方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: shoot
# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import callback [as 别名]
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")
示例2: add_leaf
# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import callback [as 别名]
def add_leaf(self, tree, spot_info):
"""Add a falling leaf."""
fall_time = randint(2000, 2500)
leaf = Leaf(tree, spot_info, self.leaves, self.all_sprites)
y = leaf.rect.centery + leaf.fall_distance
ani = Animation(centery=y, duration=fall_time, round_values=True)
ani.callback = leaf.land
ani.start(leaf.rect)
ani2 = Animation(centery=leaf.collider.centery + leaf.fall_distance,
duration=fall_time, round_values=True)
ani2.start(leaf.collider)
fade = Animation(img_alpha=0, duration=3000, delay=fall_time,
round_values=True)
fade.callback = leaf.kill
fade.update_callback = leaf.set_alpha
fade.start(leaf)
self.animations.add(ani, ani2, fade)
示例3: __init__
# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import callback [as 别名]
def __init__(self, leader_centerpoint, animations, all_sprites, *groups):
super(Flock, self).__init__(*groups)
x, y = leader_centerpoint
for offset in self.offsets:
center = x + offset[0], y + offset[1]
duck = Duck(center, all_sprites)
if offset == (0, 0):
self.leader = duck
dest = duck.rect.y + (prepare.WORLD_SIZE[1] * 2)
ani = Animation(y=dest, duration=self.fly_time, round_values=True)
ani.callback = duck.kill
ani.start(duck.rect)
flap_time = randint(100, 150)
task = Task(duck.flap, flap_time, self.fly_time // flap_time)
animations.add(ani, task)
finish = Task(self.kill, self.fly_time + 100)
animations.add(finish)
self.honked = False
示例4: add_chair
# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import callback [as 别名]
def add_chair(self, midbottom, direction):
"""Add a single chair to the chairlift."""
centerx, bottom = midbottom
if direction == "up":
x_offset = 18
destination = self.top_lifthut.rect.bottom + 10
distance = bottom - destination
klass = UpChair
elif direction == "down":
x_offset = -19
destination = self.bottom_lifthut.rect.top + 70
distance = destination - bottom
klass = DownChair
duration = distance * 30
chair = klass((centerx + x_offset, bottom), self.chairs)
ani = Animation(bottom=destination, duration=duration, round_values=True)
opposite = "up" if direction == "down" else "down"
ani.start(chair.rect)
ani.callback = chair.kill
task = Task(self.recycle_chair, interval=duration, args=(opposite,))
self.animations.add(ani, task)