Sunday, September 8, 2019

c++ - Recommended method towards making custom maps for a 2d game?


I am planning on making a 2D game, however different from my last personal projects I want this one to have enhanced graphics, with custom-designed levels. My previous 2d platformers were tile-based, in which I made a map editor for to create levels.


However, I am wondering the best way to implement custom designed maps? For say, some grass is a litter higher than others, flowers here and there, cool drawings and structures along the way, etc. instead of just the same old tiles over and over again. I am thinking but I just can't grasp the idea of how to implement it. I have seen it done in other games and am interested to see how they accomplish it, but can't get my hands on some source code. :(



Answer



There are many different types of level systems, most of which are customized specifically for a single game. This answer will not cover every implementation detail of these systems, but rather an abstracted explanation of each.


Tile-based



Although most tile-based systems are very shallow and are incapable of supporting much detail, it is possible to overcome this. At the core, a tile-based system is a two-dimensional array of cells, each filled with a piece of data that details it's contents.


The first action most designers take to add detail to a tile-based system is to add layers. Layers allow you to have multiple grids of cells stacked on top of each other, giving you the opportunity to add things such as shadows and things that are raised vertically off the ground, such as the crown of a tree or a tall lamp post.


Also, most tile-based systems use tile sets. Tile sets are palettes of data that the level system can use to store tile information. This allows you to more efficiently support a higher number of tiles, because if you need more room, you can just add another tile set.


You can add detail to each tile via metadata. For example, you might have only one "grass" tile. Instead of making new tiles for each height of grass, you can simply add metadata that describes this height.


Arbitrary Placement Level


Although a bit more complicated than a tile-based system, an arbitrary placement system gives you free control over the location of objects. Basically, every object in the level is given a position, rotation, and scale. So instead of having a list of cells that contain objects, you now have a list of objects that contain positional data.


Since each object contains it's own set of data, it is possible to store graphical information for each object. For example, instead of using a tile set to store the graphics for each type of tile, each object can now contain unique graphical data, such as the name of an image file.


Because the objects can intersect with each other, you will need to give each tile (along with it's X and Y position) a Z position, which is essentially it's layer. Objects with a higher (or lower, if you choose) Z position are drawn last, so that only the most prominent objects are shown on top, and all background objects are drawn behind these.


Arbitrarily placed objects can also have arbitrary sizes, allowing you to specify a long stretch of grass as one object, instead of have several tiles stored in several cells. Thus, an arbitrary placement system uses less memory than a tile-based system (usually). Also, things other than terrain may be stored in the level data, such as enemy placement, dynamic lights, and events. Although it is possible to make a tile-based system that included these features, it is almost certainly more difficult.


Conclusion



As you can see, both tile-based and arbitrary placement systems have their advantages, so it might be hard to choose between them. However, there is no reason you cannot have both. You can make a tile-based system as the base, and store all of your basic terrain in that, and then you can specify an arbitrary placement system on top of that, for adding objects that cannot be represented in a tile-based system.


In the end, the only way to get more detail into a level system is to force it in. Add more layers and tile attributes to your tile-based systems, and overlay an arbitrary placement system on top of that for the fine details.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...