OpenGL/Glut issues

Status
Not open for further replies.

Ugly Joe

New member
I started to poke around my shmup code again today and came across a shortcoming in GLUT. What I'm trying to do is have the ship be moved with the arrow keys, but slow down when the user holds down shift. Now, the moving part is easy, but the shift part is driving me crazy.

Glut has a function called glutGetModifiers() that you can call during your key-handling functions (but only during your key-handling functions) that will tell you if modifier keys (shift/ctrl/alt) are being held down. I can use that in the key-handler to set a "slowdown" boolean and have the game slow down the player. That almost works.

The problem is that the shift key itself does not set off the key-handlers. That is, If I were to hold shift and then hold left, the player would move slowly to the left. If were to hold left and then hold down shift, I would not slow down until I pressed another key (directional, letter, anything to set off the keyhandler function).

I've looked high and low, but can't seem to find a sane way of coding this.

I've also considered some alternatives. Like, don't use a modifier key for the slowdown button, or, use the JKLI keys for movement so that the shift key will make the character values change. The problem with both of those is that some keyboards (mine included) can only respond to a few keys at once. Using so many letter keys at once will make the game unplayable for some people.

This is almost becoming a Diaries post, so I'll stop there. If you're familiar with GLUT and know a better way of handling modifier keys, please let me know. Also, if you can think of any alternative control schemes, please let me know.

<P ID="signature"></P>
 
Instead of having to hold Shift to slow down movement, why not set some other key to a "speed toggle". For instance, say you start the game at "normal" speed. You press "Z" (or some other key) and the speed is toggled to "slow" and remains there until you hit the same key again to toggle the speed back to "normal".

You'd then just have to check the "speed toggle" variable to see how fast to move the ship when the arrow keys were pressed. I'm thinking that could resolve both problems (shift key not triggering the function, and holding multiple keys at once).

<P ID="signature"></P>
 
Thanks for the idea. I may have to go that route. It's still an issue with the multiple key presses, though. Using z for shoot and x for speed change would still cause some problems (either x wouldn't register or it would cancel out z, I forget which).

<P ID="signature"></P>
 
Status
Not open for further replies.
Back
Top Bottom