Original Post
Hiya, I've written a basic 2D engine using SDL which can create animations and draw them to screen, play sounds, and take input. Currently, I "register" functions to be run in response to certain input, then I run a function which loops over and over, taking input and running the correct functions then re-blitting everything to the screen. At this point I'm not really sure how I'd do something like different parts of a game. I could make a basic game at this point, but to run the menu separately I'd have to have a switch or something in each of my event-response functions so that the right stuff was drawn to the screen. I've seen some tutorials in the past that talk about some sort of state machine using function pointers -- I'm wondering whether or not this is a good way to structure the flow of my program, so I'd do something like -- state_register ("state_name", KEYPRESS_FUNCTION, keypress_function_ptr); state_register ("state_name", MOUSEMOVE_FUNCTION, mousemove_function_ptr); Then, I could call a function such as switch_state ("state_name"); And the state would be switched to use the new functions. My engine loop would then look like: while (1) { keypress = get_keypress_input (); current_state_keypress_function_ptr (keypress); mousemove = get_mousemove_input (); current_state_mousemove_function_ptr (mousemove); handle_graphics (); } This way, if I'm in the keypress function for a certain state, I can run the switch_state function to switch into a different game state, and the function pointers will all be changed according to what was registered to them earlier. This is all in a hypothetical, so if anyone has a good tutorial or a better way to handle different game states, I would appreciate your posting it here. Thanks in advance! --Russ