Jump to content
  • Advertisement
Sign in to follow this  
Mullanimal

Waiting for user input inside a game loop

This topic is 3284 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

I am making a simple poker game using Dev C++ and the SDL library. Following a suggestion from a tutorial i have separated the logic of a game into a game loop. Here is some rough code from the game loop. Basically this code increments player turn and runs AI so what i am unsure about is when it is a human players turn, how do i stop the loop from continuing until i have received a user action given this is a GUI application. while(!gameNotOver){ playerTurn++; if( playerTurn.type == AI ) { runAI(); } else if ( playerTurn.type == HUMAN ) { // wait/get user input} }

Share this post


Link to post
Share on other sites
Advertisement
You don't. You should access a message quewe from wich you'll retrieve input events from each frame.

Share this post


Link to post
Share on other sites
You can put your "playerTurn++" inside the brackets.

if( playerTurn.type == AI ) { runAI(); playerTurn++;}
else if ( playerTurn.type == HUMAN ) {
bool userHasInput = GetUserInput(); // check keyboard, mouse, etc.
// return false is player is not done yet
if(userHasInput) playerTurn++;
else { // sleep, let other applications have the CPU for a while }
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!