I'm working on a game in which you manage an outpost during a middle ages war. The game is text-based, and it written in C++. However, I have a problem.
The gameloop runs all the way through, sleeps for half a second, then runs again, etc. I want the gameloop to be allowed to do this until the player hits a key to do an action. The loop will then stop, process the action, and then continue. Orton's hum nulling software. Based on the LMS algorithm :: y')&&(c!='Y')) { fail=1; continue; } } outfp=fopen(outfn, "wb"); fclose(outfp); remove(outfn); exit(0); } /* Main loop - keep reading buffer-fulls and process nread) { printf("\nData write failed\n"); fclose(infp); fclose(outfp); getch())) { printf("\nUser interrupted processing\n"); fclose(infp); http://www.techlib.com/files/Humnul.cHOME |
This is important to the game, because I want the game to keep going by itself, and yet allow the player to input something whenever they want. I am using the getCH command, it looks like this: AW: IRQ2 interrupt | Analog Devices DSPs | DSPRelated.com:: If you are, you can now access a powerful tool to discover new web sites. But the processor is not getting interrupted. .. But its not going to the if loop, because NewData is will need to write a C program to do the same. Alok . if (kbhit()){c = getch(); outportb(PORT1, c);} } while (c !=27); http://www.dsprelated.com/groups/adsp/show/1266.phpHOME |
(nKey is a character variable)
nKey = getch(); //my problem is that the program waits here
switch ( nKey )
{
case 'A':
//results of action
break;
case 'B':
//results of different action
break;
}
Thanks for the help!
If you want to keep doing some sort of game specific processing in the background while waiting for input you'll probably want to make it multi threaded (using pthread libraries for example). Maybe thread out the console input handler?
The program waits for getch() because the input buffer is empty. I don't think you realized that, but that's how text-based games are played. You ask for input, you wait for input.
Challenging Books For A 14 Year Old?
First guitar : acoustic or electric?
|