At this point I am only left with turning those numerical values of the textures into chars, so map.txt can be read properly
Yeah, you can do that or map the texture coordinates manually. but it will take a looot of time and may become messy. if you tile is 64x64 pixels, for example:
if (tile == "a"){
quad[0].texCoords = sf::Vector2f(0, 0);
quad[1].texCoords = sf::Vector2f(0, 64);
quad[2].texCoords = sf::Vector2f(64, 64);
quad[3].texCoords = sf::Vector2f(64, 0);
}
if (tile == "b"){
quad[0].texCoords = sf::Vector2f(64, 64);
quad[1].texCoords = sf::Vector2f(64, 128);
quad[2].texCoords = sf::Vector2f(128, 128);
quad[3].texCoords = sf::Vector2f(128, 64);
}
//etc
What I would do is convert the characters to numbers as the file is loaded and use the rest of the code like normal. Something like:
int tile = 0;
switch (c)
{
case '.':
tile = 0;
break;
case '#':
tile = 1;
break;
case '$':
tile = 2;
break;
case '@':
tile = 3;
break;
}
where c is a char from the map. Do that for each character in the file and put the value of tile into the tiles vector.
Yep, if you replaced the std::copy (which is doing a whole line at a time) with a loop to do one character at a time.
Here's a little sample I had to test it. It's not using the same kind of container (just an array, not vectors) but it shows reading the file and converting. (I wrote it before seeing your code above)
No error checking or safety stuff. :)
const int g_width = 16;
const int g_height = 8;
char g_tiles[g_height][g_width];
void loadMap()
{
std::fstream in("data/testmap.txt");
std::string s;
for (int y = 0; y < g_height; ++y)
{
std::getline(in, s);
for (int x = 0; x < g_width; ++x)
{
int tile = 0;
switch (s[x])
{
case '.':
tile = 0;
break;
case '#':
tile = 1;
break;
case '$':
tile = 2;
break;
case '@':
tile = 3;
break;
}
g_tiles[y][x] = tile;
}
}
}