I'm trying to wrap my head around how you'd deal with multiple sprites for different objects. I'm using an asset pack that includes 4 different characters each character has 6 sprite sheets so one of my goals are to make a player that uses a different character every time they respawn. The solution I had in mind was to be able to choose character and then I'd have access to their sprites so I made a map that kind of does this and overall I don't think it was a bad attempt I think I managed to do what I wanted it's just not very good I'd imagine having a giant map for everything (enemies, coins, other stuff) is going to become rough to manage.
std::map<CharacterType, std::pair<std::map<SpriteState, std::string>, std::map<SpriteState, int>>> characterConfig = {
{CharacterType::NINJA_FROG, {
{
{SpriteState::IDLE, "source/resources/animations/player/Ninja Frog/Idle (32x32).png"},
{SpriteState::RUN, "source/resources/animations/player/Ninja Frog/Run (32x32).png"},
{SpriteState::JUMP, "source/resources/animations/player/Ninja Frog/Jump (32x32).png"},
},
{
{SpriteState::IDLE, 11},
{SpriteState::RUN, 12},
{SpriteState::JUMP, 1},
}
}},
// Other characters
};
Entity& createPlayer(Manager& manager, Graphics& graphics, int x, int y, CharacterType characterType) {
auto& player(manager.addEntity());
auto& position(player.addComponent<PositionComponent>(x, y));
auto& velocity(player.addComponent<VelocityComponent>());
auto& sprite(player.addComponent<AnimatedSpriteComponent>(graphics, characterType));
auto& physics(player.addComponent<PhysicsComponent>());
return player;
}
Entity& player = createPlayer(manager, graphics, 100, 100, CharacterType::NINJA_FROG);
// OR
Entity& player = createPlayer(manager, graphics, 100, 100, CharacterType::SOMEONE_ELSE);