I'm creating a tile based game where I have a bunch of spritesheets that I've borrowed from Space Station 13 /tg/. Right now, I'm loading in the spritesheets and separating it up into individual textures (e.g floor0 to floor300) that I store in a texture manager object. I keep a pointer to this object in my object manager and everything that'll need to retrieve textures. I have a map maker in my game which includes a toolbox with all the textures from the spritesheets. I select the texture from that, then I add it to the game world.
This works fine as long as I don't have any actual game objects with any logic, but I notice that it's getting a bit messy now that I've begun adding logic to the various objects I want in the game.
Here's the code I use for adding objects
std::string typeTemp {type};
std::string typeStripped {stripDigits(stripUnderscore(typeTemp))};
std::string selectString {type.substr(0, findDigit(type) + 1)};
if (typeStripped == "wall" || typeStripped == "floor") {
structManager.addStructure(objectRotation, tile, type);
objects.push_back(structManager.getLastAdded());
} else if (typeStripped == "mob") {
player = new Player(tileSize, objectRotation, tile, texManager->getTexture(selectString), selectString, int(objects.size()), texManager, camera);
playerExists = true;
}
else if (typeStripped == "egg")
objects.push_back(new PlayerSpawn(tileSize, objectRotation, tile, texManager->getTexture(selectString), selectString, int(objects.size()), texManager));
else if (typeStripped == "airlock")
objects.push_back(new Airlock(tileSize, objectRotation, tile, texManager->getTexture(selectString), selectString, int(objects.size()), texManager));
Part of me feels like I'm doing it in a convoluted way. Basically I'm stripping out anything preceding underscores and digits from the name of the texture to get what kind of object it is (airlock0 > airlock, normal_wall10 > wall, alien_egg0 > egg, etc) then I add the appropriate object to a list of pointers of GameObject which is the base class for all objects.
Any ideas? I don't know much about game dev so I'm not sure if what I'm doing is a good way of doing this. I mean, it works, but if I continue doing this I have a feeling I'll get a lot of repeated code which feels unnecessary.
Sorry, you need to Log In to post a reply to this thread.