public override void Shoot(GameTime gameTime, Vector2 position)
        {
            if (GameHelper.AllowedToFire(_lastFired, _shootTimer, gameTime))
            {
                _lastFired = gameTime.TotalGameTime.TotalMilliseconds;

                // We fire a laser from each side of the same time
                for(int i = 0;i < 2;i++)
                {
                    for(int j = 0;j < _pelletNum;j++)
                    {
                        Vector2 totalOffset = _offset;
                        Vector2 verticalOffset = new Vector2(0, _scale);

                        Projectile projectile = new Projectile(GameLogic.GetInstance().GetGame(), _pelletDamage);
                        projectile.SetMovingBehaviour(new StraightLine(projectile, _speed));
                        for(int k = 0;k < j;k++)
                        {
                            totalOffset += verticalOffset;
                        }
                        projectile.SetPosition(position + totalOffset);
                        GameLogic.GetInstance().GetGame().Components.Add(projectile);
                        GameLogic.GetInstance().AddPlayerProjectile(projectile);
                    }

                    _offset = new Vector2(-_offset.X, _offset.Y);
                }
            }
            _wpn.Shoot(gameTime, position);
        }
Exemple #2
0
 public 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;
         Game game = GameLogic.GetInstance().GetGame();
         Projectile projectile = new Projectile(game, _pelletDamage);
         projectile.SetMovingBehaviour(new StraightLine(projectile, _speed));
         projectile.SetPosition(position + _offset);
         projectile.SetScale(_bulletScale);
         game.Components.Add(projectile);
         GameLogic.GetInstance().AddPlayerProjectile(projectile);
     }
 }
