Sign in to follow this  
Mullanimal

Waiting for user input inside a game loop

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this