A big part with input management in a game is allowing the user to customize how he interacts with it, like the keys. Most of the time, you can find the most popular key bindings and see them written directly in the code. But there will always be people that want to do stuff their way.
We have to provide tools in order to dynamically bind the keys to specific actions. With the command queue introduced in the previous sections, this becomes a much easier task to accomplish.
With the command queue, we already define specific actions for a specific key. The difference is that right now, we have it hardcoded as follows:
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) commands.push(moveLeft); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) commands.push(moveRight);
The problem with this code is that it is very inflexible. We have to change a lot in order to allow any key to respond to any action. We have two clearly separate sets of data that we want...