A Sphere Tile object.
예제 #1
0
파일: Tile.cs 프로젝트: Radnen/spherestudio
 /// <summary>
 /// Creates a perfect clone of this Tile.
 /// </summary>
 /// <returns>A copy of the Tile object.</returns>
 public Tile Clone()
 {
     Tile newTile = new Tile((Bitmap) _graphic.Clone()) {Name = Name};
     return newTile;
 }
예제 #2
0
        /// <summary>
        /// Updates graphics From a tileset image file.
        /// </summary>
        /// <param name="filename"></param>
        public void UpdateFromImage(string filename)
        {
            Bitmap img = (Bitmap)Image.FromFile(filename);
            Rectangle rect = new Rectangle(0, 0, TileWidth, TileHeight);

            int index = 0;
            for (int y = 0; y < img.Height; y += TileHeight)
            {
                rect.Y = y;
                for (int x = 0; x < img.Width; x += TileWidth, index++)
                {
                    rect.X = x;
                    if (index < Tiles.Count)
                    {
                        Tiles[index].Graphic.Dispose();
                        Tiles[index].Graphic = img.Clone(rect, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                    }
                    else
                    {
                        Tile t = new Tile(img.Clone(rect, System.Drawing.Imaging.PixelFormat.Format32bppPArgb));
                        Tiles.Add(t);
                    }
                }
            }

            img.Dispose();
        }
예제 #3
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;
        }
예제 #4
0
 private void AddTiles(short start, short count)
 {
     List<Tile> added = new List<Tile>(count);
     Tile t;
     for (short i = 0; i < count; ++i)
     {
         t = new Tile(_tileset.TileWidth, _tileset.TileHeight);
         _tileset.Tiles.Insert(start + i, t);
         added.Add(t);
     }
     UpdateHeight();
     Invalidate();
     if (TileAdded != null) TileAdded(start, added);
 }