C++ 我该如何包装我的瓷砖呢?

C++ 我该如何包装我的瓷砖呢?,c++,bitmap,allegro5,C++,Bitmap,Allegro5,我从一个级别文件加载贴图,该文件只是与tilesheet中的一个平铺对应的数字 这是级别文件 [Map] 0 1 0 0 0 0 0 0 0 0 20 0 0 0 0 0 0 0 0 40 0 0 0 0 0 0 0 0 63 0 0 0 0 0 0 0 0 79 0 0 0 0 0 0 0 0 0 0 这是解释它的代码 void LoadMap(const char *filename, std::vector< std::vector <int> > &ma

我从一个级别文件加载贴图,该文件只是与tilesheet中的一个平铺对应的数字

这是级别文件

[Map]
0 1 0 0 0 0 0 0
0 0 20 0 0 0 0 0
0 0 0 40 0 0 0 0
0 0 0 0 63 0 0 0
0 0 0 0 0 79 0 0
0 0 0 0 0 0 0 0
这是解释它的代码

void LoadMap(const char *filename, std::vector< std::vector <int> > &map)
{
    std::ifstream openfile(filename); 
    if(openfile.is_open())
    {
        std::string line, value;
        int space;

        while(!openfile.eof())
        {
            std::getline(openfile, line);

            if(line.find("[TileSet]") != std::string::npos)
            {
                state = TileSet;
                continue;
            }
            else if (line.find("[Map]") != std::string::npos)
            {
                state = Map;
                continue;
          }

            switch(state)
            {
            case TileSet:
                if(line.length() > 0)
                    tileSet = al_load_bitmap(line.c_str());
                break;
            case Map: 

                std::stringstream str(line);
                std::vector<int> tempVector;

                while(!str.eof())
                {
                    std::getline(str, value, ' ');
                    if(value.length() > 0)
                        tempVector.push_back(atoi(value.c_str()));
                }
                map.push_back(tempVector);
                break;
            }
        }
    }
    else
    {
  }
  }
void LoadMap(const char*filename,std::vector&map)
{
std::ifstream openfile(文件名);
if(openfile.is_open())
{
std::字符串行,值;
int空间;
而(!openfile.eof())
{
std::getline(openfile,line);
if(line.find(“[TileSet]”)=std::string::npos)
{
状态=TileSet;
继续;
}
else if(line.find(“[Map]”)=std::string::npos)
{
状态=地图;
继续;
}
开关(状态)
{
案例TileSet:
if(line.length()>0)
tileSet=al_load_位图(line.c_str());
打破
案例图:
std::stringstream str(行);
std::向量tempVector;
而(!str.eof())
{
std::getline(str,value',);
如果(value.length()>0)
tempVector.push_back(atoi(value.c_str());
}
map.push_back(tempVector);
打破
}
}
}
其他的
{
}
}
这就是它的样子

好的,我的Tilesheet是1000乘200,看起来像这样

在地图文件中输入20或40时,如何使其环绕到20或40

void DrawMap(std::vector <std::vector <int> > map)
{    
    for(int i, j = 0; i < map.size(); i ++)
    {
        for(j = 0; j < map[i].size(); j ++)
        {
          al_draw_bitmap_region(tileSet, map[i][j] * TileSizeX, 0, TileSizeX, TileSizeY, j   * TileSizeX, i * TileSizeX, NULL);
        }
    }
}
void绘图图(标准::矢量图)
{    
对于(inti,j=0;i

此外,TileSizeX和TileSizeY为50

您需要计算目标磁贴所在的磁贴设置单元。你有tileset索引。根据平铺集的尺寸,使用一点数学来确定该平铺的列和列

//This is how many columns your tileset can have.
//You could even dynamically calculate this if you wanted.
static const int TILESET_COLCOUNT = 20;

void DrawMap(std::vector<std::vector<int> > map)
{    
    int mapRowCount = map.size();

    for (int i = 0; i < mapRowCount; ++i)
    {
        int mapColCount = map[i].size();

        for (int j = 0; j < mapColCount; ++j)
        {
            //This is your tileset index in your level map.
            int tilesetIndex = map[i][j];

            //The tileset row can be calculated by dividing the tileset index by the number of columns in a tileset row.
            int tilesetRow = floor(tilesetIndex / TILESET_COLCOUNT);

            //The tileset column can be calculated by retrieving the remainder of the modulus operation on the total number of columns in a row.
            int tilesetCol = tilesetIndex % TILESET_COLCOUNT;

            al_draw_bitmap_region(
                tileSet, //The tileset
                tilesetCol * TileSizeX, //multiply the tileset column by the size of a tile to get the source x
                tilesetRow * TileSizeY, //multiply the tileset row by the size of a tile to get the source y
                TileSizeX, //width
                TileSizeY, //height
                j * TileSizeX, //destination x
                i * TileSizeX, //destination y
                NULL //flags
            );
        }
    }
}
//这是tileset可以包含的列数。
//如果需要的话,您甚至可以动态地计算它。
静态常数int TILESET_COLCOUNT=20;
void DrawMap(标准::向量映射)
{    
int mapRowCount=map.size();
对于(int i=0;i
不确定你要的是什么?你的tilesheet是否总是一个常数1000乘以X?就像在中一样,一个瓷砖表中总是有20列瓷砖,行数是无限的?@user814628我想问的是,我该如何让它缠绕在瓷砖表上。i、 e如果我在级别文件中输入20,我希望它返回到开始,向下一个平铺,并显示“20”平铺。因为现在它只是在一条海峡线上。