Beispiel #1
0
            public void OnStart()
            {
                Func <bool> chaseZac = ChaseTarget;

                chaseZac += ChaseTarget;
                chaseZac += ChaseTarget;
                chaseZac += ChaseTarget;
                chaseZac += ChaseTarget;
                chaseZac += ChaseTarget;
                chaseZac += ChaseTarget;
                chaseZac += ChaseTarget;

                isDead    = new Condition(() => { return(edible && pacDist < 1); });
                isHome    = new Condition(() => { return(homeDist < 1); });
                isLeaving = new Condition(() => { return(homeTimer < 1); });
                isWander  = new Condition(() => { return(pacDist > 5f); });
                isChase   = (Condition) new[] { chaseZac, chaseZac, chaseZac, ChaseTarget };
                isFlee    = new Condition(() => { return(edible); });
                notFlee   = new Condition(() => { return(!edible); });


                toHome    = new Transistion(sAtHome, new Condition[] { isHome });
                toLeaving = new Transistion(sAtHome, new Condition[] { isLeaving });
                toWander  = new Transistion(sWander, new Condition[] { notFlee, isWander });
                toChase   = new Transistion(sChasing, new Condition[] { notFlee, isChase });
                toFlee    = new Transistion(sFleeing, new Condition[] { isFlee });


                sInit.availableTransitions    = new Transistion[] { toHome };
                sAtHome.availableTransitions  = new Transistion[] { toLeaving };
                sLeaving.availableTransitions = new Transistion[] { toChase, toWander };
                sWander.availableTransitions  = new Transistion[] { toChase, toFlee };
                sChasing.availableTransitions = new Transistion[] { toWander, toFlee };
                sFleeing.availableTransitions = new Transistion[] { toDead, toChase, toWander };
                sDead.availableTransitions    = new Transistion[] { toHome };


                sAtHome.onStateEnter  += () => { homeTimer = 8f; };
                sAtHome.onStateUpdate += () => { homeTimer -= 0.016f; };

                sLeaving.onStateEnter += () => { /*do animation*/ };

                sWander.onStateUpdate  += () => { /*do path-finding*/ };
                sChasing.onStateUpdate += () => { /*do different path-finding*/ };
                sFleeing.onStateUpdate += () => { /*do backwards path-finding*/ };

                sDead.onStateEnter  += () => { /*sprite swap*/ };
                sDead.onStateUpdate += () => { /*go home*/ };
                sDead.onStateExit   += () => { /*sprite swap*/ };

                ghostSM.Initialize(sInit);
            }
Beispiel #2
0
        private bool PerformTransistion(Transistion a_transition)
        {
            if (a_transition == null || a_transition == default)
            {
                return(false);
            }

            currentState.onStateExit?.Invoke();
            currentState = a_transition.targetState;
            currentState.onStateEnter?.Invoke();

            return(true);
        }