Setting a time limit for a level in 2D game


So I am have made this 2D ball game. But I want to set a time limit for each level. I want player to play that level for maximum 3 minutes. After 3 minutes the game level should end. I have used allegro 5.0.10 with c++ .

How to achieve it? C'mon! I can use some help from c++ experts over here.
Not to sound mean but it would of been easier for you to quickly search "allegro timers" in google then wait for an answer here.

If you want to use the built in timer events read this page carefully.
http://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Timers

Otherwise create your own timer class and keep track of how much time has passed since the timer was started with https://www.allegro.cc/manual/5/al_get_time (You would set that to a variable as soon as you start the timer).

Making it last 3 minutes shouldn't be too hard with either of those.
Games typically have a main logic loop:

1
2
3
4
5
6
while( game_is_running )
{
    process_user_input();
    do_game_logic();
    draw_a_frame();
}


If you want to add a timeout, you can just add the timeout there:

1
2
3
4
5
6
7
8
9
10
while( game_is_running )
{
    process_user_input();
    do_game_logic();
    draw_a_frame();
    if( current_time() - timeSinceLevelStart > threeMinutes )
    {
        end_the_level();
    }
}



OR do that in your do_game_logic() function.
Topic archived. No new replies allowed.