예제 #1
0
        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;
        }
예제 #2
0
        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);
        }