Esempio n. 1
0
 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
Esempio n. 2
0
 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
Esempio n. 3
0
 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
Esempio n. 4
0
 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))
Esempio n. 5
0
 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
Esempio n. 6
0
 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
Esempio n. 7
0
 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()
Esempio n. 8
0
 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()
Esempio n. 9
0
    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()
Esempio n. 10
0
 def handle_click(self):
     """The number was clicked on"""
     if not self.is_active:
         return
     self.is_called = not self.is_called
     if self.is_called:
         self.card.call_square(self.text)
         B.processEvent((events.E_PLAYER_PICKED, self))
     else:
         self.card.reset_square(self.text)
         B.processEvent((events.E_PLAYER_UNPICKED, self))
Esempio n. 11
0
    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()
Esempio n. 12
0
 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))
Esempio n. 13
0
 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))
Esempio n. 14
0
    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()
Esempio n. 15
0
    def __init__(self, rect, value=0, **kwargs):
        super(ChipPile, self).__init__(rect, **kwargs)
        self.stacking = 70, -10
        self.ignore_until_away = True
        self.arrange_function = self.animate_pop
        self._clicked_sprite = None
        self._followed_sprite = None
        self._popped_chips = list()
        self._initial_snap = None
        self._desired_pos = None
        self._selected_stack = False
        self._grabbed = False
        self._shadows = SpriteGroup()
        self._shadows_dict = dict()

        self._running_animations = dict()
        B.linkEvent('DO_DROP_STACK', self.return_stack)
        if value:
            self.add(*cash_to_chips(value))
Esempio n. 16
0
    def __init__(self, rect, value=0, **kwargs):
        super(ChipPile, self).__init__(rect, **kwargs)
        self.stacking = 70, -10
        self.ignore_until_away = True
        self.arrange_function = self.animate_pop
        self._clicked_sprite = None
        self._followed_sprite = None
        self._popped_chips = list()
        self._initial_snap = None
        self._desired_pos = None
        self._selected_stack = False
        self._grabbed = False
        self._shadows = SpriteGroup()
        self._shadows_dict = dict()

        self._running_animations = dict()
        B.linkEvent('DO_DROP_STACK', self.return_stack)
        if value:
            self.add(*cash_to_chips(value))
Esempio n. 17
0
    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()
Esempio n. 18
0
 def update_squares_to_go(self):
     """Update a card with the number of squares to go"""
     number_to_go, self.potential_winning_squares = self.state.winning_pattern.get_number_to_go_and_winners(self, self.called_squares)
     #
     # Check if a line completed
     if self.active and number_to_go == 0:
         for squares in self.state.winning_pattern.get_winning_squares(self, self.called_squares):
             state = None
             missing_squares = self.state.get_missing_squares(squares)
             if not missing_squares:
                 self.state.add_generator('flash-squares', self.flash_squares(squares, S_GOOD, S_GOOD))
                 self.state.play_sound(self.card_success_sound)
                 self.set_card_state(S_WON)
             else:
                 self.state.add_generator('flash-squares', self.flash_squares(missing_squares, S_BAD, S_BAD))
                 self.state.play_sound('bingo-card-failure')
                 self.set_card_state(S_LOST)
             B.processEvent((events.E_CARD_COMPLETE, self))
         #
         self.active = False
Esempio n. 19
0
    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)
Esempio n. 20
0
    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)
Esempio n. 21
0
 def __init__(self):
     """Initialise the bingo game"""
     #
     self.verbose = False
     self.sound_muted = prepare.ARGS['debug']
     #
     self.screen_rect = pg.Rect((0, 0), prepare.RENDER_SIZE)
     self.auto_pick = S['debug-auto-pick']
     #
     self.ui = common.ClickableGroup()
     #
     self.lobby_button = NeonButton(S['lobby-position'], 'Lobby',
                                    self.return_to_lobby)
     self.new_game_button = NeonButton(
         S['new-game-position'], 'New',
         lambda x: self.restart_game(None, None))
     #
     # The controls to allow selection of different numbers of cards
     self.card_selector = cardselector.CardSelector('card-selector', self)
     self.card_selector.linkEvent(events.E_NUM_CARDS_CHANGED,
                                  self.change_number_of_cards)
     self.ui.append(self.card_selector.ui)
     #
     self.create_card_collection()
     self.ui.extend(self.cards)
     #
     self.winning_pattern = patterns.PATTERNS[0]
     #
     self.pattern_buttons = common.DrawableGroup()
     self.debug_buttons = common.DrawableGroup()
     self.buttons = common.DrawableGroup([self.pattern_buttons])
     #
     if prepare.DEBUG:
         self.buttons.append(self.debug_buttons)
     #
     super(Bingo, self).__init__()
     #
     # The machine for picking balls
     self.ball_machine = ballmachine.BallMachine('ball-machine', self)
     self.ball_machine.start_machine()
     self.ui.append(self.ball_machine.buttons)
     #
     self.all_cards = common.DrawableGroup()
     self.all_cards.extend(self.cards)
     self.all_cards.extend(self.dealer_cards)
     #
     B.linkEvent(events.E_PLAYER_PICKED, self.player_picked)
     B.linkEvent(events.E_PLAYER_UNPICKED, self.player_unpicked)
     B.linkEvent(events.E_CARD_COMPLETE, self.card_completed)
     #
     self.current_pick_sound = 0
     self.last_pick_time = 0
