AddTile() public method

public AddTile ( Tile tile, int x, int y ) : void
tile MegaMan.Common.Tile
x int
y int
return void
Exemplo n.º 1
0
        /// <summary>
        /// Draws the brush onto the given screen at the given tile location.
        /// Returns an "undo brush" - a brush of all tiles that were overwritten.
        /// Returns null if no tiles were changed.
        /// </summary>
        public ITileBrush DrawOn(ScreenDocument screen, int tile_x, int tile_y)
        {
            TileBrush undo    = new TileBrush(Width, Height);
            bool      changed = false;

            foreach (TileBrushCell[] col in cells)
            {
                foreach (TileBrushCell cell in col)
                {
                    var old = screen.TileAt(cell.x + tile_x, cell.y + tile_y);

                    if (old == null)
                    {
                        continue;
                    }
                    undo.AddTile(old, cell.x, cell.y);
                    if (old.Id != cell.tile.Id)
                    {
                        changed = true;
                        screen.ChangeTile(cell.x + tile_x, cell.y + tile_y, cell.tile.Id);
                    }
                }
            }

            if (changed)
            {
                return(undo);
            }
            return(null);
        }
Exemplo n.º 2
0
        public void Copy()
        {
            if (ActiveSurface != null && ActiveSurface.Selection != null)
            {
                var selection = ActiveSurface.Selection.Value;
                copyBrush = new TileBrush(selection.Width, selection.Height);

                for (int ty = selection.Y; ty < selection.Bottom; ty++)
                {
                    for (int tx = selection.X; tx < selection.Right; tx++)
                    {
                        copyBrush.AddTile(ActiveSurface.Screen.TileAt(tx, ty), tx - selection.X, ty - selection.Y);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Copy()
        {
            if (ActiveSurface != null && ActiveSurface.Selection != null)
            {
                var selection = ActiveSurface.Selection.Value;
                copyBrush = new TileBrush(selection.Width, selection.Height);

                for (int ty = selection.Y; ty < selection.Bottom; ty++)
                {
                    for (int tx = selection.X; tx < selection.Right; tx++)
                    {
                        copyBrush.AddTile(ActiveSurface.Screen.TileAt(tx, ty), tx - selection.X, ty - selection.Y);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void LoadBrushes()
        {
            string dir  = System.IO.Path.GetDirectoryName(Tileset.FilePath.Absolute);
            string file = System.IO.Path.GetFileNameWithoutExtension(Tileset.FilePath.Absolute);
            string path = System.IO.Path.Combine(dir, file + "_brushes.xml");

            if (!System.IO.File.Exists(path))
            {
                return;
            }

            using (var stream = new System.IO.StreamReader(path))
            {
                while (!stream.EndOfStream)
                {
                    string line = stream.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    string[] info = line.Split(' ');

                    TileBrush brush = new TileBrush(int.Parse(info[0]), int.Parse(info[1]));

                    int x = 0; int y = 0;
                    for (int i = 2; i < info.Length; i++)
                    {
                        int id = int.Parse(info[i]);
                        if (id >= 0)
                        {
                            brush.AddTile(Tileset[id], x, y);
                        }

                        y++;
                        if (y >= brush.Height)
                        {
                            y = 0;
                            x++;
                        }
                    }

                    brushes.Add(brush);
                }
            }
        }
Exemplo n.º 5
0
        private void brushPict_MouseDown(object sender, MouseEventArgs e)
        {
            if (MainForm.Instance.CurrentBrush == null)
            {
                return;
            }

            int tx = e.X / Tileset.TileSize;
            int ty = e.Y / Tileset.TileSize;

            foreach (TileBrushCell cell in MainForm.Instance.CurrentBrush.Cells())
            {
                creatingBrush.AddTile(cell.tile, cell.x + tx, cell.y + ty);
            }

            ReDraw();
        }
Exemplo n.º 6
0
        private void LoadBrushes()
        {
            string dir = System.IO.Path.GetDirectoryName(Tileset.FilePath.Absolute);
            string file = System.IO.Path.GetFileNameWithoutExtension(Tileset.FilePath.Absolute);
            string path = System.IO.Path.Combine(dir, file + "_brushes.xml");

            if (!System.IO.File.Exists(path)) return;

            using (var stream = new System.IO.StreamReader(path))
            {
                while (!stream.EndOfStream)
                {
                    string line = stream.ReadLine();
                    if (line == null) break;

                    string[] info = line.Split(' ');

                    TileBrush brush = new TileBrush(int.Parse(info[0]), int.Parse(info[1]));

                    int x = 0; int y = 0;
                    for (int i = 2; i < info.Length; i++)
                    {
                        int id = int.Parse(info[i]);
                        if (id >= 0) brush.AddTile(Tileset[id], x, y);

                        y++;
                        if (y >= brush.Height)
                        {
                            y = 0;
                            x++;
                        }
                    }

                    brushes.Add(brush);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Draws the brush onto the given screen at the given tile location.
        /// Returns an "undo brush" - a brush of all tiles that were overwritten.
        /// Returns null if no tiles were changed.
        /// </summary>
        public ITileBrush DrawOn(ScreenDocument screen, int tile_x, int tile_y)
        {
            TileBrush undo = new TileBrush(Width, Height);
            bool changed = false;
            foreach (TileBrushCell[] col in cells) {
                foreach (TileBrushCell cell in col) {
                    var old = screen.TileAt(cell.x + tile_x, cell.y + tile_y);

                    if (old == null)
                        continue;
                    undo.AddTile(old, cell.x, cell.y);
                    if (old.Id != cell.tile.Id) {
                        changed = true;
                        screen.ChangeTile(cell.x + tile_x, cell.y + tile_y, cell.tile.Id);
                    }
                }
            }

            if (changed) return undo;
            return null;
        }