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


Python Images.make_itemdrop_image方法代码示例

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


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

示例1: load_blocks

# 需要导入模块: import Images [as 别名]
# 或者: from Images import make_itemdrop_image [as 别名]
def load_blocks():
    blocks_file = open("blocks.json", "r")
    global blocks
    blocks = json.load(blocks_file)["blocks"]
    blocks_file.close()
    
    water_image = pygame.image.load("img/water.png")
    st_water_image = water_image.copy()
    st_water_image.set_alpha(128)
    pygame.display.set_icon(water_image) #TODO: change the icon to something better
    
    bid = 0
    global block_images
    block_images = {False:{}, True:{}}
    global ctm_block_images
    ctm_block_images = {False:{}, True:{}}
    for block in blocks:
        #set some default attributes
        if "breakable" not in block.keys():
            block["breakable"] = True
        if "connectedTexture" not in block.keys():
            block["connectedTexture"] = None
        if "solid" not in block.keys():
            block["solid"] = True
        if "entity" not in block.keys():
            block["entity"] = ""
        if "item" not in block.keys():
            block["item"] = "ItemStack"
        if "description" not in block.keys():
            block["description"] = [""]
        if "harvestlevel" not in block.keys():
            block["harvestlevel"] = 0
        if "breaktime" not in block.keys():
            block["breaktime"] = 100
        if "image" not in block.keys():
            block["image"] = ""
        #add an id to the block
        block["id"] = bid
        global block_mappings
        block_mappings[block["name"]] = bid
        global id_mappings
        id_mappings[bid] = block["name"]
        
        if isinstance(block["description"], str):
            block["description"] = [block["description"]]
        
        #load the block image
        path = block["image"]
        if path != "":
            blockimg = pygame.image.load(path).convert_alpha()
            if block["connectedTexture"]:
                icon = pygame.Surface((Game.BLOCK_SIZE, Game.BLOCK_SIZE), pygame.SRCALPHA, 32)
                icon = icon.convert_alpha()
                icon.blit(blockimg, (0, 0))
            else:
                icon = blockimg.copy()
            item_images[block["name"]] = [Images.make_itemdrop_image(icon)]
            foreground_image = Images.scale(blockimg, Game.SCALE)
            block_images[False][bid] = Images.crop(foreground_image)
            #blit the image onto the water tile so it isn't just empty transparency
            image = blockimg.copy()
            for x in range(image.get_width() // Game.BLOCK_SIZE):
                for y in range(image.get_height() // Game.BLOCK_SIZE):
                    image.blit(water_image, (x * Game.BLOCK_SIZE, y * Game.BLOCK_SIZE))
            image.blit(blockimg, (0, 0))
            for x in range(image.get_width() // Game.BLOCK_SIZE):
                for y in range(image.get_height() // Game.BLOCK_SIZE):
                    image.blit(st_water_image, (x * Game.BLOCK_SIZE, y * Game.BLOCK_SIZE))
            background_image = Images.scale(image, Game.SCALE)
            block_images[True][bid] = background_image
            if block["connectedTexture"]:
                ctm_block_images[False][bid] = {}
                ctm_block_images[True][bid] = {}
                for x in range(4):
                    for y in range(4):
                        foreground_surf = pygame.Surface((Game.BLOCK_SIZE * Game.SCALE, Game.BLOCK_SIZE * Game.SCALE)).convert_alpha()
                        foreground_surf.fill((0, 0, 0, 0))
                        background_surf = foreground_surf.copy()
                        foreground_surf.blit(foreground_image, (0, 0),
                            pygame.Rect((x * Game.BLOCK_SIZE * Game.SCALE, y * Game.BLOCK_SIZE * Game.SCALE),
                                 (Game.BLOCK_SIZE * Game.SCALE, Game.BLOCK_SIZE * Game.SCALE)))
                        ctm_block_images[False][bid][(x, y)] = foreground_surf
                        background_surf.blit(background_image, (0, 0),
                            pygame.Rect((x * Game.BLOCK_SIZE * Game.SCALE, y * Game.BLOCK_SIZE * Game.SCALE),
                                 (Game.BLOCK_SIZE * Game.SCALE, Game.BLOCK_SIZE * Game.SCALE)))
                        ctm_block_images[True][bid][(x, y)] = background_surf
        #make the corresponding item
        items[block["name"]] = {"displayName": block["displayName"],
                                "image": block["image"],
                                "class": block["item"],
                                "description": block["description"],
                                "can_place": True}
        bid += 1
    block_images[False][get_block_id("water")] = pygame.Surface((Game.BLOCK_SIZE, Game.BLOCK_SIZE), pygame.SRCALPHA, 32)
开发者ID:kaikue,项目名称:Oceania,代码行数:96,代码来源:World.py


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