How can I have a map array?
<p>How do I load Levels in my game, as in Layer 1 would be Objects, Layer 2 would be Characters and so on. I only need 3 layers, and they will all be put on top of each other. i.e having a flower with a transparent background to be put on grass or dirt on the layer below.I would like to Read From the same file too. How would i go about doing this? Any help would be appreciated. </p>

<p>I load the map from a level file which are just numbers corresponding to a tile in the tilesheet.</p>

<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("[Layer1]") != 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 draws the map. Also the tile sheet is 1280 by 1280 and the tilesizeX and tilesizeY is 64</p>

<pre><code>void DrawMap(std::vector &lt;std::vector &lt;int&gt; &gt; map)
{    
    int mapRowCount = map.size();

    for(int i, j = 0; i &lt; mapRowCount; i ++)
    {
        int mapColCount = map[i].size();

        for (int j = 0; j &lt; mapColCount; ++j)
        {
              int tilesetIndex = map[i][j];
              int tilesetRow = floor(tilesetIndex / TILESET_COLCOUNT);
              int tilesetCol = tilesetIndex % TILESET_COLCOUNT;    
              al_draw_bitmap_region(tileSet, tilesetCol * TileSizeX, tilesetRow * TileSizeY, TileSizeX, TileSizeY, j * TileSizeX, i * TileSizeX, NULL);
        }
    }
}
</code></pre>

<p>EDIT: <a href="http://i.imgur.com/Ygu0zRE.jpg" rel="nofollow">http://i.imgur.com/Ygu0zRE.jpg</a></p>
