[This message has been edited by Haplo (edited December 13, 1999).]
Simultaneous Keyboard Input in C++
#1 Members - Reputation: 122
Posted 15 December 1999 - 10:22 PM
#2 Members - Reputation: 122
Posted 13 December 1999 - 05:31 PM
It really depends on how you're doing your input right now. C++ by itself really doesn't have the keyboard functionality you need to do what you want, you're going to have to use some win32 calls (assuming you're writing this for windows)
Assuming you're doing your input by checking for a keypress, then reading the key by getch() or something similar, what you need to do is check the current state of the keys you're interested in.
try something like this :
if (GetAsyncKeyState(VK_UP) {
// handle UP arrow -- up for player 1
}
if (GetAsyncKeyState(VK_W)) {
// handle W key -- up for player 2
}
Hope that helps.
------------------
- Remnant
- (Steve Schmitt)
#4 Members - Reputation: 122
Posted 13 December 1999 - 05:49 PM
If they knew how to do really good programming they'd get a programming job and make a lot more money.
Now on to answering the actual question - If you're writing this for DOS (which a fair amount of CS classes are still DOS-based) then you'll have to look at overriding the keyboard ISR, that involves some nasty 80x86 Assembly and other garbage that would take too long to explain here.
If you want a full explanation of keyboard ISRs and a good intro book for DOS game programming look for "Teach Yourself Game Programming in 21 Days" by Andre Lamothe. It'll take you longer than 21 days to read and fully understand probably, but it's well worth it.
However, DOS programming is becoming almost nonexistent in games, so you might as well make the move to Windows as soon as possible.
In windows simultaneous keyboard input is a cinch, and the general code is in a post above me.
However, if you want an explanation of how this code works, or an introduction to windows programming, or an intro to game programming in windows then I'd HIGHLY, and I mean HIGHLY suggest the book "Trick of the Windows Game Programming Books" by Andre Lamothe.
I barely knew what "Win32" meant when I got that book, and now I feel confident that I know DirectX, basic Win32 code (very basic, but enough for a game) and all kinds of cool stuff.
Anyway, that's my thoughts.
P.S. - one last note : If (when) you go to windows, use VC++, it has the least problems with DirectX and all the documentation on MSDN assumes you're using it (to my knowledge...)
------------------
gameguru4@yahoo.com
#5 Members - Reputation: 172
Posted 13 December 1999 - 05:57 PM
BTW, help files rule!!!
#6 Members - Reputation: 122
Posted 13 December 1999 - 06:45 PM
And another one: The computer besides me made a lot of noise. The teacher shouts to shut of the sound of my computer and stop playing games (sounds familiar?). Everyone was saying that it really wasn't my computer. It took him at least 5 minutes to understand (ARGH!).
#7 Members - Reputation: 144
Posted 13 December 1999 - 07:10 PM
I just figured that by now the all the crazy math teachers that got stuck teaching a programming class had all perished by now. Make way for the CS teacher that knows what an interupt is. (and maybe how to use one).
#8 Members - Reputation: 122
Posted 13 December 1999 - 10:27 PM
I do know that my teacher was a capable programmer and could definatly have got a programming job if he wanted too, but he didn't he enjoyed his job as a teacher and was good at it, mind you he had come from a maths background too.






