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


Python Brain.pop方法代码示例

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


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

示例1: __init__

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

#.........这里部分代码省略.........
        self.left = load('left')
        self.right = load('right')

        # build images
        img = pyglet.resource.image('tank/bullet.png')
        img.anchor_x = img.width * 0.5
        img.anchor_y = img.height * 0.5

        # lookup table for bullet facing
        self.bullet_facing_img = {
            Facing.UP:    img.get_transform(rotate=0),
            Facing.RIGHT: img.get_transform(rotate=90),
            Facing.DOWN:  img.get_transform(rotate=180),
            Facing.LEFT:  img.get_transform(rotate=270),
        }

        # lookup table for tank facing
        self.tank_facing_img = {
            Facing.UP:    self.up,
            Facing.RIGHT: self.right,
            Facing.DOWN:  self.down,
            Facing.LEFT:  self.left,
        }

    def blit(self, x, y, z):
        x += self.offset[0]
        y += self.offset[1]
        self.tank_facing_img[self.facing].blit(x, y, z)
        #self.rect().debug_draw()

    def read_command(self):
        '''Pop a command from the brain memory and interpret it'''
        if self.brain:
            command = self.brain.pop()

            if command in (Command.FORWARD, Command.BACKWARD):
                self.state = TankState.MOVING
                self.offset_dt = FACING_TO_VEC[self.facing]

                self.driving_forward = (command is Command.FORWARD)

                end = self.world.tile_size[0]
                if self.facing in (Facing.DOWN, Facing.UP):
                    end = self.world.tile_size[1]

                self.animation = Animation(0, abs(end), 1.0)

            if command in (Facing.UP, Facing.DOWN, Facing.LEFT, Facing.RIGHT):
                self.state = TankState.TURNING
                self.turn_to = command # bleh

                time_to_turn = 1.0
                if command in (Facing.UP, Facing.DOWN):
                    if self.facing in (Facing.LEFT, Facing.RIGHT):
                        time_to_turn = 0.5

                else:
                    if self.facing in (Facing.UP, Facing.DOWN):
                        time_to_turn = 0.5

                if command == self.facing:
                    time_to_turn = 0

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

            if command is Command.SHOOT and self.bullet is None:
开发者ID:codelurker,项目名称:BrainTank,代码行数:70,代码来源:tank.py


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