-
Keyboard?
OK.
I have a BIG problem...
I want to know how to make my program do some different things at the same time. I've heared that it's called multitasking, but I don't know anything about it. There was some function for that purpose, but what was it and how can I use it? You could also tell me how to make program to wait until some key is pressed and do something what I want, without affecting on the some other task that it's doing. :confused: Or is it the same multitasking?
Well... I wait forward for your ansewrs ;)
-
to follow up on that, can you use this, if you can, in DOS apps? Thats all i know how to do, lol...im such a loser, i cant grasp windows programming
-
It makes two of us....;)
I also have some SERIOUS problems with the Windows-monster.
-
Windows programming is not harder (in many ways, it's easier) but it's just DIFFERENT. It takes a lot of knowing how to set stuff up.
For multitasking in DOS, it may be easiest to have one loop that is constantly running, and simply call a lot of fuctions to do one "cycle" of each task. So, if you had a main loop for a game, and you wanted to check for input, move the sprites, and apply damage to various sprites if necessary, then draw the screen, you could just do something like this:
Code:
while (exit == false){
CheckForInput();
MoveSprites();
ApplyDamage();
DrawScreen();
}
Key input isn't hard, but you should NOT wait for it, unless you have a multithreaded game. Rather, your CheckForInput(); should immediately return if there is no input ready, so the rest of your game doesn't stall. You never want to stall the main loop, ever.
Doing keystrokes in DOS is not the easiest thing, especially if the goal is a game where certain keys will be held down. Usually, it is recommended that you write your own keyboard interrupts for this purpose -- and I've long sinc stopped DOS programming so I no longer have any sample code to give you =/
Check books on DOS game programming -- they'll give you lots of helpful advice.
-
Good tip about stalling the main function, i just have no clue how i would do that...if ive got a case statement that requires the user to hit arrow keys to move around, how would i make it so if there isnt any input it skips it? kinda conufsing question/topic. thanks for your input tho, lol
-
Well, you'll probably need to create a new keyboard handler, and then, you move only if an arrow key is down, else you won't move.
Many people have written keyboard handlers for DOS programs (I used to have one on the web at one point, too). This looks, at a glance, to be what you need:
http://www-scf.usc.edu/~akotaobi/opkey.html
Using this guy's keyboard handler, you'd just do things like:
if (tbl[SCAN_UP]) {
// Move up
}
-
check out c-for-dummies.com - he has a section on DOS multitaksing.
-
alright, thanks a lot guys. that should help.