I’m about to program a copy of Mario in Java. I’m thinking on 2 representations/data structures for the levels but I’m not sure which one should I choose:
- A 2D integer array.
- A quadtree to divide the level in pieces.
What are its advantages and disadvantages?
Definitely a 2d array of some type. Integers would be a good idea, however characters would be an even better idea.
Consider making a text file which is basically a “map”. It could be 10 rows by 10 columns of text. A very simple map, in this case. Maybe you could use an “a” to signify grass, and a “b” to signify brick. In this way, you could even visually understand your map before you put it into action. But you could basically program your application to depend on this text file for the map.
For instance, consider this map:
So, that would look like a long brick road above 3 long rows of grass. Imagine making this scheme much more complicated, using all kinds of characters a-z and A-Z, even punctuation like $ or % or &.
Then, you could create maps on the fly just by altering the text file. If you use integers, you are limited to only 10 characters (or 10 map objects, per se). For instance, what if you have more 10 objects, then how could you make a text file where the digits are next to each other. You won’t know how to seperate the digits.
The downside of a quadtree is that it’s overly complicated and won’t allow for quick access to specific elements.