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


Python Location.clamp方法代码示例

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


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

示例1: TestLocation

# 需要导入模块: from bravo.location import Location [as 别名]
# 或者: from bravo.location.Location import clamp [as 别名]
class TestLocation(unittest.TestCase):

    def setUp(self):
        self.l = Location()

    def test_trivial(self):
        pass

    def test_str(self):
        str(self.l)

    def test_clamp_stance(self):
        """
        Clamped stance should be 1.62 blocks above the current block.
        """

        self.l.pos = Position(0, 32, 0)
        self.l.clamp()
        self.assertAlmostEqual(self.l.stance, 2.62)

    def test_save_to_packet(self):
        self.assertTrue(self.l.save_to_packet())

    def test_in_front_of(self):
        other = self.l.in_front_of(1)

        self.assertEqual(other.pos.x, 0)
        self.assertEqual(other.pos.z, 32)

    def test_in_front_of_yaw(self):
        self.l.ori = Orientation.from_degs(90, 0)
        other = self.l.in_front_of(1)

        self.assertEqual(other.pos.x, -32)
        self.assertEqual(other.pos.z, 0)
开发者ID:JDShu,项目名称:bravo,代码行数:37,代码来源:test_location.py

示例2: BetaServerProtocol

# 需要导入模块: from bravo.location import Location [as 别名]
# 或者: from bravo.location.Location import clamp [as 别名]

#.........这里部分代码省略.........
        Hook for grounded packets.
        """

        self.location.grounded = bool(container.grounded)

    def position(self, container):
        """
        Hook for position packets.
        """

        if self.state != STATE_LOCATED:
            log.msg("Ignoring unlocated position!")
            return

        self.grounded(container.grounded)

        old_position = self.location.pos
        position = Position.from_player(container.position.x,
                container.position.y, container.position.z)
        altered = False

        dx, dy, dz = old_position - position
        if any(abs(d) >= 64 for d in (dx, dy, dz)):
            # Whoa, slow down there, cowboy. You're moving too fast. We're
            # gonna ignore this position change completely, because it's
            # either bogus or ignoring a recent teleport.
            altered = True
        else:
            self.location.pos = position
            self.location.stance = container.position.stance

        # Santitize location. This handles safety boundaries, illegal stance,
        # etc.
        altered = self.location.clamp() or altered

        # If, for any reason, our opinion on where the client should be
        # located is different than theirs, force them to conform to our point
        # of view.
        if altered:
            log.msg("Not updating bogus position!")
            self.update_location()

        # If our position actually changed, fire the position change hook.
        if old_position != position:
            self.position_changed()

    def orientation(self, container):
        """
        Hook for orientation packets.
        """

        self.grounded(container.grounded)

        old_orientation = self.location.ori
        orientation = Orientation.from_degs(container.orientation.rotation,
                container.orientation.pitch)
        self.location.ori = orientation

        if old_orientation != orientation:
            self.orientation_changed()

    def location_packet(self, container):
        """
        Hook for location packets.
        """
开发者ID:justinnoah,项目名称:bravo,代码行数:69,代码来源:protocol.py


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