示例#1
0
        public override void Update(float timeElapsed)
        {
            // calculate the combined force from each steering behavior in the vehicle's list
            Vector2D steeringForce = SB.Calculate();

            // acceleration = force / mass
            Vector2D acceleration = steeringForce.divide(Mass);

            // update velocity
            Velocity.Add(acceleration.Multiply(timeElapsed));

            // make sure vehicle does not exceed maximum velocity
            Velocity.truncate(MaxSpeed);

            // update the position
            Pos = Pos.Add(Velocity.Multiply(timeElapsed));

            // update the heading if velocity is greater than 0.
            if (Velocity.LengthSquared() > 0.001)
            {
                Heading = Velocity.Normalize();

                Side = Heading.Perpendicular();
            }
        }
示例#2
0
 public override void OnCollision(Sandbox sb, Particle other)
 {
     if (other.Mass < Mass)//меняем местами, если столкнулись с более тяжелой частицей
     {
         var loc = other.Location;
         other.Location = Location;
         Location       = loc;
     }
     Velocity = Velocity.Mult(-0);
     Velocity = Velocity.Add(new PointF(FastRnd.Next() * 2, FastRnd.Next() * 1f));
 }
示例#3
0
        public void UpdatePosition(Rectangle rectangle)
        {
            Velocity.Add(Acceleration);
            Velocity.Limit(MaxSpeed);
            Location.Add(Velocity);


            //CheckEdges(rectangle.Width, rectangle.Height, rectangle.Left, rectangle.Top);

            UpdateRectangle();
            Acceleration.Multiply(0);
        }
示例#4
0
        /// <summary>
        /// Обновление сил, скоростей и координат
        /// </summary>
        public virtual void Update(Sandbox sb, float dt)
        {
            var PrevLocation = Location;

            //приращение скорости
            Velocity = Velocity.Add(Acceleration, dt * dt);
            //приращение координаты
            Location = Location.Add(Velocity);
            //мы ударились о другую частицу?
            var cell = sb[X, Y];

            if (cell != null && cell != this)
            {
                //остаемся на месте, обрабатываем столкновение
                Location = PrevLocation;
                OnCollision(sb, cell);
            }
        }
示例#5
0
        public void Update(GameTime gameTime)
        {
            // Check if entity is under map kill threshold
            if (Position.Y >= 12.5)
            {
                if (this is IPlayer)
                {
                    IPlayer player = (IPlayer)this;
                    player.CauseDamage();
                }
                else if (this is IEnemy)
                {
                    IEnemy enemy = (IEnemy)this;
                    if (enemy.IsAlive())
                    {
                        enemy.BeStomped();
                    }
                }
            }

            // Calculate the delta time
            float delta = gameTime.ElapsedGameTime.Milliseconds / 1000f;

            // Apply pending forces to acceleration
            foreach (Force force in forces)
            {
                Acceleration.Add(force.Calculate(this, delta));
            }
            forces.Clear();

            // Limit acceleration
            Acceleration.Limit();

            // Increase velocity by acceleration and set to 0
            Velocity.Add(Acceleration.Vector);
            Acceleration.Set(Vector2.Zero);

            // Limit new velocity
            Velocity.Limit();

            // Handle moving entity's position based on velocity
            Movement.MoveEntity(this, Velocity.X * delta, -Velocity.Y * delta);
        }
示例#6
0
        // TODO: gravity
        private void UpdateVelocity(double seconds)
        {
            var engineOldOrientation = MainEngineOrientationAngle;

            UpdateRotation(seconds);
            var engineNewOrientation = MainEngineOrientationAngle;

            if (!IsMainEngineFiring)
            {
                return;
            }

            // way simplified, ..but meh, sufficient
            var engineAvgOrientantion            = (engineOldOrientation + engineNewOrientation) / 2;
            var engineGeneratedVelocityMagnitude = EngineGeneratedAcceleration * seconds;
            var engineGeneratedVelocity          = new Vector(engineGeneratedVelocityMagnitude, engineAvgOrientantion - 180);

            Velocity = Velocity.Add(engineGeneratedVelocity);
        }
示例#7
0
        public override void Update(float timeElapsed)
        {
            Console.WriteLine(ToString());
            Vector2D totalVector = new Vector2D();

            foreach (SteeringBehaviour steeringBehaviour in steeringBehaviours)
            {
                Vector2D steeringBehaviourVector = steeringBehaviour.Calculate();

                totalVector.Add(steeringBehaviourVector);
            }
            // Acceleratie toevoegen op basis van Mass
            if (totalVector.Length() != 0)
            {
                totalVector = totalVector.Normalize();
                Vector2D acceleration = totalVector.Divide(Mass).Multiply(MaxSpeed);

                Velocity.Add(acceleration.Multiply(timeElapsed));
                Velocity.Truncate(MaxSpeed);
                Pos.Add(Velocity);
            }
        }
        public override void Update(float timeElapsed)
        {
            // Calculate the combined force from each steering behaviour.
            Vector2D steeringForce = SB.Calculate();

            // Acceleration = Force / Mass (Newton's laws of physics).
            Vector2D acceleration = steeringForce.Clone().divide(Mass);

            // Update velocity.
            Velocity.Add(acceleration.Clone().Multiply(timeElapsed));

            // Make sure the moving entity does not exceed maximum speed.
            Velocity.Truncate(MaxSpeed);

            // Update position.
            Pos.Add(Velocity.Clone().Multiply(timeElapsed));

            // Update heading if the velocity is bigger than 0
            if (Velocity.LengthSquared() > 0)
            {
                Heading = Velocity.Clone().Normalize();
            }
        }