本文整理汇总了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)
示例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()