Exemple #3
0
        public override void Update(GameTime gameTime)
        {
            if (_random.NextDouble() <= _shootChance)
            {
                GameLogic gameLogic = GameLogic.GetInstance();
                Game game = gameLogic.GetGame();

                Projectile projectile = new Projectile(game, 1.0f);
                projectile.SetMovingBehaviour(new StraightLine(projectile, _shootVector));

                // Tweak the vertical position with one scaled pixel,
                // It looks better
                projectile.SetPosition(GetPosition() + _offset - new Vector2(0.0f,gameLogic.GetScale()));

                projectile.SetScale(gameLogic.GetScale() * 2.0f);
                game.Components.Add(projectile);
                gameLogic.AddEnemyProjectile(projectile);
            }
            base.Update(gameTime);
        }
        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);
        }
        /// <summary>
        /// Updates the teddy bear's location, bouncing if necessary. Also has
        /// the teddy bear fire a projectile when it's time to
        /// </summary>
        /// <param name="gameTime">game time</param>
        public void Update(GameTime gameTime)
        {
            // move the teddy bear
            drawRectangle.X += (int)(velocity.X * gameTime.ElapsedGameTime.Milliseconds);
            drawRectangle.Y += (int)(velocity.Y * gameTime.ElapsedGameTime.Milliseconds);

            // bounce as necessary
            BounceTopBottom();
            BounceLeftRight();

            // fire projectile as appropriate
            elapsedShotMilliseconds += gameTime.ElapsedGameTime.Milliseconds;

            if(elapsedShotMilliseconds > firingDelay)
            {
                elapsedShotMilliseconds = 0;
                firingDelay = GetRandomFiringDelay();

                Texture2D projectileSprite = Game1.GetProjectileSprite(projectileType);
                int projectileY = drawRectangle.Center.Y + GameConstants.TeddyBearProjectileOffset;
                Projectile projectile = new Projectile(projectileType, projectileSprite, drawRectangle.Center.X, projectileY, -GetProjectileYVelocity());
                Game1.AddProjectile(projectile);

                // use instance to lower volume as it was horrible
                SoundEffectInstance instance = shootSound.CreateInstance();
                instance.Volume = 0.2f;
                instance.Play();
            }
            // timer concept (for animations) introduced in Chapter 7
        }
        /// <summary>
        /// Updates the burger's location based on mouse. Also fires 
        /// french fries as appropriate
        /// </summary>
        /// <param name="gameTime">game time</param>
        /// <param name="mouse">the current state of the mouse</param>
        public void Update(GameTime gameTime, KeyboardState keyboard)
        {
            // burger should only respond to input if it still has health
            if(health > 0)
            {
                // move burger using keyboard
                if (keyboard.IsKeyDown(Keys.W))
                {
                    drawRectangle.Y -= GameConstants.BurgerMovementAmount;
                }else if (keyboard.IsKeyDown(Keys.S))
                {
                    drawRectangle.Y += GameConstants.BurgerMovementAmount;
                }
                if (keyboard.IsKeyDown(Keys.A))
                {
                    drawRectangle.X -= GameConstants.BurgerMovementAmount;
                } else if (keyboard.IsKeyDown(Keys.D))
                {
                    drawRectangle.X += GameConstants.BurgerMovementAmount;
                }

                // clamp burger in window
                if(drawRectangle.X < 0)
                {
                    drawRectangle.X = 0;
                }else if(drawRectangle.Right > GameConstants.WindowWidth)
                {
                    drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
                }
                if (drawRectangle.Y < 0)
                {
                    drawRectangle.Y = 0;
                }
                else if (drawRectangle.Bottom > GameConstants.WindowHeight)
                {
                    drawRectangle.Y = GameConstants.WindowHeight - drawRectangle.Height;
                }

                // update shooting allowed
                if (!canShoot)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;

                    if(elapsedCooldownMilliseconds >= GameConstants.BurgerTotalCooldownMilliseconds || keyboard.IsKeyUp(Keys.Space))
                    {
                        canShoot = true;
                        elapsedCooldownMilliseconds = 0;
                    }
                }

                // timer concept (for animations) introduced in Chapter 7

                // shoot if appropriate
                if (canShoot && keyboard.IsKeyDown(Keys.Space))
                {
                    canShoot = false;

                    Texture2D projectileSprite = Game1.GetProjectileSprite(projectileType);
                    int projectileY = drawRectangle.Center.Y - GameConstants.FrenchFriesProjectileOffset;
                    Projectile projectile = new Projectile(projectileType, projectileSprite, drawRectangle.Center.X, projectileY, GameConstants.FrenchFriesProjectileSpeed);
                    Game1.AddProjectile(projectile);
                    shootSound.Play();
                }
            }
        }
        /// <summary>
        /// Updates the teddy bear's location, bouncing if necessary. Also has
        /// the teddy bear fire a projectile when it's time to
        /// </summary>
        /// <param name="gameTime">game time</param>
        public void Update(GameTime gameTime)
        {
            // move the teddy bear
            drawRectangle.X += (int)(velocity.X * gameTime.ElapsedGameTime.Milliseconds);
            drawRectangle.Y += (int)(velocity.Y * gameTime.ElapsedGameTime.Milliseconds);

            // bounce as necessary
            BounceTopBottom();
            BounceLeftRight();

            // fire projectile as appropriate
            // timer concept (for animations) introduced in Chapter 7
            elapsedShotTime += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedShotTime > firingDelay)
            {
                elapsedShotTime = 0;
                firingDelay = GetRandomFiringDelay();
                Projectile teddyisShootingBack = new Projectile(ProjectileType.TeddyBear, Game1.GetProjectileSprite(ProjectileType.TeddyBear), drawRectangle.Center.X,
                    drawRectangle.Center.Y + GameConstants.TEDDY_BEAR_PROJECTILE_OFFSET,- GetProjectileYVelocity());
                shootSound.Play();
                Game1.AddProjectile(teddyisShootingBack);
            }
            
            
        }
        /// <summary>
        /// Updates the burger's location based on mouse. Also fires 
        /// french fries as appropriate
        /// </summary>
        /// <param name="gameTime">game time</param>
        /// <param name="mouse">the current state of the mouse</param>
        public void Update(GameTime gameTime, MouseState mouse)
        {
            // burger should only respond to input if it still has health
            if (health > 0)
            {
                // move burger using mouse
                drawRectangle.X = mouse.X - drawRectangle.Width / 2;
                drawRectangle.Y = mouse.Y - drawRectangle.Height / 2;

                // clamp burger in window
                if (drawRectangle.Left < 0)
                    drawRectangle.X = 0;
                else if (drawRectangle.Right > GameConstants.WINDOW_WIDTH)
                    drawRectangle.X = GameConstants.WINDOW_WIDTH - drawRectangle.Width;

                if (drawRectangle.Top < 0)
                    drawRectangle.Y = 0;
                else if (drawRectangle.Bottom > GameConstants.WINDOW_HEIGHT)
                    drawRectangle.Y = GameConstants.WINDOW_HEIGHT - drawRectangle.Height;

                // update shooting allowed
                // timer concept (for animations) introduced in Chapter 7
                if (!canShoot)
                {
                    elapsedCooldownTime += gameTime.ElapsedGameTime.Milliseconds;

                    if (elapsedCooldownTime >= GameConstants.BURGER_COOLDOWN_MILLISECONDS || mouse.LeftButton == ButtonState.Released)
                    {
                        canShoot = true;
                        elapsedCooldownTime = 0;
                    }
                }

                // shoot if appropriate
                if (mouse.LeftButton == ButtonState.Pressed && canShoot)
                {
                    canShoot = false;
                    Projectile projectile = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries), 
                        drawRectangle.Center.X, drawRectangle.Center.Y - GameConstants.FRENCH_FRIES_PROJECTILE_OFFSET, 
                        GameConstants.FRENCH_FRIES_PROJECTILE_SPEED);
                    Game1.AddProjectile(projectile);
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Updates the burger's location based on mouse. Also fires 
        /// french fries as appropriate
        /// </summary>
        /// <param name="gameTime">game time</param>
        /// <param name="mouse">the current state of the mouse</param>
        public void Update(GameTime gameTime, KeyboardState keyboard)
        {
            // burger should only respond to input if it still has health
            if (health > 0)
            {
                // move burger using mouse
                //drawRectangle.X = mouse.X - drawRectangle.Width / 2;
                //drawRectangle.Y = mouse.Y - drawRectangle.Height / 2;

                //move burger using keyboard
                if (keyboard.IsKeyDown(Keys.Right) ||
                keyboard.IsKeyDown(Keys.D))
                {
                    X += GameConstants.BURGER_MOVEMENT_AMOUNT;

                }
                if (keyboard.IsKeyDown(Keys.Left) ||
                    keyboard.IsKeyDown(Keys.A))
                {
                    X -= GameConstants.BURGER_MOVEMENT_AMOUNT;

                }
                if (keyboard.IsKeyDown(Keys.Up) ||
                    keyboard.IsKeyDown(Keys.W))
                {
                    Y -= GameConstants.BURGER_MOVEMENT_AMOUNT;
                }
                if (keyboard.IsKeyDown(Keys.Down) ||
                    keyboard.IsKeyDown(Keys.S))
                {
                    Y += GameConstants.BURGER_MOVEMENT_AMOUNT;
                }

                // clamp burger in window
                // timer concept (for animations) introduced in Chapter 7
                if (drawRectangle.Left < 0)
                {
                    drawRectangle.X = 0;
                }
                else if (drawRectangle.Right > GameConstants.WINDOW_WIDTH)
                {
                    drawRectangle.X = GameConstants.WINDOW_WIDTH - drawRectangle.Width;
                }
                else if (drawRectangle.Top < 0)
                {
                    drawRectangle.Y = 0;
                }
                else if (drawRectangle.Bottom > GameConstants.WINDOW_HEIGHT)
                {
                    drawRectangle.Y = GameConstants.WINDOW_HEIGHT - drawRectangle.Height;
                }
                // update shooting allowed
                // timer concept (for animations) introduced in Chapter 7
                if (canShoot == false)
                {
                    elapsedCooldownTime += gameTime.ElapsedGameTime.Milliseconds;
                    if (elapsedCooldownTime >= GameConstants.BURGER_COOLDOWN_MILLISECONDS || keyboard.IsKeyUp(Keys.Space))
                    {
                        canShoot = true;
                        elapsedCooldownTime = 0;
                    }
                }

                // shoot if appropriate
                if (health>0 && keyboard.IsKeyDown(Keys.Space) && canShoot == true)
                {
                    canShoot = false;

                    Projectile projectile = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries),
                        drawRectangle.Center.X, drawRectangle.Center.Y - GameConstants.FRENCH_FRIES_PROJECTILE_OFFSET,
                        -GameConstants.FRENCH_FRIES_PROJECTILE_SPEED);
                    Game1.AddProjectile(projectile);
                    shootSound.Play();
                }

            }
        }
