Original Post
I am currently making a 2d platformer game in C++. One issue I've run into is how do you manage level data? Currently, everything is hardcoded into the game, but I think this is not a very scalable solution. I assume that the usual practice is to store level data is some sort of external format, but I'm not sure how to do this. How do you format your level files? What parts do you put in the files, and what parts do you code into the game? It is relatively straightforward to put something like basic level geometry into the file, but what about complex triggers? It seems like some things have to be coded into the game, even if they are only used in a single room. Otherwise you may as well rewrite the game in a scripting language. Here is an example of what my code looks like right now. Doomed Hometown is a nearly empty room with one exit and one simple trigger that causes a house to fly upwards when the player walks over it.
#include "DoomedHometown/house.h"
namespace DoomedHometown
{
inline void LoadCamera(Camera& target) {target.SetBounds(0,0,800,600);}
inline WorldCoordAnim* GetBackground() {return new WorldCoordAnim( new PlainImage(zlBACKGROUND, ImgDataStruct("DoomedHometown/homescreen.bmp")),0,0);}
inline CollisionProfile GetActiveBounds() {return CollisionProfile(0,-32,864,600);}
inline void LoadEntities(entitymanager_ptr myManager, RoomLoader* myRoomManager)
{
assert(myManager);
assert(myRoomManager);
//Brushes
myManager->AddEntity(new eBrush(0,-32,32,864)); //Top
myManager->AddEntity(new eBrush(832,0,32,600)); //Right side
myManager->AddEntity(new eBrush(800,40,32,390)); //Right side 2
myManager->AddEntity(new eBrush(0,0,134,600)); //Office building
myManager->AddEntity(new eBrush(134,511,730,25)); //road
//Entities
myManager->AddEntity(new SavePoint(myManager, 456,400, HARD));
myManager->AddEntity(new TinyHouse(229,475));
for(int y=430;y>0;y-=130) {myManager->AddEntity(new Spike(768,y, Spike::LEFT));}
myManager->AddEntity(new TriggerBrush(800,430,32,211, new WarpCallback(myRoomManager, WarpDest::TUTORIALTUNNEL_TOPLEFT)));
entity_sptr temp(myManager->AddEntity(new TinyHouse(763,540)));
myManager->AddEntity(new TriggerBrush(756,462,44,50,
new trigAddBehavior(temp,
new MoveBehavior(temp.get(), .04, -3.25, 1000))));
}
};