コード例 #1
0
        public Image Paint(int tileW, int tileH)
        {
            Image bitmap;

            try
            {
                checkImage();

                bitmap = new Bitmap(image);

                Graphics e = Graphics.FromImage(bitmap);

                if (tileW > 0 && tileH > 0)
                {
                    selectSetor(tileW, tileH);

                    List <bool> list = walk_region[code];

                    for (i = 0; i < setor_actual.map_height; i++)
                    {
                        for (j = 0; j < setor_actual.map_width; j++)
                        {
                            Point loc = new Point((j * tileW) + (tileW / 2) - (global::EditorMapa2D.Properties.Resources.cross.Width / 2), (i * tileH) + (tileH / 2) - (global::EditorMapa2D.Properties.Resources.cross.Height / 2));
                            int   w   = Setor.ConvertNumero(new Point((j * tileW), (i * tileH)), tileW, tileH, setor_actual.map_width);
                            if (list.Count > w && list[w])
                            {
                                e.DrawImage(global::EditorMapa2D.Properties.Resources.cicle, loc);
                            }
                            else
                            {
                                e.DrawImage(global::EditorMapa2D.Properties.Resources.cross, loc);
                            }
                        }
                    }

                    for (i = 0; i < bitmap.Height; i += tileH)
                    {
                        e.DrawLine(Pens.Black, 0, i, bitmap.Width, i);
                    }

                    for (i = 0; i < bitmap.Width; i += tileW)
                    {
                        e.DrawLine(Pens.Black, i, 0, i, bitmap.Height);
                    }
                }

                e.Dispose();
            }
            finally { }
            return(bitmap);
        }
コード例 #2
0
        public bool setWalkRegion(Point e, int tileW, int tileH)
        {
            if (tileW > 0 && tileH > 0)
            {
                code = AddWalkRegion(tileW, tileH);

                List <bool> list = walk_region[code];

                i = Setor.ConvertNumero(e, tileW, tileH, setor[code].map_width);

                if (list.Count > i)
                {
                    list[i] = !list[i];
                    return(true);
                }
            }
            return(false);
        }
コード例 #3
0
        private string AddWalkRegion(int tileW, int tileH)
        {
            code = getCode(tileW, tileH);
            if (!setor.ContainsKey(code))
            {
                checkImage();

                Setor tmp = new Setor(Convert.ToInt32(image.Width / tileW), Convert.ToInt32(image.Height / tileH), tileW, tileH);

                setor.Add(code, tmp);

                List <bool> walk = new List <bool>();
                for (i = 0; i < (tmp.map_width * tmp.map_height); i++)
                {
                    walk.Add(true);
                }
                walk_region.Add(code, walk);

                tile_image.Add(code, new Dictionary <string, Image>());
            }
            return(code);
        }
コード例 #4
0
        public Tileset(string path)
        {
            tileset_code = 0;
            code_builder = new StringBuilder();
            walk_region  = new Dictionary <string, List <bool> >();
            setor        = new Dictionary <string, Setor>();
            setor_actual = null;
            tile_image   = new Dictionary <string, Dictionary <string, Image> >();

            if (path != string.Empty)
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    Image foto = new Bitmap(fs);

                    using (MemoryStream stream = new MemoryStream())
                    {
                        foto.Save(stream, foto.RawFormat);
                        buffer = stream.ToArray();
                    }
                }
            }
        }
コード例 #5
0
ファイル: Tileset.cs プロジェクト: farlei/libEGL
        public Tileset(string path)
        {
            tileset_code = 0;
            code_builder = new StringBuilder();
            walk_region = new Dictionary<string, List<bool>>();
            setor = new Dictionary<string, Setor>();
            setor_actual = null;
            tile_image = new Dictionary<string, Dictionary<string, Image>>();

            if (path != string.Empty)
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    Image foto = new Bitmap(fs);

                    using (MemoryStream stream = new MemoryStream())
                    {
                        foto.Save(stream, foto.RawFormat);
                        buffer = stream.ToArray();
                    }
                }
            }
        }
