Exemple #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();
            }
        }
Exemple #2
0
 public override void Initialize()
 {
     animationComponent = Entity.Get<AnimationComponent>();
     atkState = StateMachine.GetState(typeof(AttackState));
     runState = StateMachine.GetState(typeof(RunState));
 }
Exemple #3
0
 public abstract void End(StateMachineState nextState);
Exemple #4
0
 public abstract void Begin(StateMachineState previouState);
Exemple #5
0
 public override void End(StateMachineState nextState)
 {
 }
Exemple #6
0
 public override void Begin(StateMachineState previouState)
 {
     Shoot();
 }
Exemple #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");
 }
Exemple #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;
 }