/// <summary>
 /// Initializes a new instance of the <see cref="UpdateAsteroidStateMessage"/> class.
 /// </summary>
 /// <param name="asteroid">
 /// The asteroid.
 /// </param>
 public UpdateAsteroidStateMessage(Asteroid asteroid)
 {
     this.Id = asteroid.Id;
     this.Position = asteroid.SimulationState.Position;
     this.Velocity = asteroid.SimulationState.Velocity;
     this.Rotation = asteroid.SimulationState.Rotation;
     this.MessageTime = NetTime.Now;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsteroidStateChangedArgs"/> class.
 /// </summary>
 /// <param name="asteroid">
 /// The asteroid.
 /// </param>
 public AsteroidStateChangedArgs(Asteroid asteroid)
 {
     this.Asteroid = asteroid;
 }
 /// <summary>
 /// The is on screen.
 /// </summary>
 /// <param name="asteroid">
 /// The asteroid.
 /// </param>
 /// <returns>
 /// The is on screen.
 /// </returns>
 private bool IsOnScreen(Asteroid asteroid)
 {
     return
         asteroid.Bounds.Intersects(
             new Rectangle(
                 -this.screenPadding.Left, 
                 -this.screenPadding.Top, 
                 this.resolutionManager.DisplayViewport.Width + this.screenPadding.Right, 
                 this.resolutionManager.DisplayViewport.Height + this.screenPadding.Bottom));
 }
        /// <summary>
        /// The bounce asteroids.
        /// </summary>
        /// <param name="asteroid1">
        /// The asteroid 1.
        /// </param>
        /// <param name="asteroid2">
        /// The asteroid 2.
        /// </param>
        private void BounceAsteroids(Asteroid asteroid1, Asteroid asteroid2)
        {
            Vector2 cOfMass = (asteroid1.SimulationState.Velocity + asteroid2.SimulationState.Velocity) / 2;

            Vector2 normal1 = asteroid2.Center - asteroid1.Center;
            normal1.Normalize();

            Vector2 normal2 = asteroid1.Center - asteroid2.Center;
            normal2.Normalize();

            Vector2 newVelocity = asteroid1.SimulationState.Velocity - cOfMass;
            newVelocity = Vector2.Reflect(newVelocity, normal1);
            asteroid1.SimulationState.Velocity = newVelocity + cOfMass;

            newVelocity = asteroid2.SimulationState.Velocity - cOfMass;
            newVelocity = Vector2.Reflect(newVelocity, normal2);
            asteroid2.SimulationState.Velocity = newVelocity + cOfMass;

            this.OnAsteroidStateChanged(asteroid1);
            this.OnAsteroidStateChanged(asteroid2);
        }
 /// <summary>
 /// The on asteroid state changed.
 /// </summary>
 /// <param name="asteroid">
 /// The asteroid.
 /// </param>
 protected virtual void OnAsteroidStateChanged(Asteroid asteroid)
 {
     EventHandler<AsteroidStateChangedArgs> asteroidEntityStateChanged = this.AsteroidStateChanged;
     if (asteroidEntityStateChanged != null)
     {
         asteroidEntityStateChanged(this, new AsteroidStateChangedArgs(asteroid));
     }
 }
        /// <summary>
        /// The add asteroid.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="position">
        /// The position.
        /// </param>
        /// <param name="velocity">
        /// The velocity.
        /// </param>
        /// <param name="rotation">
        /// The rotation.
        /// </param>
        /// <returns>
        /// </returns>
        public Asteroid AddAsteroid(long id, Vector2 position, Vector2 velocity, float rotation)
        {
            if (this.asteroids.ContainsKey(id))
            {
                return this.asteroids[id];
            }

            var asteroid = new Asteroid(
                id, 
                this.spriteSheet, 
                this.initialAsteroidFrame, 
                this.noOfAsteroidFrames, 
                this.asteroidCollisionRadius, 
                new EntityState { Position = position, Rotation = rotation, Velocity = velocity });

            this.asteroids.Add(asteroid.Id, asteroid);

            return asteroid;
        }