Exemple #1
0
        public static TileSet loadTileSet(RabbitPlatform game, string setFileName)
        {
            TileSetInfo info;
            TileSet     ts;
            TileSetFile file = new TileSetFile(setFileName);

            TileMask[] masks;

            if (file.ReadMagic() != "TS")
            {
                throw new FileLoadException("Wrong file format!", file.path);
            }

            info  = new TileSetInfo(file.ReadUInt32(), file.ReadUInt32(), file.ReadByte());
            masks = new TileMask[info.Width * info.Height];
            Texture2D texture = TileGraphicsFilePart.fromStream(game, file.BaseStream);

            for (int y = 0; y < info.Height; y++)
            {
                for (int x = 0; x < info.Width; x++)
                {
                    masks[x + y * info.Width] = TileMaskFilePart.fromStream(file.BaseStream);
                }
            }

            ts = TileSet.loadFromTexture(texture, info, masks);
            return(ts);
        }
Exemple #2
0
        public static Level loadLevel(RabbitPlatform game, string levelName, bool editor = false)
        {
            if (game.CurrentWorld == null)
            {
                throw new NullReferenceException("You are unable to load level when without any world.");
            }

            LevelFile file = new LevelFile(levelName);

            if (file.ReadMagic() != "LV")
            {
                throw new FormatException();
            }

            //if (!editor)
            //    world = new World(game);
            //else
            //    world = new Editor.EditorWorld(game);

            string  tileset = file.ReadString();
            TileSet ts      = TileSetFile.loadTileSet(game, tileset);

            ushort layers   = file.ReadUInt16();
            ushort entLayer = file.ReadUInt16();

            Level level = new Level(game.CurrentWorld, layers, entLayer);

            //world.prepareWorld(layers, entLayer);
            TileMapInfo info;

            for (int i = 0; i < layers; i++)
            {
                info = TileMapFilePart.fromStream(level, file.BaseStream, ts);
                level.initializeLayer(info, i);
            }

            //world.createWorld();

            file.Close();

            return(level);
        }