I'm trying to build a simple 2D Shoot 'Em Up type of game in C++ using SDL2 and an Entity Component System, which I've already implemented. The idea is to have different maps/rooms where you have to kill all enemies before moving on to the next. Each room has different types of obstacles and those obstacles are positioned differently in each room.

I already have the design of the first map with all the obstacles in it. However, I suspect I should really separate the actual "map", i.e., wherever you can walk on, from the obstacles' assets in order to keep them as separate entities with their own (static) Hitbox components. This would still require me to place each and every obstacle on the map "by hand", i.e., tweaking their coordinates on the map until it looks like my current design.

My question is simply: is there a more efficient way to do this? How is this usually dealt with in the (indie) gamedev community?

If possible, I would also like to know if keeping each tree, box, wall... as separate entities with different IDs is actually a good idea. And if so, would that also be the way to implement invisible walls as map limits?

Thanks in advance for your time!


1 Answer 1


I'm not sure how you've got your mapping implemented and wondered if you'd considered tile-based mapping? If I'm not mistaken, your concerns are based around an efficient way to construct your game map. (placing objects, etc.)

I wrote a game similar to what you've described and when faced with level design, I incorporated editing into the engine, allowing me to quickly construct maps, define areas where the player cannot pass, etc. and test in real-time. This is not as complex as it may sound.

There are many examples of tile engines out there and they are very easy to implement -- an array of Tile structures is all that is required. Add a Blocked property to the Tile structure in order to define whether or not a player can pass into that area. I also stored the source co-ordinates for a tiles image in the Tile structure, to save looking it up when drawing the map.

Having some experience with mapping, I'd like to assist if I can.

  • 1
    \$\begingroup\$ Thanks for the detailed answer! A few days have passed and, eventually, I also decided that using Tile-based maps might be the best way to manage resources. What I did is, outside of the ECS I've designed, I've written a dedicated Parser that takes Tiled XML maps and tilesets and renders those separately. As for why I'm using Tiled and not a dedicated Map Editor in the engine as you suggest, which I think is way cooler: I have someone else on my team, who doesn't know how to code, designing all the maps and assets, so having a pre-designed tool with a simple interface they can use is ideal. \$\endgroup\$ Mar 25, 2022 at 13:55
  • 1
    \$\begingroup\$ On that note, what I also found very useful is separating the 'static' tiles, which do not have any properties attached to them (i.e., they are only rendered), from 'Special' tiles that have animations, collision boxes, etc. Then I can create dedicated structs / entities for those and process the logic via the ECS so I don't have to e.g. create separate collision systems for tiles vs other entities. Is that similar to what you've implemented in your game? \$\endgroup\$ Mar 25, 2022 at 14:04
  • \$\begingroup\$ You're welcome, I'm pleased to contribute. I think you've made the right choice by selecting tile-based mapping. Although it's not always the optimal solution, I use it in 95% of 2D games I cobble together because it's very flexible and when done correctly, it's tile-based nature is indistinguishable. If I may ask -- have you decided on a tile size yet and are you planning on supporting multiple resolutions? I ask because in the case of the latter, scaling things appropriately. can be a challenge. \$\endgroup\$
    – ROGRat
    Mar 27, 2022 at 5:26
  • \$\begingroup\$ @NickRomán I use a hybridized ECS/Inheritance model because I'm yet to build anything that is complex enough to require "full ECS". In the project I'm working on currently (Direct2D, .NET), a vertically scrolling shooter, the map and the ability to edit it is completely componentized to maximize flexibility, while the sprites and animations use a couple of levels of inheritance. The approach you described in your last comment sounds like a good way to go, with an ECS already in play. \$\endgroup\$
    – ROGRat
    Mar 27, 2022 at 5:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .