Exemple #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public SmellCatch(Character owner)
            : base()
        {
            this.owner = owner;

            // Create the blending behaviors
            BehaviorAndWeight a = new BehaviorAndWeight(new LookWhereYoureGoing(), 1);
            BehaviorAndWeight b = new BehaviorAndWeight(new ObstacleAvoidance(), 0.5f);
            BehaviorAndWeight c = new BehaviorAndWeight(new FriendsAvoidance(owner), 2);

            FollowPath f = new FollowPath();
            f.heuristic = 's';
            BehaviorAndWeight d = new BehaviorAndWeight(f, 1.5f);

            // Add them to the list
            blending.behaviors.Add(a);
            blending.behaviors.Add(b);
            blending.behaviors.Add(c);
            blending.behaviors.Add(d);
        }
Exemple #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="owner">The character who owns this behavior</param>
 public Separation(Character owner)
 {
     this.owner = owner;
 }
        /// <summary>
        /// Calculates a collision in the specified range, between position and moveAmount
        /// </summary>
        /// <param name="position">Initial position of the ray</param>
        /// <param name="moveAmount">Range to check</param>
        /// <returns>A collision if found</returns>
        public static Collision GetCollision(Vector3 position, Vector3 moveAmount, Character owner)
        {
            // Stuff to build the ray
            Vector3 unit = new Vector3(moveAmount.X, moveAmount.Y, moveAmount.Z);
            unit.Normalize();

            Ray ray = new Ray(position, unit);
            Vector3 minNormal = Vector3.Zero;
            float min = float.PositiveInfinity;

            // Find a collision with enemies only
            foreach (Enemy squorre in GameMode.squorres)
            {
                if (squorre == owner)
                    continue;

                float? res = squorre.bound.Intersects(ray);

                if (res.HasValue && res < min)
                {
                    min = (float)res;
                    minNormal = new Vector3(moveAmount.X, moveAmount.Y, moveAmount.Z) * -1;
                    minNormal.Normalize();
                }
            }

            Collision collision = new Collision();

            // Check if there is a collision
            if (!float.IsPositiveInfinity(min))
            {
                // Find the collision spot and compare it to the move amount
                Vector3 spot = ray.Position + ray.Direction * min;
                spot.Z = 0;

                // If the spot is within the move amount range, save it in the collision
                if ((spot - position).Length() <= moveAmount.Length())
                {
                    collision.position = spot;
                    collision.normal = minNormal;
                }
            }

            return collision;
        }
Exemple #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="character">Character owner of this sensor</param>
 public Sensor(Character character)
     : base(character)
 {
 }