When initializing levels, all of the game objects need to be placed on the map. There are many different ways of doing this, but the main goal is to be able to easily translate design to code. Many advanced games have very powerful in-game level editors (much like Little Big Planet), which makes level creation far easier for the developers. The perfect counter-example would be hard-coding the position and properties of each object into the game individually. Ideally, I want to be able to be able to quickly and easily change the position and configuration of my different game objects, without having to write too much complicated editor code.
My solution is pretty counter intuitive and weird. But it works! Essentially, all of my level designs are color-coded .png image files that contain the information of each object in the RGB values. Terrain, however, is ignored and loaded in separately. Only objects are contained in the map. To make it easier to understand, take a gander at this example:
So, that probably doesn’t make it any easier to understand at all. This is an enlarged version of the actual level map, which is a very very small image, so that it doesn’t take up much space. Each colored square on the map is the size of a single pixel, and contains information about the position of each object, and what type of object it is. The position of the object is simply defined by its relative position on the map. The code scans through the image, and places each object in the same location, but on a much larger scale. Like I mentioned earlier, information is stored in the RGB (Red, Green, Blue) values of each pixel. RGB values range from 0 to 255; The red value determines the type of object. For instance, pixels that have a color value of 249 are platforms. When the code is scanning through my image and reads a pixel with a Red value of 249, it places a platform relative to the current position on the map. The Blue value contains the Length of the object (A ladder with a Blue value of 20 would have 20 rungs), and the Green value stores anything miscellaneous I need. So, here is what the level looks like after this images runs through the level generator:
Make sense yet? If not, take a look at an enlarged version of the level map and the final result overlapped.
So, in summary, there are many ways to create level designs that the code can understand, and this one is pretty bad. But whatever, it works. Yeah… THE END, or something.