A Sphere map layer.
Exemple #1
0
        /// <summary>
        /// Creates a proper Sphere from a data stream.
        /// </summary>
        /// <param name="reader">BinaryReader to use.</param>
        /// <returns>Sphere Layer object.</returns>
        public static Layer FromBinary(BinaryReader reader)
        {
            Layer layer = new Layer
                {
                    Width = reader.ReadInt16(),
                    Height = reader.ReadInt16(),
                    Flags = reader.ReadInt16()
                };

            layer.Visible = (~layer.Flags & 1) == 1;
            layer.Parallax = (layer.Flags & 2) == 2;
            layer.ParallaxX = reader.ReadSingle();
            layer.ParallaxY = reader.ReadSingle();
            layer.ScrollX = reader.ReadSingle();
            layer.ScrollY = reader.ReadSingle();
            int segs = reader.ReadInt32();
            layer.Reflective = reader.ReadBoolean();
            reader.ReadBytes(3); // reserved

            short length = reader.ReadInt16();
            layer.Name = new string(reader.ReadChars(length));

            layer._tiles = new TwoArray<short>(layer.Width, layer.Height);
            for (int i = 0, size = layer.Width*layer.Height; i < size; ++i)
                layer._tiles.Array[i] = reader.ReadInt16();

            for (int i = 0; i < segs; ++i) layer.Segments.Add(new Segment(reader));
            return layer;
        }
Exemple #2
0
        /// <summary>
        /// Creates a new map with values.
        /// </summary>
        /// <param name="width">The width in tiles.</param>
        /// <param name="height">The height in tiles.</param>
        /// <param name="tileWidth">The tilewidth in pixels.</param>
        /// <param name="tileHeight">The tileheight in pixels.</param>
        /// <param name="tilesetPath">The path to the tileset.</param>
        public void CreateNew(short width, short height, short tileWidth, short tileHeight, string tilesetPath)
        {
            for (int i = 0; i < 9; ++i) Scripts.Add("");

            // create a base layer:
            Layer layer = new Layer();
            layer.CreateNew(width, height);
            Layers.Add(layer);

            // create a starting tile:
            Tileset = new Tileset();

            if (string.IsNullOrEmpty(tilesetPath))
                Tileset.CreateNew(tileWidth, tileHeight);
            else
            {
                Tileset = Tileset.FromFile(tilesetPath);
                Scripts[0] = Path.GetFileName(tilesetPath);
            }
        }