Beispiel #1
0
        public override void Update(float timeElapsed)
        {
            SteeringForce = SteeringForce.Zero();

            try
            {
                foreach (SteeringBehaviour SB in SteeringBehaviors)
                {
                    SteeringForce += SB.Calculate();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("MovingEntity: " + e.Message);
            }


            if (SteeringForce.isZero())
            {
                Velocity = Velocity.Zero();
            }

            SteeringForce = Vector2D.truncate(SteeringForce, Max_Force);

            SteeringForce = SteeringForce / Mass;
            SteeringForce = SteeringForce.Multiply(timeElapsed);

            //Update velocity and truncate
            Velocity = Vector2D.truncate(Velocity + SteeringForce, arriveSpeed);

            Pos = Pos + Velocity;

            //Update heading
            if (Velocity.LengthSquared() > 0.00000001)
            {
                Heading = Velocity.Normalize();
                Side    = Heading.PerpRightHand();
            }

            //treat the screen as a toroid
            Vector2D.WrapAround(this.Pos, MyWorld.Width, MyWorld.Height);
        }