Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualServant of the Lord

Posted 19 May 2012 - 01:09 PM

You can also use SDL_GetKeyState() to read keypresses, like this:

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.

#1Servant of the Lord

Posted 19 May 2012 - 01:00 PM

Oh, btw, you can also use SDL_GetKeyState() to read keypresses, like this:

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. I just figured it was important that you understood what is actually happening before using SDL_GetKeyState() as some magic bullet.

PARTNERS