hey! another kiwi! wuhkkuhd! chur! bro! etc. (this is choice - when i left NZ two years ago no-one had even heard of this stuff, now there’s folks making it…)
i think you want to veer away from the concept of a ‘timeline’. this is something that only remainsl in Flash/ActionScript because of the legacy of Flash as an animation tool rather than a programming environment, and IMO the timeline should’ve disappeared a long time ago. if you want things to happen after a specific amount of time, have a timer attached to all of this somewhere and change things when it fires… but don’t try and do a full-on Flash style timeline.
basically, i’d do something along the lines of what Arturo said, but i wouldn’t define the state machine as an external object like that, i’d just make it part of the code for the class itself. when i worked for Sidhe i picked up the way they did this, and have been doing it ever since. their approach was to have an enum of states and then do different updates based on the state. eg for a cow, a cow can be standing, walking, running, eating grass, or chewing cud, so you’d have
class Cow {
...
typedef enum { COW_STATE_IDLE, COW_STATE_WALKING, COW_STATE_RUNNING, COW_STATE_EATINGGRASS, COW_STATE_CHEWINGCUD } CowState;
CowState state;
};
then in the constructor or setup() method:
...
state = COW_STATE_IDLE;
then in the update:
if ( state == COW_STATE_IDLE )
{
if ( check if we want to be walking now )
state = COW_STATE_WALKING;
else if ( check if we want to be eating now )
state = COW_STATE_EATING;
else ....
}
else if ( state == COW_STATE_EATING )
{
// do eating update: make belly more full of cud,
// reduce amount of grass, etc
if ( finished eating )
state = COW_STATE_IDLE;
}
else ...
this is kind of cool because it becomes quite easy to come up with emergent behaviours just by coding up simple rules like this…
anyways, hope this helps.
d from Wellies 