Talk:RPG MAP2
From GDWiki
There is only one thing I didn't grasp or rather understand how to do in this tutorial. The following line: Read MapWidth, MapHeight
How can I translate that into C++ so MapWidth takes up the MapWidth value and MapHeight takes up the MapHeight value from the file?
// this code indeed compiles but it doesn't work as the Read function does it seems std::ifstream lev("level.txt"); lev >> LevelWidth, LevelHeight;
- The pseudo-code used in the article is a mix of everything, attempting only to relay the ideas of what needs to be done. When you go to apply these ideas, you need to utilize the tools you've decided to use to their fullest. In your case, with C++, it's much easier to separate the pieces of data in the text file with spaces. So your map file might look like:
3 3 0 0 0 0 32 1 32 0 0 32 0 0 0 0 1 0 0 0 0 32 0 0 32 1 32 32 0
- And notice the map dimensions given as "3x3" rather than "2x2", since in C++ you specify the array size rather than the inclusive upper bound. And so you would read it back by doing something like:
int LevelWidth; int LevelHeight; std::ifstream lev("level.txt"); lev >> LevelWidth >> LevelHeight;

