Ejemplo n.º 1
0
        /// <summary>
        /// Fills in tile sections with the desired brush.
        /// </summary>
        /// <param name="origin">The starting point for the fill, in tiles.</param>
        /// <param name="tiles">The array of tiles to fill with.</param>
        public void Fill(Point origin, GMareTile[,] tiles)
        {
            // If the origin is out of bounds, return.
            if (origin.X < 0 || origin.X >= _tiles2.GetLength(0) || origin.Y < 0 || origin.Y >= _tiles2.GetLength(1))
                return;

            // Get target tile.
            int target = _tiles2[origin.X, origin.Y].TileId;

            // Get the valid fill array.
            bool[,] mask = this.GetFillMask(origin, target);

            // Calculate fill start offsets.
            int offsetX = origin.X % tiles.GetLength(0);
            int offsetY = origin.Y % tiles.GetLength(1);

            // If the offsetX is not zero, adjust offsetX origin.
            if (offsetX != 0)
                offsetX = tiles.GetLength(0) - offsetX;

            // If the offsetY is not zero, adjust offsetY origin.
            if (offsetY != 0)
                offsetY = tiles.GetLength(1) - offsetY;

            // Selection indexers, start them at the offsets.
            int x = offsetX;
            int y = offsetY;

            // Iterate through layer columns.
            for (int col = 0; col < _tiles2.GetLength(0); col++)
            {
                // Iterate through layer rows.
                for (int row = 0; row < _tiles2.GetLength(1); row++)
                {
                    // If the coordinate values are allowed by the mask and equal the target, replace the tile.
                    if (mask[col, row] == true && _tiles2[col, row].TileId == target)
                        _tiles2[col, row] = tiles[x, y].Clone();

                    // Increment selection's row index.
                    y++;

                    // If at the max height of the tile selection, reset row index.
                    if (y == tiles.GetLength(1))
                        y = 0;

                    // If at the max height of the layer, reset row index to offsetY.
                    if (row == _tiles2.GetLength(1) - 1)
                        y = offsetY;
                }

                // Increment selection's column index.
                x++;

                // If at the max width of the tile selection, reset column index.
                if (x == tiles.GetLength(0))
                    x = 0;

                // If at the max width of the layer, reset column index to offsetX.
                if (col == _tiles2.GetLength(0) - 1)
                    x = offsetX;
            }
        }
Ejemplo n.º 2
0
        /// <summary> 
        /// Get a selection of tiles from the selected layer.
        /// </summary>
        /// <param name="grid">The grid to use for selection data.</param>
        /// <returns>An array of tiles.</returns>
        private GMareTile[,] GetTiles(GMareBrush grid)
        {
            // A new array of tile ids.
            Rectangle rect = grid.ToRectangle();
            Size tileSize = ProjectManager.Room.TileSize;
            GMareTile[,] tiles = new GMareTile[rect.Width / tileSize.Width, rect.Height / tileSize.Height];

            // Iterate through columns.
            for (int col = 0; col < tiles.GetLength(0); col++)
            {
                // Iterate through rows.
                for (int row = 0; row < tiles.GetLength(1); row++)
                {
                    // Calculate source position.
                    int x = ((col * tileSize.Width) + rect.X) / tileSize.Width;
                    int y = ((row * tileSize.Height) + rect.Y) / tileSize.Height;

                    // Set tile id.
                    tiles[col, row] = ProjectManager.Room.Layers[_layerIndex].Tiles2[x, y].Clone();
                }
            }

            // Return selected tiles.
            return tiles;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a new GMare Layer, with name, depth and tile data.
        /// </summary>
        /// <param name="name">The name of the layer.</param>
        /// <param name="depth">The depth of the layer.</param>
        /// <param name="tiles">The tiles for the layer.</param>
        public GMareLayer(string name, int depth, GMareTile[,] tiles)
        {
            // Set fields.
            _name = name;
            _depth = depth;
            _tiles2 = new GMareTile[tiles.GetLength(0), tiles.GetLength(1)];

            // Iterate through tiles.
            for (int y = 0; y < _tiles2.GetLength(1); y++)
                for (int x = 0; x < _tiles2.GetLength(0); x++)
                    _tiles2[x, y] = tiles[x, y].Clone();
        }