Jump to content

  • Log In with Google      Sign In   
  • Create Account


Sequence of Events Design


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Quat   Members   -  Reputation: 403

Like
0Likes
Like

Posted 25 October 2010 - 05:35 AM

Recently I worked on the level complete code for my game. When the level is finished, the following events happen:

1. Animate "Level Complete" sprite onto screen.
2. Animate score stats line 1 onto screen.
3. Animate score stats line 2 onto screen.
4. Wait a few seconds.
5. Fade out to mission select screen.


So basically, a sequence of events take place over a timeline. I am wondering how people organize this type of thing in their games?

Right now I did it the following way, which I did not find very elegant:

In the level Update() I do the following pseudocode:

if( levelComplete )
{
// keep track of how much time has passed since the level is complete.
timeSinceLevelComplete += deltaTime;

StartAnimateLevelComplete();

if(timeSinceLevelComplete >= 2.0)
StartAnimateScoreStatsLine1();

if(timeSinceLevelComplete >= 4.0)
StartAnimateScoreStatsLine2();

if(timeSinceLevelComplete >= 10.0)
StartFadeOut();
}

I could wrap the logic for all this in a class to at least make it more organized, but that class will not be very reusable, as it will contain hardcoded "scripting" logic.


Sponsor:

#2 ncsu121978   Members   -  Reputation: 430

Like
0Likes
Like

Posted 25 October 2010 - 05:51 AM

i use what i call an action queue. the game ownes an action queue (static class) that any other class can push actions onto it. it accepts a base class of CAction to be put in the queue. for any action you want to do you can derive from this base class.

every frame in the main game loop, i call the update and draw methods of the queue which will update/draw the current CAction that it is working with. when it is done with that action, the action queue will automatically dispose of it and start working on the next action.

how does it know when it is done with an action? the action queue queries the current CActions am_i_done_yet() method. if it is true then the action is complete and it is disposed of. the CAction also has an event (c#) that can be subscribed to so that an external class (outside of the action queue) can be notified when it is complete.

where is all this taking us?

for your example you could derive 5 classes from CAction to do the things you mention. When the level is complete, you immediately enqueue all 5 to the action queue, and listen to the event of ONLY the 5th one. when the event signals to you that it is complete, you can then proceed to do whatever you want after that.

that was prolly confusing to you, hope you figure it out or a better way.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS