• Advertisement

Archived

This topic is now archived and is closed to further replies.

Don't wait for input

This topic is 5847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i''m a N00b I am working on a 2D RTS right now, i have finished the Ai and some Easy Pathfinding Procedures, but now i came to the Part where i wanted to make the game "REALTIME", i need a procedure for something like following in C++ : wait 1 second for input SO i want that my prog waits on sec for input, and if no input is given in the sec the prog should start the next round and then waits again for input. THX Zuljin

Share this post


Link to post
Share on other sites
Advertisement
I generally advise against this method, but it''s an easy way to start and understand the basic principles. Later you can use more advanced techniques to get the actual input.

  
char c;
// This code should be in your main loop

// 1. see if there is any input (keyboard)

if(kbhit())
{
// 2. get the actual key pressed

c = getch();
.
// 3. respond to the input

switch(c)
{
case ''a'': // respond to A (lower- or uppercase)

case ''A'':
//... do something

break;
.
case ''b'': // B. You have to quote the character, even numbers!

case ''B'':
break;
.
//... etc

.
default: // if the input isn''t any of the characters that you respond to

// do something. usually we do "nothing"

break;
}
}


The genera; methodology above is applicable to DirectInput and Win32 mouse/key events as well, but you''ll need to modify it to handle simultaneous multiple keypresses.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites

  • Advertisement