Exemplo n.º 1
0
        public Vector2 Calculate(CVehicle vehicle)
        {
            Vector2 force      = new Vector2();
            float   x_strenght = 0;
            float   y_strenght = 0;

            //Checks if the vehicle has left the screen on the x coordinate
            //Set a target towards the window view
            if (vehicle.Owner.position.X <= -mapOffset)
            {
                force     += new Vector2(1, 0);
                x_strenght = Math.Abs(vehicle.Owner.position.X + mapOffset);
                force.X   *= x_strenght;
            }
            else if (vehicle.Owner.position.X >= Game1.ScreenWidth + mapOffset)
            {
                force     += new Vector2(-1, 0);
                x_strenght = Math.Abs(vehicle.Owner.position.X - Game1.ScreenWidth + mapOffset);
                force.X   *= x_strenght;
            }
            //Checks if the vehicle has left the screen on the y coordinate
            //Set a target towards the window view
            if (vehicle.Owner.position.Y >= Game1.ScreenHeight + mapOffset)
            {
                force     += new Vector2(0, -1);
                y_strenght = Math.Abs(vehicle.Owner.position.Y - Game1.ScreenWidth + mapOffset);
                force.Y   *= y_strenght;
            }
            else if (vehicle.Owner.position.Y <= -mapOffset)
            {
                force     += new Vector2(0, 1);
                y_strenght = Math.Abs(vehicle.Owner.position.Y + mapOffset);
                force.Y   *= y_strenght;
            }
            return(force);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates the vector pointing away from the target and multiplies by the intended force
        /// </summary>
        /// <param name="vehicle">Vehicle that the calculation affects</param>
        /// <returns>Returns the force necessary to evade</returns>
        public Vector2 Calculate(CVehicle vehicle)
        {
            Vector2 force = Vector2.Normalize(vehicle.Owner.position - target.position) * vehicle.maxForce;

            return(force);
        }