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


Python Inventory.get_items方法代码示例

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


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

示例1: InventorySelector

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import get_items [as 别名]
class InventorySelector(AbstractInventory):
    def __init__(self, parent, player, world, *args, **kwargs):
        super(InventorySelector, self).__init__(parent, *args, **kwargs)
        self.amount_labels = []
        self.parent = parent
        self.world = world
        self.player = player
        self.max_items = self.player.inventory.slot_count
        self.current_index = 1
        self.icon_size = self.world.group.texture.width / G.TILESET_SIZE
        self.selected_item = None
        self.selected_item_icon = None
        self.mode = 0 # 0 - Normal inventory, 1 - Crafting Table, 2 - Furnace
        self.change_image()
        self.crafting_panel = Inventory(4)
        self.crafting_outcome = None  # should be an item stack
        self.crafting_outcome_icon = None
        self.crafting_outcome_label = None
        self.crafting_table_panel = Inventory(9)
        self.furnace_panel = None   # should be a FurnaceBlock
        self.visible = False

    def change_image(self):
        if self.mode == 0:
            image = load_image('resources', 'textures', 'inventory.png')
        elif self.mode == 1:
            image = load_image('resources', 'textures', 'inventory_when_crafting_table.png')
        elif self.mode == 2:
            image = load_image('resources', 'textures', 'inventory_when_furnace.png')
        self.frame = image_sprite(image, self.batch, 0)
        self.frame.x = (self.parent.window.width - self.frame.width) / 2
        self.frame.y = self.icon_size / 2 - 4

    def update_items(self):
        rows = floor(self.max_items / 9)
        inventory_y = 43
        inventory_height = (rows * (self.icon_size * 0.5)) + ((rows+1) * 3)
        self.icons = []
        for amount_label in self.amount_labels:
            amount_label.delete()
        self.amount_labels = []
        x = self.frame.x + 7
        y = self.frame.y + inventory_y + inventory_height
        items = self.player.inventory.get_items()
        items = items[:self.max_items]
        for i, item in enumerate(items):
            if not item:
                x += (self.icon_size * 0.5) + 3
                if x >= (self.frame.x + self.frame.width) - 7:
                    x = self.frame.x + 7
                    y -= (self.icon_size * 0.5) + 3
                continue
            icon = image_sprite(get_block_icon(item.get_object(), self.icon_size, self.world), self.batch, self.group)
            icon.scale = 0.5
            icon.x = x
            icon.y = y - icon.height
            x += (self.icon_size * 0.5) + 3
            if x >= (self.frame.x + self.frame.width) - 7:
                x = self.frame.x + 7
                y -= (self.icon_size * 0.5) + 3
            if item.max_durability != -1 and item.durability != -1:
                icon.opacity = min(item.max_durability, item.durability + 1) * 255 / item.max_durability
            amount_label = pyglet.text.Label(
                str(item.amount), font_name=G.DEFAULT_FONT, font_size=9,
                x=icon.x + 3, y=icon.y, anchor_x='left', anchor_y='bottom',
                color=item.get_object().amount_label_color, batch=self.batch,
                group=self.labels_group)
            self.amount_labels.append(amount_label)
            self.icons.append(icon)

        items = self.player.quick_slots.get_items()
        items = items[:self.player.quick_slots.slot_count]
        for i, item in enumerate(items):
            if not item:
                x += (self.icon_size * 0.5) + 3
                continue
            icon = image_sprite(get_block_icon(item.get_object(), self.icon_size, self.world), self.batch, self.group)
            icon.scale = 0.5
            icon.x = x
            icon.y = self.frame.y + 7
            item.quickslots_x = icon.x
            item.quickslots_y = icon.y
            x += (self.icon_size * 0.5) + 3
            if item.max_durability != -1 and item.durability != -1:
                icon.opacity = min(item.max_durability, item.durability + 1) * 255 / item.max_durability
            amount_label = pyglet.text.Label(
                str(item.amount), font_name=G.DEFAULT_FONT, font_size=9,
                x=icon.x + 3, y=icon.y, anchor_x='left', anchor_y='bottom',
                color=item.get_object().amount_label_color, batch=self.batch,
                group=self.labels_group)
            self.amount_labels.append(amount_label)
            self.icons.append(icon)

        items = self.player.armor.get_items()
        items = items[:4]
        x = self.frame.x + 7
        y = inventory_y + inventory_height + 10 + 4 * self.icon_size * 0.5 + 9
        for i, item in enumerate(items):
            if not item:
                y -= (self.icon_size * 0.5) + 3
#.........这里部分代码省略.........
开发者ID:ronmurphy,项目名称:Minecraft,代码行数:103,代码来源:gui.py

示例2: __init__

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import get_items [as 别名]
class Player:

    def __init__(self):
        """
        Initializing our player with his initial stats
        These are what I feel players should start out with
        Hans' stats vary within the game
        :return:
        """
        self.level = 1
        self.stats = {'str': 12, 'mag': 1, 'skill': 13, 'spd': 13, 'def': 15, 'lck': 12, 'res': 4}
        self.growths = {'hp': 0.8, 'str': 0.6, 'mag': 0.2, 'skill': 0.7, 'spd': 0.7, 'def': 0.6, 'luk': 0.3, 'res': 0.3}
        self.hp = 30
        self.max_hp = 30
        self.name = "Hans"
        self.inventory = Inventory()
        self.equipped = self.inventory.get_specific_item("Steel Axe")
        self.loc = (1, 1)

    def receive_damage(self, damage):
        """
        Receiving damage to the player
        :param damage: total damage being received
        :return:
        """
        dmg = max(0, damage - self.stats['def'])
        self.hp = max(0, self.hp-dmg)

    def attack(self, defense):
        """
        Returns the damage dealt to an enemy
        If the player is not equipped with anything, simply return 0
        :param def: opposing enemy's def
        :return: damage dealt
        """
        if self.equipped:
            return self.stats['str'] + self.equipped.mt - defense
        return 0

    def equip_item(self, item):
        """
        Equips an item. Has to be a weapon
        :param item: weapon to equip
        :return:
        """
        if isinstance(item, Weapon) and item.name in self.inventory.get_items():
            self.equipped = item

    def add_to_inventory(self, item):
        """
        Adds an item to the inventory
        Following Fates, we only allow 5 item slots
        :param item: item to add to inventory
        :return:
        """
        return self.inventory.add_to_inventory(item)

    def remove_from_inventory(self, item):
        """
        Removes an item from an inventory
        TODO: find a good way to remove an item after using a healing item
        :param item: item to be removed
        :return:
        """
        if item.name in self.inventory.get_items():
            self.inventory.remove_from_inventory(item)

    def inc_max_hp(self, amount):
        """
        Increases the max hp, mostly from leveling up or items
        :param amount: amount to increase by
        :return:
        """
        self.max_hp += amount

    def use_item(self, item):
        """
        Usage of an item, must not be a weapon
        :param item:
        :return:
        """
        if item.name in self.inventory.get_items():
            if item.usage == "HEALING":
                self.hp = min(self.max_hp, self.hp+item.amount)
            if item.usage == "SERAPH":
                self.inc_max_hp(item.amount)

    def set_location(self, location):
        """
        Sets the location of the player
        :param location: location to set
        :return:
        """
        self.loc = location
开发者ID:dguan4,项目名称:HanStory,代码行数:96,代码来源:player.py


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