Beispiel #1
0
        public override void Iterate(Microsoft.Xna.Framework.GameTime gameTime)
        {
            if (!initialized)
            {
                subbehaviours = new AISubbehaviours(nodesToVisit.Count);
                if (character != null)
                {
                    // 1 add goto behaviour from character position to first node
                    AIBehaviour newBehaviour = new AIBehaviourGoTo();
                    newBehaviour.Character = this.character;
                    newBehaviour.Map       = this.map;

                    // loop
                    for (int index = 0; index < nodesToVisit.Count - 1; index++)
                    {
                        AIBehaviour newIBehaviour = new AIBehaviourGoTo();
                        newIBehaviour.Character = this.character;
                        newIBehaviour.Map       = this.map;
                        ((AIBehaviourGoTo)(newIBehaviour)).StartNode = nodesToVisit[index];
                        ((AIBehaviourGoTo)(newIBehaviour)).EndNode   = nodesToVisit[index + 1];
                        subbehaviours.Add(ref newIBehaviour);
                    }

                    newBehaviour           = new AIBehaviourGoTo();
                    newBehaviour.Character = this.character;
                    newBehaviour.Map       = this.map;
                    ((AIBehaviourGoTo)(newBehaviour)).StartNode = nodesToVisit[nodesToVisit.Count - 1];
                    ((AIBehaviourGoTo)(newBehaviour)).EndNode   = nodesToVisit[0];
                    subbehaviours.Add(ref newBehaviour);

                    // add goto behaviour from last position to first position
                }
                initialized = true;
            }
            base.Iterate(gameTime);
        }
 public AIBehaviourGoTo()
 {
     subbehaviours = new AISubbehaviours(2);
     subbehaviours.Add(ref findPath);
     subbehaviours.Add(ref followPath);
 }