Beispiel #1
0
        /// <summary>
        /// Calculates the thrust and gravity forces, adding to the velocity of the ship.
        /// </summary>
        /// <param name="stars"></param>
        /// <param name="time"></param>
        public void GetPhysics(IEnumerable <Star> stars, uint time)
        {
            Vector2D forces = new Vector2D(accelerationVector);

            accelerationVector = new Vector2D(0, 0);

            foreach (Star star in stars)
            {
                Vector2D g = star.GetLocation() - loc;
                if (World.Collides(star.GetLocation(), loc, star.GetHitBoxSize()))
                {
                    if (Alive)
                    {
                        Die(time);
                        return;
                    }
                }
                g.Normalize();
                g       = g * star.GetMass();
                forces += g;
            }

            velocity += forces;
            loc      += velocity;
        }
Beispiel #2
0
 /// <summary>
 /// Updates the projectile, making sure that it moves and also checks colisions with stars.
 /// </summary>
 /// <param name="Stars"></param>
 public void Update(IEnumerable <Star> Stars)
 {
     loc += dir * 15;
     foreach (Star star in Stars)
     {
         if (World.Collides(star.GetLocation(), loc, star.GetHitBoxSize()))
         {
             alive = false;
         }
     }
 }