![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 11
| Using curses I've built a very simple and small 'Lunar Lander' game using a combination of timers and curses. I've come to a point thought where I'd like to improve it and I'm stumped at what to do about a particular issue. From how I've organized me curses, I can only detect on key press at a time. My basic loop structure is this: Code: while(1)
{
c = getch();
if (c != ERR)
{
if (c == ' ')
{
........
}
else if (c == 't')
{
.....
}
}
}
Thanks. |
| TheDenominater is offline | |
| | #2 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 11,317
| Push them all onto a queue, stack, whatever, as you press them, and pull them off as you run through your game loop. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #3 |
| dat is, vast staat Join Date: Jul 2008 Location: SE Queens
Posts: 6,612
| Make the condition: Code: while (ch=getch()) {
You could use quzah's suggestion, but 1) I don't think it will be so simple unless you are threading this; 2) the loop should execute rapidly enough that this is not a real issue; 3) users hitting several key simultaneously need to learn to use the interface properly
__________________ C programming resources: GNU C Function and Macro Index -- glibc reference manual The C Book -- nice online learner guide Current ISO draft standard CCAN -- new CPAN like open source library repository GDB tutorial #1 -- gnu debugger tutorials -- GDB tutorial #2 cpwiki -- our wiki on sourceforge Last edited by MK27; 12-01-2009 at 06:48 PM. |
| MK27 is offline | |
| | #4 |
| Registered User Join Date: Nov 2009
Posts: 11
| Hey, Thanks for the replies. I'm not quite sure either of those will work if I understand them correctly. I should explain myself more. My code consists mainly of two part: that continuous while loop for input and a timer function that gets called every 0.05 seconds. The way it's set up now pressing a key will set a variable that affects the outcome of the timer function. If you release that key the variable will return to it's 'un-pressed' state. The problem I am facing now is that I want simultaneous key presses but I don't have them. Say the user is holding down the space-bar, but wants to press an arrow key. Pressing the arrow key will stop the loop from setting the 'space-bar' variable, but that's not what should happen, the space-bar should not be interrupted and continue after the user releases the arrow key. I have a feeling I might have to fundamentally change how it works so that I can do that. P.S. A related problem I have is that when you press a key it sets the value, pauses for a second, then start setting the value continuously. The same thing that happens as when you're typing and you hold down a key. I also want to change that. |
| TheDenominater is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Curses + Mouse control | guesst | Linux Programming | 0 | 05-26-2008 03:06 PM |
| Curses keyboard input without pause | guesst | Linux Programming | 3 | 04-14-2008 10:22 AM |
| Just wrote my first Curses program | guesst | Linux Programming | 14 | 04-02-2008 10:44 AM |
| output an array to curses, or to another window? | trev456 | C++ Programming | 2 | 04-18-2007 10:08 AM |
| Fonts and colors in curses | Unregistered | C Programming | 1 | 02-26-2002 06:22 AM |