当前位置: 首页>>代码示例>>Python>>正文


Python Hud.set_counter方法代码示例

本文整理汇总了Python中hud.Hud.set_counter方法的典型用法代码示例。如果您正苦于以下问题:Python Hud.set_counter方法的具体用法?Python Hud.set_counter怎么用?Python Hud.set_counter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hud.Hud的用法示例。


在下文中一共展示了Hud.set_counter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Game

# 需要导入模块: from hud import Hud [as 别名]
# 或者: from hud.Hud import set_counter [as 别名]
class Game (GameState):

    def do_setup (self, level):
        super (Game, self).do_setup ()
                
        self.level = level
        
        self.setup_panda ()
        self.level.setup_entities (self.entities)
        self.setup_input ()
        self.setup_controllers ()
        self.setup_hud ()
        self.setup_logic ()
        self.enter_transition ()
        
        self.events.event ('panda-escape').connect (self.enter_menu)
        self.events.event ('panda-p').connect (self.toggle_pause)

        self.manager.enter_state (
            GameMessage, message =
            (('You have to kill %i pigeons in this level...\n' +
             'Can you make it?') % self.total_pigeons))

    def enter_transition (self):
        self._transition_bg = ui.ImageEntity (entities = self.entities,
                                              image    = 'hud/red-bg.png')
        self._transition_bg.alpha = 1.0
        self._transition_bg.fade_out ()

    def leave_transition (self, next_st = 'menu'):
        self._transition_bg.fade_in ().add_next (task.run (lambda:
            self.manager.leave_state (last_state = next_st)))

    def enter_menu (self):
        self.manager.enter_state ('menu-noload', None, 'ingame')        
        
    @weak_slot
    def on_kill_pigeon (self):
        self.hud.dec_counter ('pigeons', 1)
        self.dead_pigeons += 1
        if self.dead_pigeons >= self.total_pigeons:
            self.win_game ()

    @weak_slot
    def on_kill_boy (self):
        self.fail_game (random.choice (['You are dead!',
                                        'Was it that hard to stay alive?',
                                        "Your soul is burning in hell..."]))

    @weak_slot
    def on_finish_time (self):
        self.fail_game (random.choice (['No more time for you!',
                                        'Too slow man...',
                                        'Hurry up the next time!']))
        
    def win_game (self):
        if self.manager.current == self:
            self.manager.enter_state (
                GameMessage,
                'YOU WON!\n'
                'This was a show-case level of an in-development game,\n'
                'there is more to come in the future.',
                'quit')
            
    def fail_game (self, reason):
        if self.manager.current == self:
            msg = random.choice (['LOOOOOOOOSER', 'You lost!', 'What a pity!',
                                  'Hey, no luck today!'])
            self.manager.enter_state (GameMessage, reason + '\n' + msg, 'retry')
    
    @weak_slot
    def on_place_stick (self):
        if self.player_ctl.can_place_stick:
            self.num_sticks -= 1
            if self.num_sticks == 0:
                self.player_ctl.can_place_stick = False
            self.hud.set_counter ('sticks', self.num_sticks)

    def highlight_stick_task (self, timer):
        pos = self.player_ctl.get_place_position (5)
        best = self.player_ctl.laser.best_stick (pos)
        if best != self._curr_best_stick:
            if self._curr_best_stick:
                self._curr_best_stick.unhighlight ()
            if self.player_ctl.can_place_stick:
                self._curr_best_stick = best
                if best:
                    best.highlight ()
        return task.running
    
    def do_update (self, timer):
        super (Game, self).do_update (timer)

    @weak_slot
    def on_shader_change (self, cfg):
        if cfg.value:
            self.glow_filter.enable (self.manager.panda)
        else:
            self.glow_filter.disable ()
    
#.........这里部分代码省略.........
开发者ID:arximboldi,项目名称:pigeoncide,代码行数:103,代码来源:game.py


注:本文中的hud.Hud.set_counter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。