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


Python Object.set_position方法代码示例

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


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

示例1: test_set_position

# 需要导入模块: from object import Object [as 别名]
# 或者: from object.Object import set_position [as 别名]
    def test_set_position(self):
        object = Object((10, 10), 33, 11)
        object.set_position((1, 1))

        self.assertEqual(object.position(), (1, 1))
开发者ID:minh0722,项目名称:Bomberman,代码行数:7,代码来源:test.py

示例2: Player

# 需要导入模块: from object import Object [as 别名]
# 或者: from object.Object import set_position [as 别名]
class Player(Object):
    def __init__(self, position, arena, id=1):
        Object.__init__(
            self,
            position,
            PLAYER_RECTANGLE_WIDTH,
            PLAYER_RECTANGLE_HEIGHT)

        self.bomb_capacity = 2
        self.placed_bomb = 0
        self.bomb_range = 3
        self.movement_speed = 3
        self.current_face_direction = Direction.DOWN
        self.state = PlayerState.ALIVE
        self.id = id
        self.arena = arena

        self.player_down_sprite = create_player_down(self.id)
        self.player_up_sprite = create_player_up(self.id)
        self.player_left_sprite = create_player_left(self.id)
        self.player_right_sprite = create_player_right(self.id)

        self.player_die_sprite = create_player_die(self.id)

        self.sprite_conductor = PygConductor(
            self.player_down_sprite,
            self.player_up_sprite,
            self.player_left_sprite,
            self.player_right_sprite)

        self.sprite_conductor.pause()

        self.bombs = list()

        self.tile_position = Object(
            (position[0] + TILE_OFFSET_X, position[1] + TILE_OFFSET_Y),
            PLAYER_RECTANGLE_WIDTH,
            PLAYER_RECTANGLE_WIDTH)

    def set_player_tile_position(self, position):
        self.tile_position.set_position(position)
        self.set_position(
            (position[0] - TILE_OFFSET_X, position[1] - TILE_OFFSET_Y))

    def set_player_position(self, position):
        self.set_position(position)
        self.tile_position.set_position(
            (position[0] + TILE_OFFSET_X, position[1] * TILE_OFFSET_Y))

    def get_player_tile(self):
        return self.tile_position

    def move_up(self):
        Object.move_up(self, self.movement_speed)
        self.tile_position.move_up(self.movement_speed)

        self.arena.physics.resolve_player_collision(self, Direction.UP)

        self.current_face_direction = Direction.UP
        self.player_up_sprite.play()

    def move_down(self):
        Object.move_down(self, self.movement_speed)
        self.tile_position.move_down(self.movement_speed)

        self.arena.physics.resolve_player_collision(self, Direction.DOWN)

        self.current_face_direction = Direction.DOWN
        self.player_down_sprite.play()

    def move_left(self):
        Object.move_left(self, self.movement_speed)
        self.tile_position.move_left(self.movement_speed)

        self.arena.physics.resolve_player_collision(self, Direction.LEFT)

        self.current_face_direction = Direction.LEFT
        self.player_left_sprite.play()

    def move_right(self):
        Object.move_right(self, self.movement_speed)
        self.tile_position.move_right(self.movement_speed)

        self.arena.physics.resolve_player_collision(self, Direction.RIGHT)

        self.current_face_direction = Direction.RIGHT
        self.player_right_sprite.play()

    def is_alive(self):
        return self.state is PlayerState.ALIVE

    def current_state(self):
        return self.state

    def die(self):
        if self.state is not PlayerState.DYING \
                and self.state is not PlayerState.DEAD:
            self.state = PlayerState.DYING
            self.player_die_sprite.play()

#.........这里部分代码省略.........
开发者ID:minh0722,项目名称:Bomberman,代码行数:103,代码来源:player.py


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