Ejemplo n.º 1
0
        private void TreasureSeekUpdate(GameTime gameTime)
        {
            Treasure t = stage.GetClosestTreasure(agentObject.Translation);

            if (t == null)
            {
                // No more treasure. Stop Moving
                state = NPAgentState.DONE;
                return;
            }

            if (treasureNav == null || treasureNav.Translation != t.Obj.Translation)
            {
                treasureNav = new NavNode(t.Obj.Translation, NavNode.NavNodeEnum.WAYPOINT);
                agentObject.turnToFace(treasureNav.Translation);
            }

            ObjectAvoidance();

            float distance = Vector3.Distance(
                new Vector3(treasureNav.Translation.X, 0, treasureNav.Translation.Z),
                new Vector3(agentObject.Translation.X, 0, agentObject.Translation.Z));

            stage.setInfo(15, stage.agentLocation(this));
            stage.setInfo(16,
                          string.Format("          nextGoal ({0:f0}, {1:f0}, {2:f0})  distance to next goal = {3,5:f2})",
                                        treasureNav.Translation.X / stage.Spacing, treasureNav.Translation.Y, treasureNav.Translation.Z / stage.Spacing, distance));
            // Add in the bounding sphere radius to make distance 200 from edge of bounding box instead of 200 from center of object
            if (distance <= (tagDistance + t.BoundingSphereRadius))
            {
                //Tag the treasure so it can't be found again.
                stage.TagTreasure(t, this);
                this.treasuresFound++;
                //Found treasure, stop seeking and switch states.
                treasureNav = null;

                Treasure anyMore = stage.GetClosestTreasure(agentObject.Translation);
                if (anyMore != null)
                {
                    state = NPAgentState.PATH_SEEK;
                    // snap to nextGoal and orient toward the new nextGoal
                    agentObject.turnToFace(nextGoal.Translation);
                }
                else
                {
                    state = NPAgentState.DONE;
                }
            }
        }
Ejemplo n.º 2
0
                                    { 445, 460 } };                           // loop return

        /// <summary>
        /// Create a NPC.
        /// AGXNASK distribution has npAgent move following a Path.
        /// </summary>
        /// <param name="theStage"> the world</param>
        /// <param name="label"> name of </param>
        /// <param name="pos"> initial position </param>
        /// <param name="orientAxis"> initial rotation axis</param>
        /// <param name="radians"> initial rotation</param>
        /// <param name="meshFile"> Direct X *.x Model in Contents directory </param>
        public NPAgent(Stage theStage, string label, Vector3 pos, Vector3 orientAxis,
                       float radians, string meshFile)
            : base(theStage, label, pos, orientAxis, radians, meshFile)
        {                                      // change names for on-screen display of current camera
            IsCollidable = true;               // players test collision with Collidable set.
            stage.Collidable.Add(agentObject); // player's agentObject can be collided with by others.

            InitSensors();

            state       = NPAgentState.PATH_SEEK;
            first.Name  = "npFirst";
            follow.Name = "npFollow";
            above.Name  = "npAbove";

            // Flip a coin. If 0, Go Normal Path. If 1, reverse order of list (Go backwards)
            Random r        = new Random();
            int    coinFlip = r.Next(2);

            if (coinFlip == 0)
            {
                stage.setInfo(17, "Direction: Regular");
                path = new Path(stage, pathNode, Path.PathType.LOOP); // continuous search path
            }
            else
            {
                stage.setInfo(17, "Direction: Backwards");
                path = new Path(stage, pathNode, Path.PathType.BACKWARDS); // continuous search path backwards *ADDITION
            }

            // path is built to work on specific terrain, make from int[x,z] array pathNode
            stage.Components.Add(path);
            nextGoal = path.NextNode;                     // get first path goal
            agentObject.turnToFace(nextGoal.Translation); // orient towards the first path goal
                                                          // set snapDistance to be a little larger than step * stepSize
            snapDistance = (int)(1.5 * (agentObject.Step * agentObject.StepSize));
        }
Ejemplo n.º 3
0
 public void FindTreasure()
 {
     state = NPAgentState.TREASURE_SEEK;
 }