def make_dealing_animations(self): self.animations = pg.sprite.Group() delay_time = 100 for player in self.game.deal_queue: toggle = 0 for slot in player.card_slots: card = player.draw_from_deck(self.game.deck) fx, fy = slot.topleft ani = Animation(x=fx, y=fy, duration=400, delay=delay_time, transition="in_out_quint", round_values=True) if toggle > 0: if player is self.game.player: ani.callback = player.flip_cards else: ani.callback = player.align_cards ani.start(card.rect) self.animations.add(ani) task = Task(self.play_deal_sound, delay_time + 20) task2 = Task(self.play_flip_sound, delay_time - 20) self.animations.add(task) self.animations.add(task2) delay_time += 100 toggle += 1
def make_labels(self): sr = self.screen_rect self.labels = [] self.alpha = 255 self.big_alpha = 255 self.animations = pg.sprite.Group() text = "Free Ride" if self.game.free_ride else "Ante Up" self.big_label = Label(self.font, 320, text, "gold3", {"center": sr.center}, bg=prepare.FELT_GREEN) self.big_label.image.set_colorkey(prepare.FELT_GREEN) left, top = self.big_label.rect.topleft ani = Animation(x=left, y=top-500, duration=2000, round_values=True) fade = Animation(alpha=0, duration=2000, round_values=True) big_fader = Animation(big_alpha=0, duration=1500, delay=500, round_values=True) fade.start(self) ani.start(self.big_label.rect) big_fader.start(self) self.animations.add(ani, fade, big_fader) if not self.game.free_ride: dest = self.game.pot_label.rect.center for p in self.game.players: pos = p.name_label.rect.center label = Label(self.font, 96, "${}".format(self.game.bet), "darkred", {"center": pos}, bg=prepare.FELT_GREEN) label.image.set_colorkey(prepare.FELT_GREEN) left, top = label.rect.topleft self.labels.append(label) ani = Animation(centerx=dest[0], centery=dest[1], duration=2000, delay=50, round_values=True, transition="in_quart") ani.callback = self.add_bet_to_pot ani.start(label.rect) self.animations.add(ani) fader = Animation(alpha=0, duration=2100, round_values=True) fader.start(self) self.animations.add(fader)
def clear_area_highlight(self): self.remove_animations(self._hovered_chip_area.sprite.image) ani = Animation(set_alpha=0, initial=self._hovered_chip_area.sprite.image.get_alpha, duration=500, transition='out_quint') ani.callback = self._hovered_chip_area.sprite.kill ani.start(self._hovered_chip_area.sprite.image) self.animations.add(ani) self._hovered_chip_area = None
def clear_area_highlight(self): self.remove_animations(self._hovered_chip_area.sprite.image) ani = Animation( set_alpha=0, initial=self._hovered_chip_area.sprite.image.get_alpha, duration=500, transition='out_quint') ani.callback = self._hovered_chip_area.sprite.kill ani.start(self._hovered_chip_area.sprite.image) self.animations.add(ani) self._hovered_chip_area = None
def clear_card(card): sound = choice(self.deal_sounds) sound.set_volume(.6) sound.play() set_dirty = lambda: setattr(card, 'dirty', 1) fx, fy = card.rect.move(-1400, -200).topleft ani0 = Animation(x=fx, y=fy, duration=400, transition='in_out_quint', round_values=True) ani0.update_callback = set_dirty ani0.callback = card.kill ani0.start(card.rect) ani1 = Animation(rotation=180, duration=400, transition='out_quart') ani1.update_callback = set_dirty ani1.start(card) self.animations.add(ani0, ani1)
def make_labels(self): sr = self.screen_rect self.labels = [] self.alpha = 255 self.big_alpha = 255 self.animations = pg.sprite.Group() text = "Free Ride" if self.game.free_ride else "Ante Up" self.big_label = Label(self.font, 320, text, "gold3", {"center": sr.center}, bg=prepare.FELT_GREEN) self.big_label.image.set_colorkey(prepare.FELT_GREEN) left, top = self.big_label.rect.topleft ani = Animation(x=left, y=top - 500, duration=2000, round_values=True) fade = Animation(alpha=0, duration=2000, round_values=True) big_fader = Animation(big_alpha=0, duration=1500, delay=500, round_values=True) fade.start(self) ani.start(self.big_label.rect) big_fader.start(self) self.animations.add(ani, fade, big_fader) if not self.game.free_ride: dest = self.game.pot_label.rect.center for p in self.game.players: pos = p.name_label.rect.center label = Label(self.font, 96, "${}".format(self.game.bet), "darkred", {"center": pos}, bg=prepare.FELT_GREEN) label.image.set_colorkey(prepare.FELT_GREEN) left, top = label.rect.topleft self.labels.append(label) ani = Animation(centerx=dest[0], centery=dest[1], duration=2000, delay=50, round_values=True, transition="in_quart") ani.callback = self.add_bet_to_pot ani.start(label.rect) self.animations.add(ani) fader = Animation(alpha=0, duration=2100, round_values=True) fader.start(self) self.animations.add(fader)
def animate_deal(self, sprite, initial, final, index): if hasattr(sprite, '_already_animated'): return None sprite._already_animated = True fx, fy = final ani = Animation(x=fx, y=fy, duration=400., transition='in_out_quint', round_values=True) ani.update_callback = lambda: setattr(sprite, 'dirty', 1) # HACK if 1: sprite.face_up = False ani.callback = partial(self.flip, sprite) ani.start(sprite.rect) return ani
def animate_pop(self, sprite, initial, final, index=1): """Animate chips moving to popped stack """ # cancel animation that is already running on this sprite ani = self._running_animations.get(sprite, None) if ani is not None: del self._running_animations[sprite] self._animations.remove(ani) ani.kill() shadow = self._shadows_dict.get(sprite, None) if shadow is not None: shadow.rect = sprite.rect.move(0, 5) d = get_distance(sprite.rect.topleft, final) if d == 0: return None fx, fy = final ani = Animation(x=fx, y=fy, duration=self.animation_time, transition='out_quint', round_values=True) def update_sprite(): setattr(sprite, 'dirty', 1) offset = 20 - self.height_offset shadow = self._shadows_dict.get(sprite, None) if shadow is not None: shadow.rect = sprite.rect.move(0, offset) ani.update_callback = update_sprite def finalize(): del self._running_animations[sprite] if d > 1: self.play_chip_sound() ani.callback = finalize ani.start(sprite.rect) self._running_animations[sprite] = ani return ani