I’ve been programming in c++ for a bit now and Im very familiar with the syntax. I’m trying to use Allegro to make a card game. I understand everything I need to do for the game logic and what not. What puzzles me is how to drive the game. I’m sort of new to loop based applications. I got used to event based programming in VB .Net. I’m just not sure the proper way of for example switching players and raising “events” without having lots of ifs and bools. Also right now I have an array of bool to check which card is in play. And my game iterates through the whole bool array every time and it seems messy to me. Also, if I want to go from my menu loop to my settings loop, how is that done without a big bool?
Thanks
I’ve been programming in c++ for a bit now and Im very familiar with
Share
Most gaming frameworks provide two methods you need to implement (both of them are called in a loop):
The
Updateis where you should put all that stuff, which should check for User input, state changes, intervalled actions etc. Examples would be Physics, ButtonPressed, etc. Nothing prevents you from working with events here (have a look at BoostLibrary Signals).The
Drawshould just render the current, underlying state to the screen. So you have to make sure your underlying state/model is easy to access.You can solve your Menu/SettingsMenu issue with
Scenesand aSceneManager(which can be a Stack). So instead of putting the logic into theGamedirectly, you put it intoScenes. And you can push/pop scenes to/from the Manager.If you want to start with more advanced stuff, you could try to store “events” into a huge list and fire all events when you enter the
Game::updatemethod – this is how VB makes sure that you can’t modify controls from another thread than the UI thread – but I don’t think that this is something you would do using C++.