Uint8 *keystates = SDL_GetKeyState(NULL); if (keystate[SDLK_LEFT] && player.x < SCREEN_WIDTH - 5 - player.width) player.x++; if (keystate[SDLK_RIGHT] && player.x > 0 + 5) player.x--;
...and thus get rid of the 'playerMovingLeft' and 'playerMovingRight' variables, since SDL does that internally, making your code cleaner. But it's important that you understood what is actually happening before using SDL_GetKeyState() as a magic bullet.