def move_followed_sprite(self, pos): if self._selected_stack: B.processEvent(('PICKUP_STACK_MOTION', (self._popped_chips, pos))) else: B.processEvent(('SNAP_STACK_MOTION', (self._popped_chips, pos))) self._desired_pos = pos[0], pos[1] + self.height_offset self._needs_arrange = True
def move_followed_sprite(self, pos): if self._selected_stack: B.processEvent(('PICKUP_STACK_MOTION', (self._popped_chips, pos))) else: B.processEvent(('SNAP_STACK_MOTION', (self._popped_chips, pos))) self._desired_pos = pos[0], pos[1] + self.height_offset self._needs_arrange = True
def on_jackpot(space, arbiter): ball, pocket = arbiter.shapes ball.needs_remove = True self.ball_tray += self.jackpot_amount + 1 B.processEvent(('pachinko_jackpot', self)) B.processEvent(('pachinko_tray', self)) return True
def f(sprite): if len(self.bets) > 0: self._allow_exit = False self._enable_chips = False sprite.kill() self._advisor.empty() self.deal_cards() B.processEvent(('DO_DROP_STACK', self))
def win_card(self): """Win one of the cards""" possible_cards = [card for card in self.cards if card.active] if possible_cards: card = random.choice(possible_cards) card.set_card_state(bingocard.S_WON) self.play_sound(card.card_success_sound) B.processEvent((events.E_CARD_COMPLETE, card)) card.active = False
def win_card(self): """Win one of the cards""" possible_cards = [card for card in self.cards if card.active] if possible_cards: card = random.choice(possible_cards) card.set_card_state(bingocard.S_WON) self.play_sound(card.card_success_sound) B.processEvent((events.E_CARD_COMPLETE, card)) card.active = False
def return_stack(self, *args): B.processEvent(('RETURN_STACK', self)) self._grabbed = False self._selected_stack = False self._needs_arrange = False self._initial_snap = None self._followed_sprite = None self._popped_chips = list() self.ignore_until_away = True self.arrange()
def return_stack(self, *args): B.processEvent(('RETURN_STACK', self)) self._grabbed = False self._selected_stack = False self._needs_arrange = False self._initial_snap = None self._followed_sprite = None self._popped_chips = list() self.ignore_until_away = True self.arrange()
def handle_motion(self, pos): """Do stuff with the mouse/touch pointer :param pos: Mouse/Touch position in screen coordinates :return: """ # check if mouse is close to a sprite, and snap to it closest_sprite = self.snap_sprite(pos) if self.ignore_until_away: if closest_sprite is None: self.ignore_until_away = False else: return # ignore chips in motion if closest_sprite in self._running_animations.keys(): return # this will snap chips to the cursor elif not self._grabbed and closest_sprite is not None: # prevent multiple stacks from being hovered at once if ChipPile.__current_stack is not self: if ChipPile.__current_stack is None: ChipPile.__current_stack = self elif ChipPile.__current_stack._grabbed: return else: ChipPile.__current_stack.return_stack() ChipPile.__current_stack = self if self._followed_sprite is not closest_sprite: choice(self.chip_sounds).play() self._followed_sprite = closest_sprite self._popped_chips.append(closest_sprite) self._initial_snap = closest_sprite.rect.center if len(self._popped_chips) == 1: B.processEvent(('SNAP_STACK', (self, pos))) # we have a sprite following the pointer # if self._followed_sprite is not None: if self._popped_chips: self.move_followed_sprite(pos) close_enough = (abs(get_distance(pos, self._initial_snap)) < self._maximum_distance_until_drop) # we've moved too far away without selecting the stack # so the stack is returned to the pile if not close_enough and not self._selected_stack: self.return_stack()
def handle_motion(self, pos): """Do stuff with the mouse/touch pointer :param pos: Mouse/Touch position in screen coordinates :return: """ # check if mouse is close to a sprite, and snap to it closest_sprite = self.snap_sprite(pos) if self.ignore_until_away: if closest_sprite is None: self.ignore_until_away = False else: return # ignore chips in motion if closest_sprite in self._running_animations.keys(): return # this will snap chips to the cursor elif not self._grabbed and closest_sprite is not None: # prevent multiple stacks from being hovered at once if ChipPile.__current_stack is not self: if ChipPile.__current_stack is None: ChipPile.__current_stack = self elif ChipPile.__current_stack._grabbed: return else: ChipPile.__current_stack.return_stack() ChipPile.__current_stack = self if self._followed_sprite is not closest_sprite: choice(self.chip_sounds).play() self._followed_sprite = closest_sprite self._popped_chips.append(closest_sprite) self._initial_snap = closest_sprite.rect.center if len(self._popped_chips) == 1: B.processEvent(('SNAP_STACK', (self, pos))) # we have a sprite following the pointer # if self._followed_sprite is not None: if self._popped_chips: self.move_followed_sprite(pos) close_enough = (abs(get_distance(pos, self._initial_snap)) < self._maximum_distance_until_drop) # we've moved too far away without selecting the stack # so the stack is returned to the pile if not close_enough and not self._selected_stack: self.return_stack()
def remove_internal(self, sprite): super(ChipPile, self).remove_internal(sprite) for name in ('_clicked_sprite', '_followed_sprite'): if getattr(self, name) is sprite: setattr(self, name, None) try: self._popped_chips.remove(sprite) except ValueError: pass try: shadow = self._shadows_dict.pop(sprite) self._shadows.remove(shadow) except KeyError: pass B.processEvent(('CHIPS_VALUE_CHANGE', self))
def drop_followed(self, pos): d = { 'object': self, 'position': pos, 'chips': list(self._popped_chips) } # drop will be be true when somebody # has accepted the dropped stack drop = self.handle_drop(B.processEvent(('DROP_STACK', d))) self.return_stack()
def handle_click(self, value, pos=None): value = bool(value) if not self._selected_stack == value: # the button is clicked and something is following # so we assume it is a pickup. followed = self._followed_sprite is not None if value and followed: self._grabbed = True B.processEvent(('PICKUP_STACK', self)) # button is released and and we are followed, so # lets drop whatever is following up elif not value and followed: self._grabbed = False self.ignore_until_away = True self.drop_followed(pos) # this triggers animation changes, essentially self._selected_stack = value self.handle_motion(pos)
def on_ball_return(space, arbiter): ball, pocket = arbiter.shapes ball.needs_remove = True self.ball_tray += 1 B.processEvent(('pachinko_tray', self)) return True
def on_ball_fail(space, arbiter): ball, pocket = arbiter.shapes ball.needs_remove = True B.processEvent(('pachinko_gutter', self)) return True
def add_internal(self, *args, **kwargs): super(ChipPile, self).add_internal(*args, **kwargs) B.processEvent(('CHIPS_VALUE_CHANGE', self))
def new_ball(self, space, arbiter): if not self._plunger.chute_counter and self.ball_tray: self.add(Ball(space, self._plunger.ball_chute)) self.ball_tray -= 1 B.processEvent(('pachinko_tray', self))