Пример #1
0
 private Vector2 ApplyAcceleration( GameTime gameTime )
 {
     return Velocity = Utility.Limit( Velocity + Acceleration * gameTime.GetGameTick(), MaxVelocity );
 }
Пример #2
0
        private void CalculateVelocity( GameTime gameTime )
        {
            var tick = gameTime.GetGameTick();

            // apply gravity
            var gravityVector = new Vector2( 0, FragEngineGame.Gravity * tick * GravityFactor );

            Velocity += gravityVector;

            // are we speeding up, or slowing down?
            if( Acceleration != Vector2.Zero )
                Velocity = ApplyAcceleration( gameTime );
            else if( Friction != Vector2.Zero )
                Velocity = ApplyFriction( gameTime );
        }
Пример #3
0
        private Vector2 ApplyFriction( GameTime gameTime )
        {
            var frictionDelta = Friction * gameTime.GetGameTick();

            var newVelocity = Velocity;

            if( Velocity.X - frictionDelta.X > 0 ) newVelocity.X -= frictionDelta.X;
            else if( Velocity.X + frictionDelta.X < 0 ) newVelocity.X += frictionDelta.X;
            else newVelocity.X = 0;

            if( Velocity.Y - frictionDelta.Y > 0 ) newVelocity.Y -= frictionDelta.Y;
            else if( Velocity.Y + frictionDelta.Y < 0 ) newVelocity.Y += frictionDelta.Y;
            else newVelocity.Y = 0;

            return Utility.Limit( newVelocity, MaxVelocity );
        }
Пример #4
0
        public virtual void Update( GameTime gameTime )
        {
            CalculateVelocity( gameTime );

            var partialVelocity = Velocity * gameTime.GetGameTick();

            // ask the collision system if we're going to have a collision at that co-ord
            var result = CollisionService.Check( Position, partialVelocity, BoundingBox );

            UpdateEntityState( result );
        }