Esempio n. 1
0
        public FindFoodState(EntityStateMachine ownerFiniteStateMachine) : base(ownerFiniteStateMachine)
        {
            SeekBehaviour seekBehaviour = new SeekBehaviour(OwnerEntity.SeekTarget, OwnerEntity);

            wanderBehaviour = new WanderBehaviour(OwnerEntity);
            steeringBehaviours.Add(seekBehaviour);
            steeringBehaviours.Add(new DistancingBehaviour(OwnerEntity));
            steeringBehaviours.Add(new ObstacleAvoidance(OwnerEntity));
            Name = "FindFood";

            // If the entity doesn't have a target for some reason, try to find one
            if (OwnerEntity.SeekTarget == null)
            {
                // try to find new target
                seekBehaviour.NewTarget(OwnerEntity.SeekTarget);
                // If it's still Null, no targets exist
            }
        }
Esempio n. 2
0
 public override void OnStateUpdate(GameTime gameTime)
 {
     // If the seekTarget is null, there are no valid targets. In that case,
     // default back to wandering
     // SeekTarget automatically tries to get a new target in the getter
     if (OwnerEntity.SeekTarget == null && !isWandering)
     {
         steeringBehaviours.Add(wanderBehaviour);
         isWandering = true;
     }
     else
     {
         // If it found a target, no longer wander
         steeringBehaviours.Remove(wanderBehaviour);
         isWandering = false;
         SeekBehaviour seekbehaviour = (SeekBehaviour)steeringBehaviours[0];
         seekbehaviour.NewTarget(OwnerEntity.SeekTarget);
     }
     base.OnStateUpdate(gameTime);
 }