Ejemplo n.º 1
0
 private LevelRenderer(Level level, string name)
 {
     this.level = level;
     this.name = name;
     sprites = new SpriteLoader();
     result = new LevelRenderResult();
     result.Level = level;
 }
Ejemplo n.º 2
0
        public static Level LoadLevel(byte[] data, bool loadAsDiff)
        {
            var level = new Level();
            var stream = new BitStream(data);

            var buffer = new byte[6];
            stream.Read(buffer, 48);
            if (loadAsDiff)
                throw new NotImplementedException();
            if (buffer[0] != 'D' || buffer[1] != 'F' || buffer[2] != '_' || buffer[3] != 'L' || buffer[4] != 'V' || buffer[5] != 'L')
                throw new InvalidDataException();
            stream.Read(buffer, 16);
            ushort levelFormatVersion = Util.MakeU16(buffer);
            int thingCount = 0;
            if (levelFormatVersion >= 0x2b) {
                stream.Read(buffer, 32);  // ignored
                stream.Read(buffer, 32);
                thingCount = Util.MakeI32(buffer);

                LoadLevelMetadata(stream);
            }
            if (levelFormatVersion >= 0x2c) {
                stream.Read(buffer, 32);
                int thumbnailSize = Util.MakeI32(buffer);
                if (!loadAsDiff) {
                    var thumbnailBuffer = new byte[thumbnailSize];
                    stream.Read(thumbnailBuffer, thumbnailSize * 8);
                }
            }
            level.Tags = Util.ReadKeyValueList(stream);

            var itemsOffset = ((stream.BitPosition - 1) / 8 + 1) + (4 * thingCount);

            for (var t = 0; t < thingCount; ++t) {
                stream.Read(buffer, 32);
                var ptr = itemsOffset + Util.MakeI32(buffer);
                var itemBytes = Util.MakeI32(data, ptr);
                var item = new byte[itemBytes];
                Array.Copy(data, ptr, item, 0, itemBytes);
                level.Blocks.Add(LoadBlock(item));
            }

            return level;
        }
Ejemplo n.º 3
0
 public static LevelRenderResult Render(Level level, string name)
 {
     var renderer = new LevelRenderer(level, name);
     renderer.Render();
     return renderer.result;
 }
Ejemplo n.º 4
0
 public RenderedTiles(Level level, string path, Rectangle area, int layer)
 {
     Path = path;
     Area = area;
     Layer = layer;
 }