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?
Cancel
Save
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()
Cancel
Save
Dang, so this could possible get complicated with porting issues eh ?
Cancel
Save
What? No, of course not. Multithreading would have been more complicated with porting issues.
Cancel
Save
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.
Cancel
Save