Public Group

Archived

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

Don't wait for input

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

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 on other sites
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 on other sites
Ahh, many Thanks, that will bring me closer to my 1st game

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• Forum Statistics

• Total Topics
633323
• Total Posts
3011361
• Who's Online (See full list)

There are no registered users currently online

×