Esempio n. 22
0
 def __init__(self):
     """Initialise the bingo game"""
     #
     self.verbose = False
     self.sound_muted = prepare.ARGS['debug']
     #
     self.screen_rect = pg.Rect((0, 0), prepare.RENDER_SIZE)
     self.auto_pick = S['debug-auto-pick']
     #
     self.ui = common.ClickableGroup()
     #
     self.lobby_button = NeonButton(S['lobby-position'], 'Lobby', self.return_to_lobby)
     self.new_game_button = NeonButton(S['new-game-position'], 'New', lambda x: self.restart_game(None, None))
     #
     # The controls to allow selection of different numbers of cards
     self.card_selector = cardselector.CardSelector('card-selector', self)
     self.card_selector.linkEvent(events.E_NUM_CARDS_CHANGED, self.change_number_of_cards)
     self.ui.append(self.card_selector.ui)
     #
     self.create_card_collection()
     self.ui.extend(self.cards)
     #
     self.winning_pattern = patterns.PATTERNS[0]
     #
     self.pattern_buttons = common.DrawableGroup()
     self.debug_buttons = common.DrawableGroup()
     self.buttons = common.DrawableGroup([self.pattern_buttons])
     #
     if prepare.DEBUG:
         self.buttons.append(self.debug_buttons)
     #
     super(Bingo, self).__init__()
     #
     # The machine for picking balls
     self.ball_machine = ballmachine.BallMachine('ball-machine', self)
     self.ball_machine.start_machine()
     self.ui.append(self.ball_machine.buttons)
     #
     self.all_cards = common.DrawableGroup()
     self.all_cards.extend(self.cards)
     self.all_cards.extend(self.dealer_cards)
     #
     B.linkEvent(events.E_PLAYER_PICKED, self.player_picked)
     B.linkEvent(events.E_PLAYER_UNPICKED, self.player_unpicked)
     B.linkEvent(events.E_CARD_COMPLETE, self.card_completed)
     #
     self.current_pick_sound = 0
     self.last_pick_time = 0
Esempio n. 23
0
 def unlink_events(self):
     for name, f in self.interested_events:
         B.unlinkEvent(name, f)
Esempio n. 24
0
 def add_internal(self, *args, **kwargs):
     super(ChipPile, self).add_internal(*args, **kwargs)
     B.processEvent(('CHIPS_VALUE_CHANGE', self))
Esempio n. 25
0
 def __del__(self):
     B.unlinkEvent('DO_DROP_STACK', self.return_stack)
Esempio n. 26
0
 def __del__(self):
     B.unlinkEvent('DO_DROP_STACK', self.return_stack)
Esempio n. 27
0
    def startup(self, now, persistent):
        self.now = now
        self.persist = persistent

        # stuff that might get moved to a gui layer sometime?
        self._needs_clear = True
        self._clicked_sprite = None

        self._power = .5
        self._should_autoplay = False

        B.linkEvent('pachinko_jackpot', self.on_jackpot)
        B.linkEvent('pachinko_gutter', self.on_gutter)
        B.linkEvent('pachinko_tray', self.on_tray)

        # hack related to game states that do not finish
        try:
            self.on_tray()
        except:
            pass
        self.done = False
        try:
            self.playfield.background = None
        except AttributeError:
            pass

        # hack related to game states that do not finish
        if self.did_startup:
            return

        self.did_startup = True

        self.casino_player = self.persist['casino_player']
        self.casino_player.current_game = self.name

        self.playfield = Playfield()
        self.hud = pg.sprite.RenderUpdates()

        font = pg.font.Font(prepare.FONTS["Saniretro"], font_size)
        self.tray_count = TextSprite('', font)
        self.tray_count.rect.topleft = 960, 100
        self.hud.add(self.tray_count)
        self.on_tray()

        t = TextSprite("Press F to add 25", font)
        t.rect.topleft = 960, 170
        self.hud.add(t)

        t = TextSprite("Spacebar Shoots", font)
        t.rect.topleft = 960, 250
        self.hud.add(t)

        def lower_power():
            self.playfield.auto_power -= .01

        def raise_power():
            self.playfield.auto_power += .01

        font = pg.font.Font(prepare.FONTS["Saniretro"], 50)
        fg = pg.Color('gold2')
        text = TextSprite("- POWER", font, fg=fg)
        self.hud.add(Button(text, (1000, 370, 350, 80), lower_power))

        text = TextSprite("AUTO", font, fg=fg)
        self.auto_button = Button(text, (1000, 460, 350, 80),
                                  self.toggle_autoplay)
        self.hud.add(self.auto_button)

        text = TextSprite("+ POWER", font, fg=fg)
        self.hud.add(Button(text, (1000, 550, 350, 80), raise_power))

        b = NeonButton('lobby', (1000, 920, 0, 0), self.goto_lobby)
        self.hud.add(b)

        if 'Pachinko' not in self.casino_player.stats:
            self.casino_player.stats['Pachinko'] = OrderedDict([
                ('games played', 0),
                ('total winnings', 0),
                ('earned', 0),
                ('jackpots', 0),
                ('gutters', 0),
            ])

        self.casino_player.stats['Pachinko']['games played'] += 1
