Пример #1
0
    // The NPC has 4 states: Patrol, Chasing, Attack, Dead
    private void ConstructFSM()
    {
        ZombiePatrolState patrol = new ZombiePatrolState();

        patrol.AddTransition(ZombieTransition.SawHuman, ZombieFSMStateID.Chasing);
        patrol.AddTransition(ZombieTransition.NoHealth, ZombieFSMStateID.Dead);
        patrol.AddTransition(ZombieTransition.ReachShelter, ZombieFSMStateID.Win);

        ZombieChaseState chase = new ZombieChaseState();

        chase.AddTransition(ZombieTransition.LostHuman, ZombieFSMStateID.Patrolling);
        chase.AddTransition(ZombieTransition.ReachHuman, ZombieFSMStateID.Atakking);
        chase.AddTransition(ZombieTransition.NoHealth, ZombieFSMStateID.Dead);
        chase.AddTransition(ZombieTransition.ReachShelter, ZombieFSMStateID.Win);

        ZombieAttackState attack = new ZombieAttackState();

        attack.AddTransition(ZombieTransition.LostHuman, ZombieFSMStateID.Patrolling);
        attack.AddTransition(ZombieTransition.SawHuman, ZombieFSMStateID.Chasing);
        attack.AddTransition(ZombieTransition.NoHealth, ZombieFSMStateID.Dead);
        attack.AddTransition(ZombieTransition.ReachShelter, ZombieFSMStateID.Win);

        ZombieDeadState dead = new ZombieDeadState();

        dead.AddTransition(ZombieTransition.NoHealth, ZombieFSMStateID.Dead);

        fsm = new ZombieFSMSystem();
        fsm.AddState(patrol);
        fsm.AddState(chase);
        fsm.AddState(attack);
        fsm.AddState(dead);
    }
    private void InitializeFSM()
    {
        ZombieChaseState chase = new ZombieChaseState();

        chase.AddTransition(Transition.PlayerLost, StateID.Idling);
        chase.AddTransition(Transition.PlayerReached, StateID.Attacking);
        chase.AddTransition(Transition.NoHealth, StateID.Dead);

        ZombieIdleState idle = new ZombieIdleState();

        idle.AddTransition(Transition.PlayerSpotted, StateID.Chasing);
        idle.AddTransition(Transition.PlayerHeard, StateID.Alert);
        idle.AddTransition(Transition.NoHealth, StateID.Dead);

        ZombieAttackingState attack = new ZombieAttackingState();

        attack.AddTransition(Transition.PlayerOutOfRange, StateID.Chasing);
        attack.AddTransition(Transition.NoHealth, StateID.Dead);

        ZombieAlertState alert = new ZombieAlertState();

        alert.AddTransition(Transition.PlayerLost, StateID.Idling);
        alert.AddTransition(Transition.PlayerSpotted, StateID.Chasing);
        alert.AddTransition(Transition.NoHealth, StateID.Dead);

        ZombieDeadState dead = new ZombieDeadState();

        AddState(attack);
        AddState(chase);
        AddState(idle);
        AddState(alert);
        AddState(dead);
    }