コード例 #6
0
ファイル: Tileset.cs プロジェクト: farlei/libEGL
        private string AddWalkRegion(int tileW, int tileH)
        {
            code = getCode(tileW, tileH);
            if (!setor.ContainsKey(code))
            {
                checkImage();

                Setor tmp = new Setor(Convert.ToInt32(image.Width / tileW), Convert.ToInt32(image.Height / tileH), tileW, tileH);

                setor.Add(code, tmp);

                List<bool> walk = new List<bool>();
                for (i = 0; i < (tmp.map_width * tmp.map_height); i++)
                {
                    walk.Add(true);
                }
                walk_region.Add(code, walk);

                tile_image.Add(code, new Dictionary<string, Image>());
            }
            return code;
        }
コード例 #7
0
ファイル: Tileset.cs プロジェクト: farlei/libEGL
        public void selectSetor(int tileW, int tileH)
        {
            code = AddWalkRegion(tileW, tileH);

            setor_actual = setor[code];
        }
コード例 #8
0
ファイル: ProjectExportEGL.cs プロジェクト: robsonmwoc/libEGL
        private int[,] get_image_crop(Tile tile, out int index_image)
        {
            int[,] arr  = new int[0, 0];
            index_image = -1;
            try
            {
                if (world_export.tilesets.ContainsKey(tile.tileset_code))
                {
                    if (!tilesets.ContainsKey(tile.tileset_code))
                    {
                        tilesets.Add(tile.tileset_code, new ProjectExportEGLTileSet());
                    }

                    Tileset tileset             = world_export.tilesets[tile.tileset_code];
                    ProjectExportEGLTileSet tmp = tilesets[tile.tileset_code];

                    if (tileset.tile_image.ContainsKey(tile.tile_code))
                    {
                        if (!tmp.tile.ContainsKey(tile.tile_code))
                        {
                            tmp.tile.Add(tile.tile_code, new Dictionary <string, ProjectExportEGLTile>());
                        }

                        Dictionary <string, Image> list_image = tileset.tile_image[tile.tile_code];
                        Dictionary <string, ProjectExportEGLTile> listTile = tmp.tile[tile.tile_code];

                        if (list_image.ContainsKey(tile.tile_crop))
                        {
                            if (!listTile.ContainsKey(tile.tile_crop))
                            {
                                Image image = list_image[tile.tile_crop];

                                using (FileStream fs = new FileStream(path_export + "\\" + path_image + name_image + image_index + ".png", FileMode.Create))
                                {
                                    image.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }
                                index_image = image_index;

                                image_index++;
                                ProjectExportEGLTile tmpTile = new ProjectExportEGLTile();

                                tmpTile.image_idx = index_image;

                                List <bool> list_walk = tileset.walk_region[tile.tile_code];
                                Setor       setor     = tileset.setor[tile.tile_code];
                                Rectangle   sector    = Tileset.convert_tile_crop(tile.tile_crop);

                                int x = sector.X;
                                int y = sector.Y;

                                int iX = x / setor.tile_width;
                                int iY = y / setor.tile_height;

                                int iW = sector.Width / setor.tile_width;
                                int iH = sector.Height / setor.tile_height;

                                arr = new int[iW, iH];

                                int k = 1;

                                for (i = 0; i < arr.GetLength(0); i++)
                                {
                                    for (j = 0; j < arr.GetLength(1); j++)
                                    {
                                        k = Setor.ConvertNumero(new Point(((i + iX) * setor.tile_width), ((j + iY) * setor.tile_height)), setor.tile_width, setor.tile_height, setor.map_width);
                                        if (list_walk.Count > k)
                                        {
                                            arr[i, j] = list_walk[k] ? 1 : 0;
                                        }
                                    }
                                }

                                tmpTile.walk_region = arr;

                                listTile.Add(tile.tile_crop, tmpTile);
                            }
                            else
                            {
                                ProjectExportEGLTile tmpTile = listTile[tile.tile_crop];

                                index_image = tmpTile.image_idx;

                                arr = tmpTile.walk_region;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
            return(arr);
        }
コード例 #9
0
ファイル: frmMain.cs プロジェクト: farlei/libEGL
        private int OpenTileset(ProjectTileSet pTileSet)
        {
            int i = 0;
            try
            {
                Tileset tileset = new Tileset();

                tileset.Name = pTileSet.tileset_name;
                tileset.tileset_code = pTileSet.tileset_code;
                tileset.buffer = pTileSet.buffer;

                for (i = 0; i < pTileSet.tiles.Length; i++)
                {
                    ProjectTiles pTile = pTileSet.tiles[i];

                    Setor setor = new Setor(pTile.tileset_setor[0], pTile.tileset_setor[1], pTile.tileset_setor[2], pTile.tileset_setor[3]);

                    string code = tileset.getCode(setor.tile_width, setor.tile_height);

                    if (!tileset.setor.ContainsKey(code))
                    {
                        tileset.setor.Add(code, setor);

                        List<bool> walk_r = new List<bool>();
                        int j;
                        for (j = 0; j < pTile.tileset_walk.Length; j++)
                            walk_r.Add(pTile.tileset_walk[j]);

                        tileset.walk_region.Add(code, walk_r);

                        tileset.tile_image.Add(code, new Dictionary<string, Image>());

                        Dictionary<string, Image> tile_images = tileset.tile_image[code];
                        List<byte[]> image_l = pTile.tileset_images;
                        string[] names_l = pTile.tileset_names;

                        for (j = 0; j < names_l.Length; j++)
                        {
                            Image tile;

                            using (MemoryStream ms = new MemoryStream(image_l[j]))
                            {
                                tile = Bitmap.FromStream(ms);
                            }

                            tile_images.Add(names_l[j], tile);
                        }
                    }
                }
                i = world.AddTileset(tileset);
                InsertTileset(tileset.Name, i);
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
            return i;
        }
コード例 #10
0
        public void selectSetor(int tileW, int tileH)
        {
            code = AddWalkRegion(tileW, tileH);

            setor_actual = setor[code];
        }
コード例 #11
0
ファイル: Project.cs プロジェクト: kenjasi75202/libegl
        public void add_tile_set(Tileset tileset)
        {
            try
            {
                if (tileset == null)
                {
                    return;
                }

                ProjectTileSet tmp = new ProjectTileSet();
                tmp.tileset_name = tileset.Name;
                tmp.buffer       = tileset.buffer;
                tmp.tileset_code = tileset.tileset_code;
                tmp.tiles        = new ProjectTiles[tileset.setor.Count];
                int i = 0;
                foreach (string key in tileset.setor.Keys)
                {
                    ProjectTiles tmp_tiles = new ProjectTiles();

                    if (tileset.walk_region.ContainsKey(key))
                    {
                        List <bool> walk_list = tileset.walk_region[key];

                        tmp_tiles.tileset_walk = new bool[walk_list.Count];

                        for (int j = 0; j < walk_list.Count; j++)
                        {
                            tmp_tiles.tileset_walk[j] = walk_list[j];
                        }
                    }

                    if (tileset.setor.ContainsKey(key))
                    {
                        Setor sector = tileset.setor[key];

                        tmp_tiles.tileset_setor = new int[4];

                        tmp_tiles.tileset_setor[0] = sector.map_width;
                        tmp_tiles.tileset_setor[1] = sector.map_height;
                        tmp_tiles.tileset_setor[2] = sector.tile_width;
                        tmp_tiles.tileset_setor[3] = sector.tile_height;
                    }

                    if (tileset.tile_image.ContainsKey(key))
                    {
                        Dictionary <string, Image> list = tileset.tile_image[key];

                        tmp_tiles.tileset_names = new string[list.Count];

                        tmp_tiles.tileset_images = new List <byte[]>();

                        int j = 0;
                        foreach (string names in list.Keys)
                        {
                            tmp_tiles.tileset_names[j] = names;

                            Image crop_image = new Bitmap(list[names]);

                            using (MemoryStream stream = new MemoryStream())
                            {
                                crop_image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                                byte[] buffer = stream.ToArray();
                                tmp_tiles.tileset_images.Add(buffer);
                            }

                            j++;
                        }
                    }

                    tmp.tiles[i] = tmp_tiles;
                    i++;
                }
                tilesets.Add(tmp);
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
        }