A sphree Tileset object.
Inheritance: IDisposable
        public void Refresh(Layer target, Tileset tileset, bool shownums = false)
        {
            if (tileset.IsDisposed) return;

            TargetLayer = target;
            for (int i = 0; i < _cells.Length; ++i) _cells[i].Redraw(target, tileset);
        }
Exemple #2
0
        /// <summary>
        /// Loads a tileset from a filestream.
        /// </summary>
        /// <param name="reader">The System.IO.BinrayReader to use.</param>
        /// <returns>A tileset object.</returns>
        public static Tileset FromBinary(BinaryReader reader)
        {
            Tileset ts = new Tileset();
            reader.ReadChars(4); // sign
            ts._version = reader.ReadInt16();  // version
            short numTiles = reader.ReadInt16();
            ts.TileWidth = reader.ReadInt16();
            ts.TileHeight = reader.ReadInt16();
            reader.ReadInt16(); // tile_bpp
            ts._compression = reader.ReadByte();
            ts._hasObstruct = reader.ReadByte();
            reader.ReadBytes(240);

            using (BitmapLoader loader = new BitmapLoader(ts.TileWidth, ts.TileHeight))
            {
                int bitSize = ts.TileWidth * ts.TileHeight * 4;

                while (numTiles-- > 0)
                {
                    Tile newTile = new Tile(ts.TileWidth, ts.TileHeight);
                    newTile.Graphic = loader.LoadFromStream(reader, bitSize);
                    ts.Tiles.Add(newTile);
                }
            }

            foreach (Tile t in ts.Tiles)
            {
                reader.ReadByte();
                t.Animated = reader.ReadBoolean();
                t.NextAnim = reader.ReadInt16();
                t.Delay = reader.ReadInt16();
                reader.ReadByte();
                t.Blocked = reader.ReadByte();
                int segs = reader.ReadInt16();
                int amt = reader.ReadInt16();
                reader.ReadBytes(20);
                t.Name = new string(reader.ReadChars(amt));
                while (segs-- > 0)
                {
                    Line l = new Line(reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16());
                    t.Obstructions.Add(l);
                }
            }

            return ts;
        }
Exemple #3
0
        /// <summary>
        /// Takes the images of a spriteset and creates a ileset representation of it.
        /// </summary>
        /// <param name="set">The spriteset to use.</param>
        /// <returns>A tileset of the spritesets images.</returns>
        public static Tileset FromSpriteset(Spriteset set)
        {
            Tileset tileset = new Tileset();
            foreach (Bitmap image in set.Images)
                tileset.Tiles.Add(new Tile(image));

            tileset.TileWidth = set.SpriteWidth;
            tileset.TileHeight = set.SpriteHeight;

            return tileset;
        }
 public void Refresh(Tileset tileset)
 {
     if (tileset.IsDisposed) return;
     for (int i = 0; i < _cells.Length; ++i) _cells[i].Redraw(TargetLayer, tileset);
 }
            public void Redraw(Layer layer, Tileset tileset)
            {
                if (_canvas == null) return;

                int tile, tx, ty;
                for (int x = 0; x < _mul; ++x)
                {
                    tx = x * _tile_w;
                    for (int y = 0; y < _mul; ++y)
                    {
                        tile = layer.GetTile(x + Offset.X, y + Offset.Y);
                        if (tile < 0) continue;

                        ty = y * _tile_h;
                        _canvas.DrawImageUnscaled(tileset.Tiles[tile].Graphic, tx, ty);
                    }
                }
            }
            public void Allocate(Layer layer, Tileset tileset)
            {
                if (_canvas != null) return;

                Image = new Bitmap(_mul * _tile_w, _mul * _tile_h, PixelFormat.Format32bppPArgb);
                _canvas = Graphics.FromImage(Image);
                _canvas.CompositingMode = CompositingMode.SourceCopy;
                _canvas.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
                _canvas.SmoothingMode = SmoothingMode.None;
                _canvas.CompositingQuality = CompositingQuality.HighSpeed;
                _canvas.InterpolationMode = InterpolationMode.NearestNeighbor;

                Redraw(layer, tileset);
            }
        // determines which cells to load up:
        public void Update(ref Point offset, Size bounds, Tileset tileset)
        {
            if (tileset.IsDisposed) return;

            int cell_x = _tile_w * _zoom, cell_y = _tile_h * _zoom;
            int size = _mul * _tile_w * _zoom;
            foreach (LayerCell cell in _cells)
            {
                int x = cell.Offset.X * cell_x + offset.X;
                int y = cell.Offset.Y * cell_y + offset.Y;

                if (x < -size || y < -size || x > bounds.Width || y > bounds.Height)
                    cell.Deallocate();
                else
                    cell.Allocate(TargetLayer, tileset);
            }
        }
Exemple #8
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);
            }
        }