Esempio n. 28
0
 def unlink_events(self):
     for name, f in self.interested_events:
         B.unlinkEvent(name, f)
Esempio n. 29
0
 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
Esempio n. 30
0
 def on_ball_fail(space, arbiter):
     ball, pocket = arbiter.shapes
     ball.needs_remove = True
     B.processEvent(('pachinko_gutter', self))
     return True
Esempio n. 31
0
    def startup(self, now, persistent):
        self.now = now
        self.persist = persistent

        # stuff that might get moved to a gui layer sometime?
        self._needs_clear = True
        self._clicked_sprite = None

        self._power = .5
        self._should_autoplay = False

        B.linkEvent('pachinko_jackpot', self.on_jackpot)
        B.linkEvent('pachinko_gutter', self.on_gutter)
        B.linkEvent('pachinko_tray', self.on_tray)

        # hack related to game states that do not finish
        try:
            self.on_tray()
        except:
            pass
        self.done = False
        try:
            self.playfield.background = None
        except AttributeError:
            pass

        # hack related to game states that do not finish
        if self.did_startup:
            return

        self.did_startup = True

        self.casino_player = self.persist['casino_player']
        self.casino_player.current_game = self.name

        self.playfield = Playfield()
        self.hud = pg.sprite.RenderUpdates()

        font = pg.font.Font(prepare.FONTS["Saniretro"], font_size)
        self.tray_count = TextSprite('', font)
        self.tray_count.rect.topleft = 960, 100
        self.hud.add(self.tray_count)
        self.on_tray()

        t = TextSprite("Press F to add 25", font)
        t.rect.topleft = 960, 170
        self.hud.add(t)

        t = TextSprite("Spacebar Shoots", font)
        t.rect.topleft = 960, 250
        self.hud.add(t)

        def lower_power():
            self.playfield.auto_power -= .01

        def raise_power():
            self.playfield.auto_power += .01

        font = pg.font.Font(prepare.FONTS["Saniretro"], 50)
        fg = pg.Color('gold2')
        text = TextSprite("- POWER", font, fg=fg)
        self.hud.add(Button(text, (1000, 370, 350, 80), lower_power))

        text = TextSprite("AUTO", font, fg=fg)
        self.auto_button = Button(text, (1000, 460, 350, 80),
                                  self.toggle_autoplay)
        self.hud.add(self.auto_button)

        text = TextSprite("+ POWER", font, fg=fg)
        self.hud.add(Button(text, (1000, 550, 350, 80), raise_power))

        b = NeonButton('lobby', (1000, 920, 0, 0), self.goto_lobby)
        self.hud.add(b)

        if 'Pachinko' not in self.casino_player.stats:
            self.casino_player.stats['Pachinko'] = OrderedDict([
                ('games played', 0),
                ('total winnings', 0),
                ('earned', 0),
                ('jackpots', 0),
                ('gutters', 0),
            ])

        self.casino_player.stats['Pachinko']['games played'] += 1
Esempio n. 32
0
 def cleanup(self):
     B.unlinkEvent('pachinko_jackpot', self.on_jackpot)
     B.unlinkEvent('pachinko_gutter', self.on_gutter)
     B.unlinkEvent('pachinko_tray', self.on_tray)
     return self.persist
Esempio n. 33
0
 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))
Esempio n. 34
0
 def add_internal(self, *args, **kwargs):
     super(ChipPile, self).add_internal(*args, **kwargs)
     B.processEvent(('CHIPS_VALUE_CHANGE', self))
Esempio n. 35
0
 def cleanup(self):
     B.unlinkEvent('pachinko_jackpot', self.on_jackpot)
     B.unlinkEvent('pachinko_gutter', self.on_gutter)
     B.unlinkEvent('pachinko_tray', self.on_tray)
     return self.persist