0

i have a game loop, i want to be able to make it temporary stop and then make it run again.

I TRIED to freeze and unfreeze the game by passing a boolean variable by reference to void functions, which their job is to set the variables value to true and false.

there are 3 functions in the game loop here is a pseudo code:

while(!quit)  
     if(!freeze):  
     [handle events()] -> [move()] ->[render()] (REPEAT)
void game_over(int *flag);
void restart_game(int *flag);

void game_over(int *flag)`  
{  
    *flag = 0;  
}  
void restart_game(int *flag)  
{  
    *flag = 1;  
}

int main()  
{  
    //freeze boolean flag initially false  
    int freeze = 0;  
    SDL_event e;  
    //game loop  
    int quit = 0;  
    while(!quit)  
    {  
        if(!freeze)  
            {  
                 while(SDLPollEvent(&e) != 0)  
                 {  
                      switch(e.key.keysym.sym)  
                      {  
                           case SDLK_t:  
                               game_over(&freeze);//passing freeze address  
                               break;  
                           case SDLK_r:  
                               restart_game(&freeze);  
                               break;  
                      }  
                 }  
                 move();  
                 render();  
            }  
    }  
    close();  
    return();
}

PROBLEM IS when i press r ( when the restart-game() is called) the program becomes so heavy that i can hardly close it (infinity loop) .
can anyone think of what needs to be fixed or what is perhaps a better approach?

genpfault
  • 51,148
  • 11
  • 85
  • 139
no_hope
  • 39
  • 5

0 Answers0