gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Detecting simultaneous keypresses

#27073 - mr_square - Sat Oct 02, 2004 4:38 pm

Hi all - I have a little man who runs, and I want him to do a running jump only when 'A' is pressed whilst running right - how would I implement this?

I'm currently using a finite state machine to model sprite animations, so my code is something like:

if(!(*KEYS & KEY_A))
{
nextState = new jumpState;
return nextState;
}

#27080 - sajiimori - Sat Oct 02, 2004 7:32 pm

Try to design your code so that you can say what you mean. So, if you mean "if the A button was just pressed and player is not already jumping, then do a running jump if running or a regular jump otherwise":
Code:
if(just_pressed(A_BUTTON) && !player_jumping())
{
  if(player_running())
    do_running_jump();
  else
    do_regular_jump();
}
It's practically a direct translation, and it makes for self-documenting code that has little need for comments.