Пример #1
0
        /// <summary>
        /// Converts a rectangle to a array of new tiles
        /// </summary>
        /// <param name="rectangle">The source rectangle to copy tiles from</param>
        /// <param name="width">The width of the source tileset</param>
        /// <returns>A new tile brush</returns>
        public static GMareBrush RectangleToTileBrush(Rectangle rectangle, int width, Size tileSize)
        {
            GMareBrush brush = new GMareBrush();

            // Position variables
            int x = 0;
            int y = 0;

            // Calculate columns and rows
            int cols = rectangle.Width / tileSize.Width;
            int rows = rectangle.Height / tileSize.Height;

            // Create a new tile id array
            GMareTile[,] tiles = new GMareTile[cols, rows];

            // Iterate through columns
            for (int col = 0; col < cols; col++)
            {
                // Iterate through rows
                for (int row = 0; row < rows; row++)
                {
                    // Calculate tile position.
                    x = (col * tileSize.Width) + rectangle.X;
                    y = (row * tileSize.Height) + rectangle.Y;

                    // Create new tile
                    GMareTile tile = new GMareTile();
                    tile.TileId = PositionToSourceTileId(x, y, width, tileSize);

                    // Set tile
                    tiles[col, row] = tile;
                }
            }

            // Set brush properties
            brush.Tiles  = tiles;
            brush.StartX = rectangle.X;
            brush.StartY = rectangle.Y;
            brush.EndX   = rectangle.Right;
            brush.EndY   = rectangle.Bottom;

            return(brush);
        }
Пример #2
0
        /// <summary>
        /// Creates a new copy of this brush
        /// </summary>
        /// <returns>A new brush copy</returns>
        public GMareBrush Clone()
        {
            GMareBrush brush = (GMareBrush)this.MemberwiseClone();

            brush.Glyph        = _glyph == null ? null : (Bitmap)_glyph.Clone();
            GMareTile[,] tiles = new GMareTile[_tiles.GetLength(0), _tiles.GetLength(1)];

            // Deep clone
            for (int x = 0; x < _tiles.GetLength(0); x++)
            {
                for (int y = 0; y < _tiles.GetLength(1); y++)
                {
                    tiles[x, y] = _tiles[x, y].Clone();
                }
            }

            brush.Tiles = tiles;
            return(brush);
        }
Пример #3
0
        /// <summary>
        /// Searches the brush to see if it contains the given tile id
        /// </summary>
        /// <param name="tileId">The given tile id to search for</param>
        /// <returns>If the brush contains the given tile id</returns>
        public bool Same(GMareBrush brush)
        {
            // If the sizes don't match, they brushes do not match
            if (brush.Tiles.GetLength(0) != _tiles.GetLength(0) ||
                brush.Tiles.GetLength(1) != _tiles.GetLength(1))
            {
                return(false);
            }

            // Iterate through tile ids
            for (int row = 0; row < _tiles.GetLength(1); row++)
            {
                for (int col = 0; col < _tiles.GetLength(0); col++)
                {
                    if (brush.Tiles[col, row].TileId != _tiles[col, row].TileId)
                    {
                        return(false);
                    }
                }
            }

            // Tiles match
            return(true);
        }