title: How do I get my TileSheet to wrap?
body: <p>I load the map from a level file which are just numbers corresponding to a tile in the tilesheet.</p>
  
  <p>Here is the level file</p>
  
  <pre><code>[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
  </code></pre>
  
  <p>And here is the code that interprets it</p>
  
  <pre><code>void LoadMap(const char *filename, std::vector&lt; std::vector &lt;int&gt; &gt; &amp;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() &gt; 0)
                      tileSet = al_load_bitmap(line.c_str());
                  break;
              case Map: 
  
                  std::stringstream str(line);
                  std::vector&lt;int&gt; tempVector;
  
                  while(!str.eof())
                  {
                      std::getline(str, value, ' ');
                      if(value.length() &gt; 0)
                          tempVector.push_back(atoi(value.c_str()));
                  }
                  map.push_back(tempVector);
                  break;
              }
          }
      }
      else
      {
    }
    }
  </code></pre>
  
  <p>And this is how it looks
  <a href="http://i.imgur.com/6W49eWf.jpg" rel="nofollow">http://i.imgur.com/6W49eWf.jpg</a></p>
  
  <p>Ok so my Tilesheet is 1000 by 200 and it looks like this <a href="http://i.imgur.com/Y83zBxj.png" rel="nofollow">http://i.imgur.com/Y83zBxj.png</a></p>
  
  <p>How would I make it wrap around to 20 or 40 when putting in 20 or 40 in the map file?</p>
  
  <pre><code>void DrawMap(std::vector &lt;std::vector &lt;int&gt; &gt; map)
  {    
      for(int i, j = 0; i &lt; map.size(); i ++)
      {
          for(j = 0; j &lt; map[i].size(); j ++)
          {
            al_draw_bitmap_region(tileSet, map[i][j] * TileSizeX, 0, TileSizeX, TileSizeY, j   * TileSizeX, i * TileSizeX, NULL);
          }
      }
  }
  </code></pre>
  
  <p>Also the TileSizeX and TileSizeY is 50  </p>