Exemplo n.º 1
0
        /// <summary>
        /// Initialize controlling state machine
        /// </summary>
        private void InitializeStateMachine()
        {
            //states
            IdleState idleState = new IdleState();
            idleState.Parent = this;
            mStateMachine.AddState(idleState);

            WalkState walkState = new WalkState();
            walkState.Parent = this;
            mStateMachine.AddState(walkState);

            /*
            RunState runState = new RunState();
            runState.Parent = this;
            mStateMachine.AddState(runState);
            */

            GetWalkTarget getWalkTargetState = new GetWalkTarget();
            getWalkTargetState.Parent = this;
            mStateMachine.AddState(getWalkTargetState);
                
            SpawnInState spawnInState = new SpawnInState();
            spawnInState.Parent = this;
            mStateMachine.AddState(spawnInState);

            SpawnOutState spawnOutState = new SpawnOutState();
            spawnOutState.Parent = this;
            mStateMachine.AddState(spawnOutState);

            DeadState deadState = new DeadState();
            deadState.Parent = this;
            mStateMachine.AddState(deadState);

            EatCarrotState eatCarrotState = new EatCarrotState();
            eatCarrotState.Parent = this;
            mStateMachine.AddState(eatCarrotState);


            EatFlowerState eatFlowerState = new EatFlowerState();
            eatFlowerState.Parent = this;
            mStateMachine.AddState(eatFlowerState);

            WinDanceState winDanceState = new WinDanceState();
            winDanceState.Parent = this;
            mStateMachine.AddState(winDanceState);
            LostState lostState = new LostState();
            lostState.Parent = this;
            mStateMachine.AddState(lostState);
            //transitions
            mStateMachine.AddTransition((int)CharacterEvents.To_Walk, idleState, walkState);
            mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, idleState, getWalkTargetState);

            mStateMachine.AddTransition((int)CharacterEvents.To_Idle, walkState, idleState);
            mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, walkState, getWalkTargetState);

            mStateMachine.AddTransition((int)CharacterEvents.To_Walk, getWalkTargetState, walkState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Idle, getWalkTargetState, idleState);

            mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, spawnInState, getWalkTargetState);

            mStateMachine.AddTransition((int)CharacterEvents.To_SpawnOut, getWalkTargetState, spawnOutState);
            mStateMachine.AddTransition((int)CharacterEvents.To_EatCarrot, getWalkTargetState, eatCarrotState);
            mStateMachine.AddTransition((int)CharacterEvents.To_EatFlower, getWalkTargetState, eatFlowerState);


            mStateMachine.AddTransition((int)CharacterEvents.To_Dead, spawnOutState, deadState);

            mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, eatCarrotState, getWalkTargetState);

            mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, eatFlowerState, getWalkTargetState);

            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, getWalkTargetState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, idleState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, walkState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, spawnInState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, spawnOutState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, eatFlowerState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, eatCarrotState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, idleState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, walkState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, getWalkTargetState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, spawnInState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, spawnOutState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, eatFlowerState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, eatCarrotState, lostState);
#if (WINDOWS_PHONE && !SILVERLIGHT)
 mStateMachine.AddTransition((int)CharacterEvents.To_SpawnIn, deadState, spawnInState);
#endif
            //mStateMachine.AddTransition((int)CharacterEvents.To_Run, walkState, runState);
            //mStateMachine.AddTransition((int)CharacterEvents.TimerElapsed, runState, walkState);

            // character starts in a spawn in state
#if (WINDOWS_PHONE && !SILVERLIGHT)
            mStateMachine.StartState = deadState;
#else
            mStateMachine.StartState = spawnInState;
#endif
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize controlling state machine
        /// </summary>
        private void InitializeStateMachine()
        {
            //states
            IdleState idleState = new IdleState();

            idleState.Parent = this;
            mStateMachine.AddState(idleState);

            WalkState walkState = new WalkState();

            walkState.Parent = this;
            mStateMachine.AddState(walkState);

            /*
             * RunState runState = new RunState();
             * runState.Parent = this;
             * mStateMachine.AddState(runState);
             */

            GetWalkTarget getWalkTargetState = new GetWalkTarget();

            getWalkTargetState.Parent = this;
            mStateMachine.AddState(getWalkTargetState);

            SpawnInState spawnInState = new SpawnInState();

            spawnInState.Parent = this;
            mStateMachine.AddState(spawnInState);

            SpawnOutState spawnOutState = new SpawnOutState();

            spawnOutState.Parent = this;
            mStateMachine.AddState(spawnOutState);

            DeadState deadState = new DeadState();

            deadState.Parent = this;
            mStateMachine.AddState(deadState);

            EatCarrotState eatCarrotState = new EatCarrotState();

            eatCarrotState.Parent = this;
            mStateMachine.AddState(eatCarrotState);


            EatFlowerState eatFlowerState = new EatFlowerState();

            eatFlowerState.Parent = this;
            mStateMachine.AddState(eatFlowerState);

            WinDanceState winDanceState = new WinDanceState();

            winDanceState.Parent = this;
            mStateMachine.AddState(winDanceState);
            LostState lostState = new LostState();

            lostState.Parent = this;
            mStateMachine.AddState(lostState);
            //transitions
            mStateMachine.AddTransition((int)CharacterEvents.To_Walk, idleState, walkState);
            mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, idleState, getWalkTargetState);

            mStateMachine.AddTransition((int)CharacterEvents.To_Idle, walkState, idleState);
            mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, walkState, getWalkTargetState);

            mStateMachine.AddTransition((int)CharacterEvents.To_Walk, getWalkTargetState, walkState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Idle, getWalkTargetState, idleState);

            mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, spawnInState, getWalkTargetState);

            mStateMachine.AddTransition((int)CharacterEvents.To_SpawnOut, getWalkTargetState, spawnOutState);
            mStateMachine.AddTransition((int)CharacterEvents.To_EatCarrot, getWalkTargetState, eatCarrotState);
            mStateMachine.AddTransition((int)CharacterEvents.To_EatFlower, getWalkTargetState, eatFlowerState);


            mStateMachine.AddTransition((int)CharacterEvents.To_Dead, spawnOutState, deadState);

            mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, eatCarrotState, getWalkTargetState);

            mStateMachine.AddTransition((int)CharacterEvents.To_GetTarget, eatFlowerState, getWalkTargetState);

            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, getWalkTargetState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, idleState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, walkState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, spawnInState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, spawnOutState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, eatFlowerState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_WinDance, eatCarrotState, winDanceState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, idleState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, walkState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, getWalkTargetState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, spawnInState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, spawnOutState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, eatFlowerState, lostState);
            mStateMachine.AddTransition((int)CharacterEvents.To_Lost, eatCarrotState, lostState);
#if (WINDOWS_PHONE && !SILVERLIGHT)
            mStateMachine.AddTransition((int)CharacterEvents.To_SpawnIn, deadState, spawnInState);
#endif
            //mStateMachine.AddTransition((int)CharacterEvents.To_Run, walkState, runState);
            //mStateMachine.AddTransition((int)CharacterEvents.TimerElapsed, runState, walkState);

            // character starts in a spawn in state
#if (WINDOWS_PHONE && !SILVERLIGHT)
            mStateMachine.StartState = deadState;
#else
            mStateMachine.StartState = spawnInState;
#endif
        }