Пример #1
0
        /// <summary>
        /// Grabs all the tiles in the selected area
        /// </summary>
        /// <param name="area">The area to grab the tiles, must be multiple of the tile width and height.</param>
        /// <param name="clone">Determines if the result should use cloned tiles</param>
        /// <returns>The matrix of the tiles that were found. This result may contain null positions in case you select areas that aren't fully filled.</returns>
        public Tile[,] GrabTiles(Rectangle area, bool clone)
        {
            Rectangle _area;
            if ((_area = WorldAreaToMatrix(area)) == Rectangle.Empty)
                return null;

            Tile[,] result = new Tile[_area.Width, _area.Height];

            for (int x = _area.X; x < _area.X + _area.Width; x++)
            {
                for (int y = _area.Y; y < _area.Y + _area.Height; y++)
                {
                    if (tiles[x, y] != null)
                        result[x - _area.X, y - _area.Y] = tiles[x, y].DeepCopy();
                }
            }

            return result;
        }
Пример #2
0
        /// <summary>
        /// Removes tiles from a selected area (world position)
        /// </summary>
        /// <param name="area">The area (world position) you want to have tiles removed</param>
        /// <returns>The removed tiles</returns>
        public Tile[,] RemoveTiles(Rectangle area)
        {
            Rectangle _area;
            if ((_area = WorldAreaToMatrix(area)) == Rectangle.Empty)
                return null;

            //Console.WriteLine("valido {0}", endPos);
            Tile[,] result = new Tile[_area.Width, _area.Height];

            //Console.WriteLine(result.GetLength(0) + ":" + result.GetLength(1));

            for (int x = _area.X; x < _area.X + _area.Width; x++)
            {
                for (int y = _area.Y; y < _area.Y + _area.Height; y++)
                {
                    if (tiles[x, y] != null)
                        result[x - _area.X, y - _area.Y] = tiles[x, y].DeepCopy();

                    tiles[x, y] = null;
                }
            }

            needsRefresh = true;

            return result;
        }
Пример #3
0
 /// <summary>
 /// Places a matrix of tiles
 /// </summary>
 /// <param name="newTiles">The tiles to place</param>
 /// <param name="startingPosition">The starting position (world position)</param>
 public void PlaceTiles(Tile[,] newTiles, Vector2 startingPosition)
 {
     for (int x = 0; x < newTiles.GetLength(0); x++)
     {
         for (int y = 0; y < newTiles.GetLength(1); y++)
         {
             if (newTiles[x, y] != null)
             {
                 PlaceTile(
                     new Vector2(newTiles[x, y].Source.X, newTiles[x, y].Source.Y),
                     new Vector2(startingPosition.X + (x * tileWidth), startingPosition.Y + (y * tileHeight)));
             }
         }
     }
 }
Пример #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="newWidth"></param>
        /// <param name="newHeight"></param>
        public void ResizeTileset(int newWidth, int newHeight)
        {
            Tile[,] newTileset = new Tile[newWidth, newHeight];

            // smart update:
            for (int x = 0; x < newWidth; x++)
            {
                for (int y = 0; y < newHeight; y++)
                {
                    Vector2 relativePosition;

                    relativePosition.X = (newWidth < Width) ?
                        (x + (Width / 2 - newWidth / 2)) : (x - (newWidth / 2 - Width / 2));

                    relativePosition.Y = (newHeight < Height) ?
                        (y + (Height / 2 - newHeight / 2)) : (y - (newHeight / 2 - Height / 2));

                    if (ValidPosition(relativePosition))
                    {
                        newTileset[x, y] = tiles[(int)relativePosition.X, (int)relativePosition.Y];
                    }
                }
            }

            needsRefresh = true;

            this.tiles = newTileset;
        }
Пример #5
0
        /// <summary>
        /// Deep Copy
        /// </summary>
        /// <returns>A new array of the tiles in this tileset</returns>
        public Tile[,] DeepCopy()
        {
            Tile[,] result = new Tile[tiles.GetLength(0), tiles.GetLength(1)];

            for (int x = 0; x < tiles.GetLength(0); x++)
            {
                for (int y = 0; y < tiles.GetLength(1); y++)
                {
                    if (tiles[x, y] != null)
                        result[x, y] = tiles[x, y].DeepCopy();
                }
            }

            return result;
        }
Пример #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="change"></param>
 /// <param name="element"></param>
 public TilesetCommand(Tile[,] change, Tile[,] before, Tileset element)
 {
     _change = change;
     _element = element;
     _beforeChange = before;
 }