sdl program not restarting

i have literally spent all night trying to ask the user to if he wants to play again pres enter, and when he does press enter, the game restarts but i guess some of the variables doesnt reload properly or i dont know what happens,
can any one suggest me a way of how i should rerun this whole program properly
thanks.

by the way, i did create a function to re initialize everything and call that ftn in the main while loop, so when if any of the 2 player wins he would be prompted a texture to press enter to try again and escape to quit, bu tthat doesnt worked either.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
game.initialize(); //to initalize all my variables
        
        while (is_running) {
            ticks_for_caping_fps = SDL_GetTicks();

            while (SDL_PollEvent(&main_event)) {
                if (main_event.type == SDL_QUIT) {
                    is_running = false;
                    break;
                }

                //check if both players are selected
                check_if_both_players_selected(main_event, state);

                if (main_event.type == SDL_KEYDOWN) {
                    if (both_player_selected == true && sound_flag == false) {
                        switch (main_event.key.keysym.sym) {
                            //if user wants to start the game
                        case 13://enter key numeric code
                            state = fighting;
                            gb_music.load_background_music(state);
                            gfight_sound.load_sound_effect("sounds/fight.mp3", 0);

                            player1.create_player(player_selected[0]);
                            player2.create_player(player_selected[1]);
                            sound_flag = true;
                        }
                        break;
                    }
                }

                player1.handleEvent(main_event);
                player2.handleEvent(main_event);
            }

            SDL_SetRenderDrawColor(grender, 255, 255, 255, 255);
            SDL_RenderClear(grender);

            //load main menu
            game.load_main_menu();

            game.start_game(main_event);

            SDL_RenderPresent(grender);
            capfps(ticks_for_caping_fps);//fps would not go higher than 60
        }
Last edited on
debug it, step through what all your variables are in the second run. You just missed something... note that often in such cases objects that were created with a ctor need a reset that does the same thing the ctor does to any values.
Topic archived. No new replies allowed.