Пример #1
0
 /// <summary>
 /// Initializes the specified instance of an enemy.
 /// </summary>
 /// <param name="_sprite">The _sprite.</param>
 /// <param name="_position">The _position.</param>
 /// <param name="_bulletSprite">The _bullet sprite.</param>
 public void Initialize(Sprite _sprite, Vector2 _position, Sprite _bulletSprite)
 {
     bullets = new Queue<Bullet>();
     base.Initialize(_sprite, _position);
     AddVelocity(1f);
     for (int i = 0; i < MAX_NB_BULLETS; i++)
     {
         Bullet bullet = new Bullet();
         bullet.Initialize(_bulletSprite, position);
         bullet.AddVelocity(5f);
         bullets.Enqueue(bullet);
     }
 }
Пример #2
0
 /// <summary>
 /// Adds the bonus.
 /// </summary>
 /// <param name="_type">The _type.</param>
 public override void AddBonus(Bonus.Type _type)
 {
     base.AddBonus(_type);
     if (_type == Bonus.Type.STOP_TIME)
     {
         velocity = Vector2.Zero;
     }
     else if (_type == Bonus.Type.ASTEROID_EXPLODE)
     {
         Bullet fakeBullet = new Bullet();
         fakeBullet.Initialize(sprite, position);
         HasCollided(fakeBullet);
     }
 }
Пример #3
0
        /// <summary>
        /// Loads the content and Initialize the Player's instance.
        /// @see Initialize
        /// @see AddScoreObserver
        /// @see StoreBullet
        /// </summary>
        /// <param name="_content">The _content.</param>
        public void LoadContent(ContentManager _content)
        {
            content = _content;
            AsteroidFactory.SetContent(_content);
            EnemyFactory.SetContent(_content);
            input = AsteroidGame.input;

            // Create scene
            LevelLoader levelLoader = new LevelLoader(level);
            scene = levelLoader.GetScene();
            UIContainer uiContainer = new UIContainer();
            uiContainer.LoadContent(content);
            scene.Initialize(uiContainer, content);

            // Player
            Player.GetInstance().Initialize(content, new Sprite(content.Load<Texture2D>("Graphics\\ship"), 0.6f), new Vector2(500, 300));
            for (int i = 0; i < Player.MAX_NB_BULLETS; i++)
            {
                Bullet bullet = new Bullet();
                bullet.Initialize(new Sprite(content.Load<Texture2D>("Graphics\\fork"), 0.4f), Player.GetInstance().Position);
                bullet.AddVelocity(5f);
                bullet.AddScoreObserver(Player.GetInstance());
                Player.GetInstance().StoreBullet(bullet);
            }
            scene.AddDrawableObject(Player.GetInstance());
        }
Пример #4
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;
        }
Пример #5
0
 /// <summary>
 /// Stores the bullet.
 /// </summary>
 /// <param name="_bullet">The _bullet.</param>
 public void StoreBullet(Bullet _bullet)
 {
     bullets.Enqueue(_bullet);
 }