Esempio n. 1
0
        public override async Task Execute()
        {
            var scripts = Entity.Get<ScriptComponent>();
            for (var index = 0; index < scripts.Scripts.Count; index++)
            {
                var script = scripts.Scripts[index];
                var machineState = script as StateMachineState;
                if (machineState != null)
                {
                    states.Add(machineState.GetType(), machineState);
                    machineState.StateMachine = this;
                }
            }

            foreach (var stateMachineState in states)
            {
                stateMachineState.Value.Initialize();
            }

            currentState = states.First().Value;
            currentState.Begin(null);

            while (Game.IsRunning)
            {
                if (currentState.ShouldEnd() && currentState.Next() != null)
                {
                    var nextState = currentState.Next();
                    var prevState = currentState;
                    currentState.End(nextState);

                    currentState = nextState;
                    currentState.Begin(prevState);
                }

                currentState.Update();

                await Script.NextFrame();
            }
        }
Esempio n. 2
0
 public override void Initialize()
 {
     animationComponent = Entity.Get<AnimationComponent>();
     atkState = StateMachine.GetState(typeof(AttackState));
     runState = StateMachine.GetState(typeof(RunState));
 }
Esempio n. 3
0
 public abstract void End(StateMachineState nextState);
Esempio n. 4
0
 public abstract void Begin(StateMachineState previouState);
Esempio n. 5
0
 public override void End(StateMachineState nextState)
 {
 }
Esempio n. 6
0
 public override void Begin(StateMachineState previouState)
 {
     Shoot();
 }
Esempio n. 7
0
 public override void Begin(StateMachineState previouState)
 {
     for (var index = 0; index < animationComponent.PlayingAnimations.Count; index++)
     {
         var animation = animationComponent.PlayingAnimations[index];
         if (animation.Name == "Run") return;
     }
     animationComponent.Play("Run");
 }
Esempio n. 8
0
 public override void Initialize()
 {
     animationComponent = Entity.Get<AnimationComponent>();
     atkState = StateMachine.GetState(typeof(AttackState));
     idlState = StateMachine.GetState(typeof(IdleState));
     baseScaleX = Entity.Transform.Scale.X;
 }