public Asteroid(Texture2D image, Vector2 position, AsteroidSize size)
            : base(image, position)
        {
            this.size = size;

            if (size == AsteroidSize.BIG)
            {
                asteroids[0] = new Asteroid(image, position, AsteroidSize.MEDIUM);
                asteroids[1] = new Asteroid(image, position, AsteroidSize.MEDIUM);
            }
            else if (size == AsteroidSize.MEDIUM)
            {
                asteroids[0] = new Asteroid(image, position, AsteroidSize.SMALL);
                asteroids[1] = new Asteroid(image, position, AsteroidSize.SMALL);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Adds the asteroid.
 /// </summary>
 /// <param name="_object">The _object.</param>
 public void AddAsteroid(Asteroid _object)
 {
     _object.AddObserver(this);
     AddDrawableObject(_object);
 }
Esempio n. 3
0
        /// <summary>
        /// Calculates the new rotations.
        /// </summary>
        /// <param name="asteroid">The asteroid.</param>
        /// <param name="bullet">The bullet.</param>
        /// <returns></returns>
        protected float[] CalculateNewRotations(Asteroid asteroid, Bullet bullet)
        {
            float[] returnedValues = new float[2] { 0, 0 };
            float PI = 3.1415f;

            float bulletRotation = bullet.Rotation % (2 * PI);
            float asteroidRotation = asteroid.Rotation % (2 * PI);

            if ((bulletRotation >= asteroidRotation - PI / 4) && (bulletRotation < asteroidRotation + PI / 4))
            {
                //Bullet comes from behind
                returnedValues[0] = PI / 4;
                returnedValues[1] = -PI / 4;
            }
            else if ((bulletRotation >= asteroidRotation - 5 * PI / 4) && (bulletRotation < asteroidRotation + 3 * PI / 4))
            {
                //Bullet comes from the front
                returnedValues[0] = PI / 2;
                returnedValues[1] = -PI / 2;
            }
            else if ((bulletRotation >= asteroidRotation + PI / 4) && (bulletRotation < asteroidRotation + 3 * PI / 4))
            {
                //Bullet comes from the right
                returnedValues[0] = -PI / 4;
                returnedValues[1] = 0;
            }
            else
            {
                //Bullet comes from the left
                returnedValues[0] = PI / 4;
                returnedValues[1] = 0;
            }
            return returnedValues;
        }