• Advertisement
Sign in to follow this  

C++ Allegro Pausing The Game

This topic is 2383 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

I've been searching all around, for the existence of a pause function in allegro, I have not been able to find one, and I'm left with the option of multi-threading, to test for a key input while drawing, and moving functions of allegro are disabled. I've even thought about going as far as something like this...


class foo
{
public:
bool paused;
void init();
bool test_paused();
bool can_move;
};

void foo::init()
{
paused = false;
can_move = true;
}

void foo::test_paused()
{
if(paused == true)
{
can_move = false;
}
}


This code is really not in my program, it was just an example of what I was considering.
Any thoughts?

Share this post


Link to post
Share on other sites
Advertisement
Pausing the game isn't Allegro-specific.

Hint:
If you read up on finite state machines, you'll find the solution quite simple:


while running:
process_events()
update_game()
render_game()

update_game:
switch state:
on play_state: update_play_state()
on pause_state: update_pause_state()
on menu_state: update_menu_state()

render_game:
switch state:
on play_state: render_play_state()
on pause_state: render_pause_state()
on menu_state: render_menu_state()

update_play_state:
if pause_key is pressed
state = pause_state
return
if game_over
state = menu_state
return
game_update()

update_pause_state:
set_music_volume( 0.20 )
if pause_key is pressed
set_music_volume( 1 )
state = play_state

render_play_state:
game_render()

render_pause_state:
game_render()
render_pause_overlay()

Share this post


Link to post
Share on other sites
So the game would remain paused as long as the play is holding the button ?

But my game looks really, really similar in format to your pseudo code. It might not be as hard as I thought.

Share this post


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

  • Advertisement