| tianajrp (23) | |
|
Someone told me that multidimensional in C++ is something that shouldnt be touched, is it true? Plus I have a question. Im making an RPG, 2d RPG which tile engine. I had been thinking and still have no idea how to implement a map What I have in mind is that a class map: class Map { private: int maxX, maxY; //code that goes here use to store data public Map(int x, int y) } the code that use to store data will generate maxX, maxY tile and set it to default tile which is 0. I believe this will require some sort of array, but I really have no idea how to do this | |
|
|
|
| kbw (5520) | |||
http://www.cplusplus.com/reference/map/map/ | |||
|
|
|||
| freddie1 (847) | |
|
I allocate memory using an allocator, which gives me a linear address space. Then I write a macro which indexes into that allowing (x, y, z) type subscript notation. So far, in my C++ code, I've never needed to go beyond three dimensional arrays, and so I have code I could help you with to index into two and three dimensional arrays. In my work I occasionally need four dimensional arrays, but I haven't yet taken the time to work that macro out in C/C++ syntax. I also code in PowerBASIC, and I believe that language allows up to 8 dimensions, dynamically allocated. In the app that needs four dimensional arrays, I used PowerBASIC. If you want help or examples wit two or three dimensional arrays, let me know. As far as I know, the issue with C and C++ is that all of the dimensions can't be allocated at run time. If I'm wrong about that, I hope somebody will tell me too. I know I did spend some time researching this quite a few years ago, and gave up on it with C++. It's my understnding C++ coders use various capabilities from STL and such to deal with this issue, as kbw intimated. | |
|
Last edited on
|
|
| tianajrp (23) | |||||
|
probably due to my misunderstanding (sorry my english is really bad) but let me make sure we are on the same page. The map im talking about is literally, a map. If you had ever played any 2d rpg, you will see your character walk on a bunch of tiles putted together. Those "bunch" of tiles putted together. That is called a map. Plainly speaking, a map is simply a data (sort of like array) that store x and y (coordinate) number that represent a tile. For example:
i want to use multidimensional array as something like this: int myTiles[MaxX][MaxY]then have a function that be like this:
If you can please teach me to use multidimensional array. I only need to use 2 variables x and y. | |||||
|
Last edited on
|
|||||
| freddie1 (847) | |||
I didn't think this would work, but it does. Maybe it shows what you are asking ...
| |||
|
|
|||