-
Loading maps
I'm writing my first rpg and I read that it is much better to load maps rather than including them in the compilation because it reduces the .exe size, which makes sense. I'm not to sure how to do that. Here is an example of what my maps look like:
Code:
if (map ==1){
vector<string> trail1(8);
trail1[0] = " ________ ____ ";
trail1[1] = "| / / |";
trail1[2] = "| / / |";
trail1[3] = "| | | |";
trail1[4] = "| | | |";
trail1[5] = "| | | |";
trail1[6] = "| | | |";
trail1[7] = "|_____| |_____|";
trail1[y].replace(x, 1, "X");
for (int index = 0; index <8; ++index)
{
cout << trail1[index] << endl;
}
}
That is saved as a seperate file and is included during the compilation. I was wondering how I could get the map to load when the user enters that area rather than it already being in the .exe.
-
You would probably store this in a textfile:
Code:
________ ____
| / / |
| / / |
| | | |
| | | |
| | | |
| | | |
|_____| |_____|
Then you just need to read it line by line:
Code:
// assume this typedef somewhere
typedef std::vector<std::string> MapType;
// reading into trail
MapType trail;
std::ifstream in("textfile.txt");
std::string str;
while (std::getline(in, str))
{
trail.push_back(str);
}
// making the replacement
trail[y].replace(x, 1, "X"); // y must be less than trail.size()
// to print
for (MapType::iterator i = trail.begin(); i != trail.end(); ++i)
{
std::cout << *i << std::endl;
}