示例#1
0
        public AliveBunnyState(object thisObject, Vector2 setpoint1, Vector2 setpoint2)
            : base("AliveBunnyState_StateMachine")
        {
            this.thisObject = thisObject;
            IState patrol = new PatrolBunnyState(thisObject, setpoint1, setpoint2);
            IState charge = new ChargingBunnyState();

            patrolToCharge = new DistanceTest(patrolTochargeDist - patrolToChargeHisteresis / 2);
            chargeToPatrol = new DistanceTest(patrolTochargeDist + patrolToChargeHisteresis / 2);

            charge.setThisObject(thisObject);

            Transition t = new Transition();

            t.nextState      = charge;
            t.transitionTest = patrolToCharge.lesser;
            patrol.addTransition(MessageTypes.characterPosition, t);

            t                = new Transition();
            t.nextState      = patrol;
            t.transitionTest = chargeToPatrol.greater;
            charge.addTransition(MessageTypes.characterPosition, t);

            InitialState = patrol;
        }
示例#2
0
        public AliveFlowerState(object thisObject)
            : base("AliveFlowerState_StateMachine")
        {
            this.thisObject = thisObject;
            IState idle   = new IdleFlowerState();
            IState evil   = new EvilFlowerState();
            IState attack = new AttackingFlowerState();

            idleToEvil   = new DistanceTest(idleToEvilDist - idleToEvilHisteresis / 2);
            evilToIdle   = new DistanceTest(idleToEvilDist + idleToEvilHisteresis / 2);
            evilToAttack = new DistanceTest(evilToAttackDist - evilToAttackHisteresis / 2);
            attackToEvil = new DistanceTest(evilToAttackDist + evilToAttackHisteresis / 2);

            idle.setThisObject(thisObject);
            evil.setThisObject(thisObject);
            attack.setThisObject(thisObject);

            Transition t = new Transition();

            t.nextState      = evil;
            t.transitionTest = idleToEvil.lesser;
            idle.addTransition(MessageTypes.characterPosition, t);

            t                = new Transition();
            t.nextState      = idle;
            t.transitionTest = evilToIdle.greater;
            evil.addTransition(MessageTypes.characterPosition, t);
            t                = new Transition();
            t.nextState      = attack;
            t.transitionTest = evilToAttack.lesser;
            evil.addTransition(MessageTypes.characterPosition, t);

            t                = new Transition();
            t.nextState      = evil;
            t.transitionTest = attackToEvil.greater;
            attack.addTransition(MessageTypes.characterPosition, t);

            InitialState = idle;
        }