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


Python Brain.detach方法代码示例

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


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

示例1: __init__

# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import detach [as 别名]

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

                self.animation = Animation(0, time_to_turn, 1.0)

            if command is Command.SHOOT and self.bullet is None:
                #print self.color, 'is SHOOTING'
                self.state = TankState.SHOOTING

    def stop(self):
        '''Stop current state and return to idle.'''
        self.offset = (0,0)
        self.animation = None
        self.state = TankState.IDLE

    def update(self, dt):
        '''Process tank state, with respect to time'''
        if self.animation:
            self.animation.update(dt)

        if self.state is TankState.IDLE:
            self.read_command()

        if self.state is TankState.TURNING:
            if self.animation.done:
                self.state = TankState.IDLE
                self.facing = self.turn_to
            return

        if self.state is TankState.SHOOTING:
            self.shots += 1
            self.bullet = Bullet(self)
            self.world.add_bullet(self.bullet)
            self.state = TankState.IDLE
            return

        if self.state is TankState.MOVING:
            o = self.offset
            dt = self.offset_dt
            anim = self.animation
            world = self.world

            sign = 1 if self.driving_forward else -1

            if anim.done: # done moving, warp to final destination
               # set up a warp
               self.warp_x = self.x + dt[0]*sign
               self.warp_y = self.y + dt[1]*sign

               world.warp(self)
               self.set_position(self.warp_x, self.warp_y)
               self.stop()

            else: # still moving
                target = world.get_tile(self.x+dt[0]*sign, self.y+dt[1]*sign)
                current = world.get_tile(self.x, self.y)

                # look for blocking items
                if target[0] in world.blocking_tiles or target[1] in world.blocking_items:
                    self.stop()
                    print self.color, 'tried to drive into item, stopping'
                    return

                # don't move off map
                if target[0] is None:
                    self.stop()
                    print self.color, 'tried to drive off map, stopping'
                    return

                # don't collide with another tank
                if target[1] in world.tanks:
                    self.stop()
                    print self.color, 'tried to ram another tank, stopping'
                    return

                # move speed adjustment
                jitter = (0,0)
                ri = random.randint
                progress = anim.unit()
                anim.speed = self.speed
                if current[0] is world.dirt and progress < 0.5:
                    anim.speed = self.reduced_speed
                    jitter = (ri(-1,1),ri(0,2))
                if target[0] is world.dirt and progress > 0.5:
                    anim.speed = self.reduced_speed
                    jitter = (ri(-1,1),ri(0,2))

                self.offset = (dt[0]*anim.value*sign+jitter[0],
                               -dt[1]*anim.value*sign+jitter[1])


    def is_idle(self):
        return self.state is TankState.IDLE

    def kill(self):
        print "BANG! %s is dead." % self.color

        self.state = TankState.DEAD

        if self.brain:
            self.brain.detach()
            self.world.detonate(self)
开发者ID:codelurker,项目名称:BrainTank,代码行数:104,代码来源:tank.py


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