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


Python Inventory.put_item方法代码示例

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


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

示例1: Actor

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import put_item [as 别名]
class Actor(movable_object.Movable_Object):

    is_event_handler = True

    def __init__(self, body):
        cshape = cm.AARectShape(eu.Vector2(0, 0), TILE_SIZE_IN_PIXELS / 2, body.img.height / 2)
        super(Actor, self).__init__(body.img, cshape=cshape)

        self.fight_group = -1

        self.direction = 1

        self.owner = self
        self.body = body(self)
        self.launcher = Launcher(self)
        self.state = "stand"
        self.inventory = Inventory(self)

        self.ground_count = 0
        self.on_ground = False

        self.recovery = 0.0  # Time before moment when acton can be controlled again

    height = property(lambda self: self.body.img.height)
    width = property(lambda self: self.body.img.width)

    def setup_b2body(self):
        super(Actor, self).setup_b2body()
        pix_to_tile = pixels_to_tiles
        rx, ry = pix_to_tile((self.cshape.rx, self.cshape.ry))
        self.b2body.CreateFixture(
            b2.b2FixtureDef(
                shape=b2.b2PolygonShape(
                    vertices=[(-rx, ry), (-rx, -ry + 0.1), (-rx + 0.1, -ry), (rx - 0.1, -ry), (rx, -ry + 0.1), (rx, ry)]
                )
            )
        )
        self.b2body.fixtures[-1].filterData.categoryBits = B2SMTH | B2ACTOR
        self.b2body.CreateFixture(
            b2.b2FixtureDef(shape=b2.b2EdgeShape(vertex1=(-rx, -ry), vertex2=(rx, -ry)), isSensor=True)
        )
        self.b2body.fixtures[-1].filterData.categoryBits = B2GNDSENS
        self.b2body.fixtures[-1].filterData.maskBits = B2LEVEL | B2ACTOR
        self.world.addEventHandler(self.b2body.fixtures[-1], self.on_ground_begin, self.on_ground_end)

    def use_item(self, item_type, trigger, args):  # MAIN or SECONDARY
        if item_type is MAIN:
            item = self.inventory.main_item
        else:
            item = self.inventory.secondary_item

        if not item:
            return
        if trigger and not item.on_use and item.available:
            item.start_use(*args)
        elif trigger and item.on_use and item.available:
            item.continue_use(*args)
        elif not trigger and item.on_use and item.available:
            item.end_use(*args)

    def start_interact_with_item(self, item):
        if item and item.item_update:
            self.schedule(item.item_update)

    def stop_interact_with_item(self, item):
        if item and item.item_update:
            self.unschedule(item.item_update)

    def collide(self, other):
        other._collide_actor(self)

    def _collide_actor(self, other):
        coll.collide_actor_actor(self, other)

    def _collide_hit_zone(self, other):
        coll.collide_actor_hit_zone(self, other)

    def _collide_slash(self, other):
        coll.collide_actor_slash(self, other)

    def activate_trigger(self, trigger):
        self.dispatch_event("on_activate_trigger", trigger, self)

    def put_item(self, item):
        self.inventory.put_item(item)

    def open(self):
        self.inventory.open()

    def close(self):
        self.inventory.close()

    def destroy(self):
        """
        Remove Actor from level
        """
        if self.fight_group > 0:
            for armor in filter(lambda x: (x.attached is not None), self.body.body_parts):
                armor.attached.drop()
            self.fight_group = -1
#.........这里部分代码省略.........
开发者ID:Ecialo,项目名称:Codename-Parzalon,代码行数:103,代码来源:actor.py


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