示例#1
0
        private void ApplyGravityToSingleObject(GameObjectAbstract gameObject)
        {
            Vector2 gameObjectPosition = gameObject.sprite.Position;
            Vector2 distanceVector = sprite.Position - gameObjectPosition;
            Vector2 unitVector =  Vector2.Normalize(distanceVector);

            float forceMagnitude = cachedForceNumerator / Vector2.LengthSquared(distanceVector + minDistanceEPS);

            float accelerationOnObject = forceMagnitude / mass;

            Vector2 accelerationVector = accelerationOnObject * unitVector;

            gameObject.acceleration += accelerationVector;
        }
示例#2
0
        public void ApplyGravityToObjectArray(GameObjectAbstract[] objectArray)
        {
            cachedMass = objectArray[0].mass;
            cachedForceNumerator = gMValue * cachedMass;

            foreach(GameObjectAbstract gameObject in objectArray)
            {

                if(gameObject.isAlive == true)
                {

                    ApplyGravityToSingleObject(gameObject);
                }
            }
        }