Multiple Key Presses
If you're using DirectInput, there's a very similar post here called "Player input: buffered or immediate" that handles the same problem.
What if I decide to make my own keyboard input function and forget about direct input.
Perhaps this will help you:
int ASCIIKeys[256];
int SpecialKeys[256]; // keys like up down..
int ASCIIKeys[256];
int SpecialKeys[256]; // keys like up down..
void AsciiKeyPressed(unsigned char key)
{ ASCIIKeys[key]=1;
}
void AsciiKeyReleased(unsigned char key)
{ ASCIIKeys[key]=0;
}
void SpecialKeyPressed(unsigned int key)
{ SpecialKeys[key]=1;
}
void SpecialKeyReleased(unsigned int key)
{ SpecialKeys[key]=0;
}
in your gameloop you now have to do the following:
...
if(SpecialKeys[FIRE]) player.firegun();
if(SpecialKeys[UP]) player.run();
...
The only problem you now have is to make your programm call the callback functions from above when a keyboard event happens.
How do you get multiple key presses and process them in your game? Example: Getting the forward key being presses and the fire key being pressed and making the player fire and walk at the same time.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement