diff options
Diffstat (limited to 'examples/state_machine/main.cpp')
-rw-r--r-- | examples/state_machine/main.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/examples/state_machine/main.cpp b/examples/state_machine/main.cpp index 7d83d2b..c061a81 100644 --- a/examples/state_machine/main.cpp +++ b/examples/state_machine/main.cpp @@ -14,16 +14,33 @@ using namespace JinEngine::Time; ParticleSystem* p; StateMachine sm; Timer timer; +enum +{ + STATE_EMPTY = 0, + STATE_RUN, + STATE_IDLE, + STATE_SLEEP, + STATE_JUMP +}; + +enum +{ + PARAM_RUN = 1, + PARAM_IDLE = 2, + PARAM_IDLE2 = 3, + PARAM_RUN = 4 +}; + void onLoad() { - sm.addState("Run"); - sm.addState("Idle"); - sm.addState("Sleep"); - sm.addState("Jump"); - sm.addParametert("run"); - sm.addParameterb("idle"); - sm.addParameterb("idle2"); - sm.addTransition("Empty", "Idle", StateMachine::Conditions().andt("run")); + sm.addState(STATE_RUN); + sm.addState(STATE_IDLE); + sm.addState(STATE_SLEEP); + sm.addState(STATE_JUMP); + sm.addParametert(PARAM_RUN); + sm.addParameterb(PARAM_IDLE); + sm.addParameterb(PARAM_IDLE2); + sm.addTransition(STATE_EMPTY, STATE_IDLE, StateMachine::Conditions().andt(PARAM_RUN)); sm.addTransition("Idle", "Run", StateMachine::Conditions().andb("idle", StateMachine::BOOL_IS, true).andb("idle2", StateMachine::BOOL_IS, true)); sm.setEnterListener([](const string& state, void* p) { cout << "Enter: " << state << endl; |