Exemple #10
0
 /// <summary>
 /// Adds the given projectile to the game
 /// </summary>
 /// <param name="projectile">the projectile to add</param>
 public static void AddProjectile(Projectile projectile)
 {
     projectiles.Add(projectile);
 }
Exemple #11
0
 public void AddPlayerProjectile(Projectile projectile)
 {
     _playerProjectiles.Add(projectile);
 }
Exemple #12
0
 public void AddEnemyProjectile(Projectile projectile)
 {
     _enemyProjectiles.Add(projectile);
 }
        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);
        }
        /// <summary>
        /// Adds the given projectile to the game
        /// </summary>
        /// <param name="projectile">the projectile to add</param>
        public static void AddProjectile(Projectile projectile)
        {

        }
        /// <summary>
        /// Updates the burger's location based on mouse. Also fires 
        /// french fries as appropriate
        /// </summary>
        /// <param name="gameTime">game time</param>
        /// <param name="mouse">the current state of the mouse</param>
        public void Update(GameTime gameTime, KeyboardState keyboard)
        {
            // burger should only respond to input if it still has health
            if (health > 0)
            {
                // move burger using keyboard
                if (keyboard.IsKeyDown(Keys.A))
                    drawRectangle.X -= GameConstants.BURGER_MOVEMENT_AMOUNT;

                if (keyboard.IsKeyDown(Keys.D))
                    drawRectangle.X += GameConstants.BURGER_MOVEMENT_AMOUNT;

                if (keyboard.IsKeyDown(Keys.S))
                    drawRectangle.Y += GameConstants.BURGER_MOVEMENT_AMOUNT;

                if (keyboard.IsKeyDown(Keys.W))
                    drawRectangle.Y -= GameConstants.BURGER_MOVEMENT_AMOUNT;

                // clamp burger in window

                // clamp for x axis
                if (drawRectangle.X < 0)
                    drawRectangle.X = 0;

                if (drawRectangle.X + sprite.Width >= GameConstants.WINDOW_WIDTH)
                    drawRectangle.X = GameConstants.WINDOW_WIDTH - sprite.Width - 1;

                // clamp for y axis
                if (drawRectangle.Y < 0)
                    drawRectangle.Y = 0;

                if (drawRectangle.Y + sprite.Height >= GameConstants.WINDOW_HEIGHT)
                    drawRectangle.Y = GameConstants.WINDOW_HEIGHT - sprite.Height - 1;

                // update shooting allowed
                if (canShoot == false)
                {
                    elapsedCooldownTime += gameTime.ElapsedGameTime.Milliseconds;
                    if (elapsedCooldownTime > GameConstants.BURGER_COOLDOWN_MILLISECONDS || keyboard.IsKeyUp(Keys.Space))
                    {
                        elapsedCooldownTime = 0;
                        canShoot = true;
                    }
                }

                // shoot if appropriate
                // create a new projectile
                if (keyboard.IsKeyDown(Keys.Space) && canShoot)
                {
                    canShoot = false;
                    Projectile projectile = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries),
                        drawRectangle.Center.X, drawRectangle.Center.Y - GameConstants.FRENCH_FRIES_PROJECTILE_OFFSET, -GameConstants.FRENCH_FRIES_PROJECTILE_SPEED);
                    Game1.AddProjectile(projectile);
                    shootSound.Play();
                }
            }
        }