I am trying to write code that separates the sdl event stuff from the rest of my code. I made a input manager class that uses an array of bools to store which keys are pressed or not. I was wondering if thats the right way to go about it because it seems quite clean but now that I am trying to use it I'm not sure.
I used it to exit the gameloop when escape is pressed ok but for somthing like controling your characters movement maybe it wouldn't be usefull. Perhaps each loop I would check if each direction key had been pressed seperately and if one of them had change the velocity of the character, but then how would I make sure if you held the left button for example the character didn't keep going faster and faster to the left.
Also I am trying to make my game quite efficient because I am not making it for the PC so I was wondering if this is maybe a unnecessarily expensive way to go about it. (With all the different keys being checked each loop and all.)
This is the sort of code I would use to exit if escape is pressed:
input_manager input_man;
while (running == true)
{
input_man.update();
if (input_man.check(KEY_ESCAPE) == true)
running = false;
}
Here is the input_manager class:
class input_manager
{
public:
input_manager();
void update();
bool check(unsigned char button) {return key[button];};
private:
SDL_Event event;
bool key[18];
};
Thanks