Advertisement

Don't wait for input

Started by February 22, 2002 12:09 PM
1 comment, last by Zuljin 22 years, 9 months ago
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
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!
Advertisement
Ahh, many Thanks, that will bring me closer to my 1st game

This topic is closed to new replies.

Advertisement