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