// 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);
    }
示例#2
0
    public void Initialize(GameObject followTarget)
    {
        FollowTarget = followTarget;

        ZombieIdleState idleState = new ZombieIdleState(this, StateMachine);

        StateMachine.AddState(ZombieStateType.Idle, idleState);

        ZombieFollowState followState = new ZombieFollowState(FollowTarget, this, StateMachine);

        StateMachine.AddState(ZombieStateType.Follow, followState);

        ZombieAttackState attackState = new ZombieAttackState(FollowTarget, this, StateMachine);

        StateMachine.AddState(ZombieStateType.Attack, attackState);


        ZombieDeadState deadState = new ZombieDeadState(this, StateMachine);

        StateMachine.AddState(ZombieStateType.Dead, deadState);


        //StateMachine.Intialize(ZombieStateType.Idle);
        //StateMachine.Intialize(ZombieStateType.Follow);
        //StateMachine.Intialize(ZombieStateType.Attack);
        StateMachine.Intialize(ZombieStateType.Dead);
    }
示例#3
0
 private void InitilizeStates()
 {
     aiStates            = new List <AIState>();
     chase               = new ZombieChaseState();
     chase.stateName     = "chase";
     attack              = new ZombieAttackState();
     attack.stateName    = "attack";
     stun                = new ZombieStunState();
     stun.stateName      = "stun";
     celebrate           = new ZombieCelebrateState();
     celebrate.stateName = "celebrate";
     getUp               = new ZombieGetUpState();
     getUp.stateName     = "getUp";
     aiStates.Add(chase);
     aiStates.Add(attack);
     aiStates.Add(stun);
     aiStates.Add(celebrate);
     aiStates.Add(getUp);
 }