Sign in to follow this  
lukeymoo

C++ Allegro Pausing The Game

Recommended Posts

lukeymoo    106
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...

[code]
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;
}
}
[/code]

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
fastcall22    10845
Pausing the game isn't Allegro-specific.

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

[code]
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()
[/code]

Share this post


Link to post
Share on other sites
lukeymoo    106
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this