タイルシートのタイルに対応する数字だけのレベル ファイルからマップを読み込みます。
レベルファイルはこちら
[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
{
}
}
これがその外観です http://i.imgur.com/6W49eWf.jpg
わかりましたので、私のタイルシートは 1000 x 200 で、次のようになりますhttp://i.imgur.com/Y83zBxj.png
マップ ファイルに 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);
}
}
}
また、TileSizeX と TileSizeY は 50 です