In my games update loop, which happens on a fixed timestep of 30 times per second, I am checking the current state of several keys to determine how to move the player. For example:
if(Keyboard.down(KEY_LEFT) { /* move character left */ }
This works fine in situations where I expect the player to hold the key down for extended periods (such as movement), but for things like shooting, where the player just taps the key quickly, it doesn't always pick up the key being down.
This is due to the key being both pressed and released in the gap between polling.
Now obviously I don't want to trigger my shooting code 30 times a second like I do my moving code, so the solution needs to incorporate some kind of buffering/delay mechanism to make sure each shot is still x milliseconds apart, but I need the first one to register immediately and with certainty.
I am using Javascript, so I can easily use event driven functions linked to keypresses (in fact I am doing this already in order to keep track of which keys are down), but I didn't want to have game logic outside of the fixed timestep update.
Can anyone suggest a solution? I'm not looking for code, more an idea of how to design/structure the code around the problem.