1
\$\begingroup\$

I'm having some trouble understanding ways to sequence events in my game. Assume the game is data driven, what is the best way to control the events?

Do I have some sort of EventSequencer that loads all the possible events for a level and the enemies? If so, would it be a list of events that I 'fire' off one at a time into the game engine and when the event is completed or finished, remove the event and fire the next one?

My thoughts were similar to the above questions: Build an event sequencer that manages what event is running and loads the proper event (enemy wave, boss battle, etc)...

I'm just not sure if this is a good idea.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ It sounds like you're suffering from design paralysis. Why don't you just try it and get back to us when you actually have a real problem instead of a theoretical one? \$\endgroup\$
    – Tetrad
    Commented Mar 23, 2013 at 13:08
  • \$\begingroup\$ Sounds like you need trigger zones (e.g. an area or volume which can start events when the player enters/leaves it). I'd store the position and extends (and maybe orientation and shape) of the trigger zone and a reference to the script which should be executed upon entering the trigger zone with the level data. A script can be as simple as a single command (e.g. spawn an enemy) or a list of commands (spawn explosion, spawn enemy, change to boss fight state). \$\endgroup\$
    – Exilyth
    Commented Mar 23, 2013 at 14:21

1 Answer 1

2
\$\begingroup\$

Based on your example "events", I would probably use a state machine with rules on which state can come next. You can be in EnemyWave state, and as soon as the last enemy is killed switch to BossBattle state. A simplistic code fragment might look like this

class EnemyWave : State
{
    void main()
    {
        // Game logic for handling the enemy wave
    }
    State nextState()
    {
        if(allEnemiesDead)
        {
            return new BossBattle();
        }
        else
        {
            return this;
        }
    }
}

mainLoop()
{
    // Game logic goes here

    // State specific logic
    currentState.Main();

    // More game logic

    // Ask state for next state
    currentState = currentState.nextState();
}

If the game is data driven, then your nextState condition would be driven by your data, and your game logic for the particular state just gets swapped in.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .