much as possible, you want to separate your actual drawing (display) from
your game logic (update).
want to update at a constant frame rate. If you don’t, as you add more
objects to your scene, the game will slow down.
A simple display/update loop:
while (elapsed < frame_time);
option is to keep the update rate constant, but display as quickly as
possible. This will also handle crappy machines with slow displays.
A fancier display/update loop:
while (elapsed < frame_time)
matter what your game involves, see if you can use actors to play the
types! Make an enumerated type showing all your actors
you can access each individual member of the gameActors array be just
now, of course, you can loop through your entire actors array to perform
operations (like drawing, updating animations, etc.) on them.
can perform tasks, that often cause specific animations to be played. Make
tasks an enumerated type, just like your actors.
for (i=0; i<NUM_CHEERLEADERS; i++)
More on displays
for (actorNum=0; actorNum<NUM_ACTORS;
Actor* actor = gameActors[actorNum];
- Make a
state machine indicating which game state you’re currently in
(STATE_PREGAME, STATE_INGAME, STATE_AFTERGOAL, etc…), and make decisions
based on game events, user input, and your current state.
can use state machines for buttloads of other stuff too. As an example,
for opponent AI, you can have actors be in either a (STATE_TRACK, STATE_RETREAT,
STATE_PASS, STATE_SHOOT, STATE_RUN_FOR_PASS) state, and have it change
depending on game conditions at the time.