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


Python Timer.start_timer方法代码示例

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


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

示例1: BuildProcess

# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import start_timer [as 别名]
class BuildProcess(LevelObject):
    def __init__(self, var_dict):
        LevelObject.__init__(self, var_dict)
        self.type = BUILD_PROC
        str_input = var_dict['input']
        str_output = var_dict['output']
        self.input_items = [x.strip() for x in str_input.split(',')]
        self.output_items = [x.strip() for x in str_output.split(',')]
        self.length = to_num(var_dict['time'])
        self.delay_timer = Timer(5, self._ready)
        self.build_timer = Timer(self.length, self._finish)
        self.ready = True
        self.built = []  # list of output items that need to be spawned into the level
        self.input_area = self.rect  # required input parts must collide with this rect to start build
        self.output_area = pygame.Rect(self.rect.right, self.rect.bottom, 200, 100)  # items with output in this rect

    def _ready(self):
        print('ready')
        self.ready = True

    def _finish(self):
        print('Finished')
        self._build()
        self.ready = False
        self.delay_timer.start_timer()

    def start(self):
        if self.ready:
            print('Starting')
            self.build_timer.start_timer()

    def _build(self):
        print('built')
        [self.built.append(x) for x in self.output_items]

    def interact(self, obj, behavior):
        if self.ready:
            print('Starting')
            self.build_timer.start_timer()

    def provide_type_vars(self):
        LevelObject.provide_type_vars(self)
        yield ('input', str(self.input_items))
        yield ('output', str(self.output_items))
        yield ('time', str(self.length))
开发者ID:v0ided,项目名称:FirstPyGame,代码行数:47,代码来源:BuildProcess.py

示例2: PlayerSprite

# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import start_timer [as 别名]

#.........这里部分代码省略.........

    def _respond_collision(self, obj):
        """Responds to a collision, trusts the caller that the objects are colliding"""
        if obj.collidable:
                #save the last collided object
                self.col_object = obj
                if obj.rect.collidepoint(self.rect.midbottom):
                    self.yvel = 0
                    self.rect.bottom = obj.rect.top
                    #save the object the player is on
                    self.on_object = obj
                    #If falling, let jump state know player landed
                    if self.jump_state == FALLING:
                        self.__next_jump_state()
                elif obj.rect.collidepoint(self.rect.bottomleft):
                    if self.direction == DIR_LEFT:
                        self.xvel = 0
                elif obj.rect.collidepoint(self.rect.bottomright):
                    if self.direction == DIR_RIGHT:
                        self.xvel = 0

    def _check_pos_interact(self, obj, colliding):
        """Maintains list of objects with possible interaction"""
        if colliding:
            if obj not in self.pos_interact:
                self.pos_interact.append(obj)
        else:
            if obj in self.pos_interact:
                self.pos_interact.remove(obj)

    def __next_jump_state(self):
        if self.jump_state == NOT_JUMPING:
            self.jump_state = JUMP_DELAY
            self.j_delay_timer.start_timer()
        elif self.jump_state == JUMP_DELAY:
            self.jump_state = JUMP
            self.jump_timer.start_timer()
            self._change_vel(DIR_UP, 2)
        elif self.jump_state == JUMP:
            self.jump_state = FALLING
        elif self.jump_state == FALLING:
            self.jump_state = NOT_JUMPING
        else:
            print("Invalid player jump state: " + str(self.jump_state))

    def start_jump(self):
        self.__next_jump_state()

    def _do_jump(self):
        self._change_vel(DIR_UP, self.jumpvel)

    def update(self):
        self.move()

    def do_gravity(self, gravity):
        self._change_vel(DIR_DOWN, gravity)

    def check_interactions(self):
        if not self._use_timer:
            self._use_timer = Timer(self.use_timer_len, self._set_can_use)
        if self._can_use:
            #interact with held item
            if self.held_item:
                if self.interact(self.held_item, PLACE):
                    self._can_use = False
                    self._use_timer.start_timer()
开发者ID:v0ided,项目名称:FirstPyGame,代码行数:70,代码来源:Player.py


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