I'm working on an RPG and I'm trying to figure out how to manage the different levels/areas in the game. Currently I create a new state (source file) for every area, defining its unique aspects. My concern is that as the game grows the number of class files will become unmanageable with all the towns, houses, shops, dungeons, etc. that I need to keep track of.

I would also prefer to separate my levels from the source code because non-programmer members of the team will be creating levels, and I would like the engine to be as free from game specific code as possible.

I'm thinking of creating a class that provides all the functions that will be the same between all the levels/areas with a unique member variable that can be used to look up level specifics from data. This way I only need to define level/area once in the code, but can create multiple instances each with its own unique aspects provided by data.

Is this a good way to go about solving the issue? Is there a better way to handle a growing number of levels?


2 Answers 2


Having just one generic "Map" class and have each instance of this class load its layout, objects, scripts etc. from an external file is the usual way to do it.

Usually a WYSIWYG map editor is used to create and edit these map files. This map editor can be integrated into your game or be a stand-alone program. In the latter case you can often safe lots of work by using an existing map editor and just implement its file format in your game engine.

For 2d games, I prefer Tiled.

  • \$\begingroup\$ Ok, that makes a lot of sense. Just one follow-up question. What is the best way to differentiate each instance so it knows what to load in? Just have a member variable used as an identifier? Or a parameter in the constructor I guess. \$\endgroup\$
    – Hexlan
    Commented Jun 6, 2014 at 14:43
  • 1
    \$\begingroup\$ @Hexlan You could pass the map file to load to the constructor of the Map class. Or you could initialize maps empty, add getters and setters for all map properties and have a separate MapFactory class which reads the map files and sets up each map instance. That's what I am doing in my current project, because I have both pre-mapped and procedurally auto-generated maps. \$\endgroup\$
    – Philipp
    Commented Jun 6, 2014 at 15:14
  • \$\begingroup\$ Thanks for the advice. I don't believe my current project will include any procedurally generated maps, but I may have to play around 'MapFactory' class in my side projects. \$\endgroup\$
    – Hexlan
    Commented Jun 6, 2014 at 15:27
  • \$\begingroup\$ +1 having your map data in files is also a good step towards data-driven architecture, which is awesome for games (and RPGs). \$\endgroup\$
    – ashes999
    Commented Jun 6, 2014 at 19:42

Don't go with a class for each area! Make you area have certain parameters! Unless its something really specific - when I mean specific is that really changes the concept of area and you can't fit it anywhere.

Then, you should make a event system for you game (you will thank me later) this will make creating different area lore and dynamic actions a lot easier in the long run!

-By Event System I mean, something that interpretes simple commands that can be chained to create complex actions (move, turn,jump, change something in the map , etc) this will make creating dynamic areas extremely easy!

Source : I have worked in many 2D RpGS in the past, and trust this saves a lot of time in the long run.

Think before you act. Planning will bring you a long way.

  • \$\begingroup\$ Thanks for the advice. Just curious, for the event system would you suggest implementing it with an Entity Component System or just by itself? \$\endgroup\$
    – Hexlan
    Commented Jun 14, 2014 at 4:19

You must log in to answer this question.

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