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


Python Level.load方法代码示例

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


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

示例1: load

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import load [as 别名]
    def load(self, filename, data):
        self._filename = filename
        self._world_index = int(os.path.basename(filename)[1]) - 1

        stream = StreamRead.from_file(filename, Endianness.BIG)

        self._offset_tile_gfx = stream.read_uint() - WORLD_BASE_OFFSET
        self._offset_tile_collision = stream.read_uint() - WORLD_BASE_OFFSET
        self._offset_palette = stream.read_uint() - WORLD_BASE_OFFSET
        self._offset_u1 = stream.read_uint() - WORLD_BASE_OFFSET
        self._offset_u2 = stream.read_uint() - WORLD_BASE_OFFSET

        if self._offset_tile_gfx > stream.size or self._offset_tile_collision > stream.size or self._offset_palette > stream.size:
            raise Exception('"{}" is not a valid world file.'.format(filename))

        # Read level header offsets.
        level_count = stream.read_ushort()
        self._level_offsets = []
        for _ in range(0, level_count):
            self._level_offsets.append(stream.read_uint() - WORLD_BASE_OFFSET)

        # Read level headers.
        self._levels = []
        for level_index, offset in enumerate(self._level_offsets):
            stream.seek(offset)

            level = Level(self._world_index, level_index)
            level.name = '{}-{}: {}'.format(self._world_index + 1, level_index + 1, data[level_index]['name'])
            level.maximum_blockmap_size = data[level_index]['blockmap_size']
            level.load_header(stream)
            self._levels.append(level)

        # Read the world palette.
        stream.seek(self._offset_palette)
        self._palette = Palette.from_stream(stream, 16, 4)

        # Read tileset.
        self._tileset = TileSet.from_stream(stream, self._offset_tile_gfx, self._offset_tile_collision, self._palette)

        # Read level data.
        for level_index, level in enumerate(self._levels):
            if level_index > 0:
                game_dir = os.path.dirname(filename)
                level_file = 'L{}-{}'.format(self._world_index + 1, level_index + 1)
                level_file = os.path.join(game_dir, level_file)
                stream.insert(level_file, level.data_offset)

            if self._world_index == 2 and level_index == 1:
                offset = 19620
            else:
                offset = 0

            level.load(stream, offset)
开发者ID:GitExl,项目名称:Turrican2Editor,代码行数:55,代码来源:world.py

示例2: _setup

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import load [as 别名]
 def _setup(self):
     self._load_resources()
     
     level = Level(self.IMAGE_CACHE)
     level.load("test", "test.txt")
     self.background = level.draw()
     self.screen.blit(self.background, (0, 0))
     
     self.sprites = pygame.sprite.RenderUpdates()
     self.player = Player(image=self.IMAGE_CACHE['sprites'], pos=level.player_spawn(), frame=(0, 1))
     self.sprites.add(self.player)
     
     pygame.display.flip()
开发者ID:jakebarnwell,项目名称:PythonGenerator,代码行数:15,代码来源:game.py


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