Server.Planets.applyGravity C# (CSharp) Méthode

applyGravity() public méthode

This function changes the speed of the object based on its proximity to its Planet instance
public applyGravity ( Bullet b ) : void
b Bullet An instance to a Bullet
Résultat void
        public void applyGravity(Bullet b)
        {
            //Gravity Calculations between bullets and the planet(object that is producing gravity)
            float G = MatchConfig.gravityConstant;

            double distanceG = Math.Sqrt((Math.Pow(b.x - this.x, 2) + Math.Pow(b.y - this.y, 2)));
            double speedVector = (float)((G * this.mass) / Math.Pow(distanceG, 2));
            double deltaY = (b.y - this.y);
            double deltaX = (b.x - this.x);
            double angleDegree = Math.Atan(deltaY / deltaX);// * 180 / Math.PI;
            //float rad = (float)(Math.PI / 180) * o.angle;
            if (b.x != this.x)
            {
                //speedX += (float)(Math.Cos(angleDegree) * speedVector);
                if (b.x > this.x)
                    b.speedX -= (float)Math.Abs((Math.Cos(angleDegree) * speedVector));
                else
                    b.speedX+= (float)Math.Abs((Math.Cos(angleDegree) * speedVector));
            }
            if (b.y != this.y)
            {
                //speedY += (float)(Math.Sin(angleDegree) * speedVector);
                if (b.y < this.y)
                    b.speedY+= (float)Math.Abs((Math.Sin(angleDegree) * speedVector));
                else
                    b.speedY-= (float)Math.Abs((Math.Sin(angleDegree) * speedVector));
            }
        }

Same methods

Planets::applyGravity ( Player p ) : void