• Advertisement
Sign in to follow this  

Need advice with game loop

This topic is 1286 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 am newbie to game programming, so excuse me if I ask silly question.

I start to implement my first game. The game is like a turn-base board game.(implemented using Java for Android)

Each player have 14 soldiers. each soldier placed/located in default position.

Before starting game, there is an 'INIT' stage, where each player can change the default location of each of his soldiers.

After each player set their soldiers, the game can start.

 

My game loop(pseudo code)

while(true){
	processUserEvents();	// if its player's TURN, will update the event(else will drop it)
	draw();			// redraw			
}

My question is: should the stage of 'INIT' need to be inside game loop?

or it should be in a different place, and when 'INIT' finished, only then execute game loop ?

 

any byte of advice will help.

 

Share this post


Link to post
Share on other sites
Advertisement

Ok Thanks..

 

BTW, user input(such as touch event), are stored in Queue, instead of handling them immediately.

In every iteration of game loop i 'poll' event from the queue and handle it.

Share this post


Link to post
Share on other sites

 

Before starting game, there is an 'INIT' stage, where each player can change the default location of each of his soldiers.

 

Ooops, didn't read it thorough. Of course in this case this should be in game loop. SORRY for inconvenience.

Share this post


Link to post
Share on other sites

In this instance I'd be inclined to do something like...

initialise_game();

bool replay = true;

while( replay )
{
    get_player_start_locations(); // this function would have a mini game loop while players set their starting locations
    
    bool running = true;

    while( running )
    {
        running = process_user_events(); // return false when player hits quit button etc.
 
        if( running == true )
        {
            draw();
        }
    }

    replay = ask_if_player_wants_another_game(); // again, a mini game loop in here while replay question is displayed
}

shut_down_game();
Edited by mark ds

Share this post


Link to post
Share on other sites
Maybe you can create a set of states, so depending on the game state something will happen when you're in the game loop. In your case you could have a state "menu" in which the player can either change the positions you mentioned or config something else. And another state coud be "game_running"

Share this post


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

  • Advertisement