public override void Shoot(GameTime gameTime, Vector2 position)
        {
            // Check if we're allowed to fire, do so
            if (GameHelper.AllowedToFire(_lastFired, _shootTimer, gameTime))
            {
                _lastFired = gameTime.TotalGameTime.TotalMilliseconds;

                // If last time we fired from the right,
                // set the offset to the left and vice versa
                Vector2 offset;
                if (_sideFiredLast == SideFired.Left)
                {
                    offset = new Vector2(_offset.X, _offset.Y);
                    _sideFiredLast = SideFired.Right;
                }
                else
                {
                    offset = new Vector2(-_offset.X, _offset.Y);
                    _sideFiredLast = SideFired.Left;
                }

                // Extra Offset for the spacing between elements
                Vector2 extraOffset = new Vector2();

                // Store the previous projectile so we can follow it.
                // This allows the rest of the missile to stay together if the
                // enemy dies.
                Projectile previousProjectile = null;
                for(int i = 0;i < _pelletNum;i++)
                {
                    Vector2 totalOffset = offset;

                    Projectile projectile = new Projectile(GameLogic.GetInstance().GetGame(), _pelletDamage);
                    if(previousProjectile == null)
                    {
                        projectile.SetPosition(position + totalOffset);
                        projectile.SetMovingBehaviour(new Follow(projectile, _enemies, _speed));
                        Vector2 t = projectile.GetMovingBehaviour().GetSpeed();
                        t.Normalize();
                        extraOffset = new Vector2(0.0f, -_scale * _missileScale * 1.01f);
                    }
                    else
                    {
                        for (int j = 0; j < i; j++)
                        {
                            totalOffset += extraOffset;
                        }
                        projectile.SetPosition(position + totalOffset);
                        projectile.SetMovingBehaviour(new Follow(projectile, previousProjectile, _enemies, _speed));
                    }
                    previousProjectile = projectile;

                    projectile.SetScale(_scale * _missileScale);
                    GameLogic.GetInstance().GetGame().Components.Add(projectile);
                    GameLogic.GetInstance().AddPlayerProjectile(projectile);
                }
            }
            _wpn.Shoot(gameTime, position);
        }
Exemplo n.º 2
0
        public override void Shoot(GameTime gameTime, Vector2 position)
        {
            // Check if we're allowed to fire, do so
            if (GameHelper.AllowedToFire(_lastFired, _shootTimer, gameTime))
            {
                _lastFired = gameTime.TotalGameTime.TotalMilliseconds;

                // If last time we fired from the right,
                // set the offset to the left and vice versa
                Vector2 offset;
                if (_sideFiredLast == SideFired.Left)
                {
                    offset = new Vector2(_offset.X, _offset.Y);
                    _sideFiredLast = SideFired.Right;
                }
                else
                {
                    offset = new Vector2(-_offset.X, _offset.Y);
                    _sideFiredLast = SideFired.Left;
                }

                for(int i = 0;i < _pelletNum;i++)
                {
                    Vector2 totalOffset = offset;
                    Vector2 verticalOffset = new Vector2(0, _scale * _rocketScale);

                    Projectile projectile = new Projectile(GameLogic.GetInstance().GetGame(), _pelletDamage);
                    projectile.SetMovingBehaviour(new StraightLine(projectile, _speed));
                    for(int k = 0;k < i;k++)
                    {
                        totalOffset += verticalOffset;
                    }
                    projectile.SetPosition(position + totalOffset);
                    projectile.SetScale(_scale * _rocketScale);
                    GameLogic.GetInstance().GetGame().Components.Add(projectile);
                    GameLogic.GetInstance().AddPlayerProjectile(projectile);
                }
            }
            _wpn.Shoot(gameTime, position);
        }