Ejemplo n.º 1
0
        public IEnumerator Switches_To_Dead_Only_When_HP_Is_Zero()
        {
            yield return(Helpers.LoadEntityStateMachineTestsScene());

            EntityStateMachine stateMachine = GameObject.FindObjectOfType <EntityStateMachine>();
            Entity             entity       = stateMachine.GetComponent <Entity>();

            // Check that we start in the Idle state
            entity.TakeHit(entity.Health - 1);
            yield return(null);

            Assert.AreEqual(typeof(Idle), stateMachine.CurrentStateType);

            // Check that we transition to Dead state when taking lethal damage
            entity.TakeHit(entity.Health);
            yield return(null);

            Assert.AreEqual(typeof(Dead), stateMachine.CurrentStateType);
        }
Ejemplo n.º 2
0
        /*
         * public override bool OnEnter(GameEntity entity, EntityState previousState, EntityStateMachine fsm)
         * {
         *  entity.GetComponent<EventBus>().AddEventListenerOnce("Hit", () =>
         *  {
         *      fsm.ChangeState(HitState);
         *  });
         *  entity.GetComponent<AnimationController>().ChangeAnimation(AnimatorController, (GameSystem.Instance.PlayerInControl.transform.position - entity.transform.position).x);
         *  return base.OnEnter(entity, previousState, fsm);
         * }*/

        public override void OnUpdate(GameEntity entity, EntityStateMachine fsm)
        {
            if (MoveState && fsm.ChangeState(MoveState))
            {
                return;
            }
            if (JumpState && fsm.ChangeState(JumpState))
            {
                return;
            }
            if (SkillState && fsm.ChangeState(SkillState))
            {
                return;
            }
            if (ClimbState && fsm.ChangeState(ClimbState))
            {
                return;
            }
            if (!entity.GetComponent <MovableEntity>().OnGround&& fsm.ChangeState(AirState))
            {
                return;
            }
            fsm.GetComponent <AnimationController>().PlayAnimation(AnimatorController, (fsm as EntityController).FaceDirection);
        }
Ejemplo n.º 3
0
        public IEnumerator switches_to_dead_state_when_entity_is_dead()
        {
            yield return(Helpers.LoadEntityStateMachineTestsScene());

            EntityStateMachine stateMachine = Object.FindObjectOfType <EntityStateMachine>();
            Entity             entity       = stateMachine.GetComponent <Entity>();

            yield return(null);

            Assert.AreEqual(typeof(EntityIdle), stateMachine.CurrentStateType);

            // Take non lethal damage.
            entity.TakeDamage(entity.Health - 1);

            yield return(null);

            Assert.AreEqual(typeof(EntityIdle), stateMachine.CurrentStateType);

            entity.TakeDamage(entity.Health);

            yield return(null);

            Assert.AreEqual(typeof(EntityChasePlayer), stateMachine.CurrentStateType);
        }