Пример #1
0
        /// <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
            elapsedShotMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedShotMilliseconds > firingDelay)
            {
                elapsedShotMilliseconds = 0;
                firingDelay             = GetRandomFiringDelay();
                Projectile projectile = new Projectile(ProjectileType.TeddyBear,
                                                       Game1.GetProjectileSprite(ProjectileType.TeddyBear),
                                                       drawRectangle.Center.X,
                                                       drawRectangle.Center.Y + GameConstants.TeddyBearProjectileOffset,
                                                       GetProjectileYVelocity());
                Game1.AddProjectile(projectile);
                shootSound.Play();
            }
        }
Пример #2
0
        /// <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
            elapsedShotMilliseconds += gameTime.ElapsedGameTime.Milliseconds;

            if (elapsedShotMilliseconds > firingDelay)
            {
                // shoot
                Texture2D  projectileSprite = Game1.GetProjectileSprite(ProjectileType.TeddyBear);
                int        xLocation        = drawRectangle.Center.X;
                int        yLocation        = drawRectangle.Bottom + GameConstants.TeddyBearProjectileOffset;
                Projectile teddyProjectile  = new Projectile(ProjectileType.TeddyBear, projectileSprite,
                                                             xLocation, yLocation, GetProjectileYVelocity());
                Game1.AddProjectile(teddyProjectile);

                shootSound.Play();

                // reset firing
                elapsedShotMilliseconds = 0;
                firingDelay             = GetRandomFiringDelay();
            }
        }
        /// <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
            this.drawRectangle.X += (int)(this.velocity.X * gameTime.ElapsedGameTime.Milliseconds);
            this.drawRectangle.Y += (int)(this.velocity.Y * gameTime.ElapsedGameTime.Milliseconds);

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

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

            if (this.elapsedShotTime > this.firingDelay)
            {
                this.elapsedShotTime = 0;
                this.firingDelay     = GetRandomFiringDelay();
                //create a projectile and add it to Game1
                Projectile projectile = new Projectile(ProjectileType.TeddyBear,
                                                       Game1.GetProjectileSprite(ProjectileType.TeddyBear),
                                                       this.drawRectangle.Center.X,
                                                       this.drawRectangle.Center.Y + GameConstants.TEDDY_BEAR_PROJECTILE_OFFSET,
                                                       GetProjectileYVelocity());
                Game1.AddProjectile(projectile);

                //play shoot sound
                this.shootSound.Play(0.3f, 0.0f, 0.0f);
            }

            // timer concept (for animations) introduced in Chapter 7
        }
Пример #4
0
        /// <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
            elapsedShotMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedShotMilliseconds > firingDelay)
            {
                elapsedShotMilliseconds = 0;
                firingDelay             = GetRandomFiringDelay();

                Projectile teddybear = new Projectile(ProjectileType.TeddyBear,
                                                      Game1.GetProjectileSprite(ProjectileType.TeddyBear),
                                                      drawRectangle.Center.X,
                                                      drawRectangle.Center.Y + GameConstants.TeddyBearProjectileOffset,
                                                      GameConstants.TeddyBearProjectileSpeed);

                Game1.AddProjectile(teddybear);
            }
        }
Пример #5
0
        /// <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;

            // firing teddy projectile
            if (elapsedShotMilliseconds > firingDelay)
            {
                elapsedShotMilliseconds = 0;
                firingDelay             = GetRandomFiringDelay();

                // creating projectile
                ProjectileType teddyProjectile = ProjectileType.TeddyBear;
                int            x          = drawRectangle.Center.X;
                int            y          = drawRectangle.Center.Y + GameConstants.TeddyBearProjectileOffset;
                Projectile     projectile = new Projectile(teddyProjectile, Game1.GetProjectileSprite(teddyProjectile), x, y, -GetProjectileYVelocity());
                Game1.AddProjectile(projectile);

                // adding sound efect
                shootSound.Play();
            }
            // timer concept (for animations) introduced in Chapter 7
        }
Пример #6
0
        /// <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
        }
Пример #7
0
        /// <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();
                Projectile projectile = new Projectile(ProjectileType.TeddyBear, Game1.GetProjectileSprite(ProjectileType.TeddyBear),
                                                       drawRectangle.X + drawRectangle.Width / 2, drawRectangle.Y + drawRectangle.Height / 2 + GameConstants.TeddyBearProjectileOffset,
                                                       -GetProjectileYVelocity());
                Game1.AddProjectile(projectile);
                shootSound.Play(0.3f, 0f, 0f);
            }
            // timer concept (for animations) introduced in Chapter 7
        }
        /// <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 projectile = new Projectile(ProjectileType.TeddyBear, Game1.GetProjectileSprite(ProjectileType.TeddyBear),
                                                       drawRectangle.Center.X, drawRectangle.Center.Y + GameConstants.TEDDY_BEAR_PROJECTILE_OFFSET,
                                                       GetProjectileYVelocity());
                Game1.AddProjectile(projectile);
                shootSound.Play();
            }
        }
        /// <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 (this.health <= 0)
            {
                return;
            }

            // 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;
            }
            if (drawRectangle.Right > GameConstants.WindowWidth)
            {
                drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
            }
            if (drawRectangle.Top < 0)
            {
                drawRectangle.Y = 0;
            }
            if (drawRectangle.Bottom > GameConstants.WindowHeight)
            {
                drawRectangle.Y = GameConstants.WindowWidth - drawRectangle.Height;
            }

            // update shooting allowed
            // timer concept (for animations) introduced in Chapter 7

            // shoot if appropriate
            if ((mouse.LeftButton == ButtonState.Pressed) && (canShoot))
            {
                Projectile projectile = new Projectile(ProjectileType.FrenchFries,
                                                       Game1.GetProjectileSprite(ProjectileType.FrenchFries), drawRectangle.Center.X,
                                                       drawRectangle.Center.Y - GameConstants.FrenchFriesProjectileOffset,
                                                       -GameConstants.FrenchFriesProjectileSpeed);

                Game1.AddProjectile(projectile);

                canShoot = false;
            }

            if (!canShoot)
            {
                elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;

                if (elapsedCooldownMilliseconds > GameConstants.BurgerTotalCooldownMilliseconds ||
                    mouse.LeftButton == ButtonState.Released)
                {
                    elapsedCooldownMilliseconds = 0;
                    canShoot = true;
                }
            }
        }
        /// <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.Position.X;
                drawRectangle.Y = mouse.Position.Y;

                // clamp burger in window
                if (drawRectangle.X < 0)
                {
                    drawRectangle.X = 0;
                }
                else if (drawRectangle.X + drawRectangle.Width > GameConstants.WindowWidth)
                {
                    drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
                }

                if (drawRectangle.Y < 0)
                {
                    drawRectangle.Y = 0;
                }
                else if ((drawRectangle.Y + drawRectangle.Height) > GameConstants.WindowHeight)
                {
                    drawRectangle.Y = GameConstants.WindowHeight - drawRectangle.Height;
                }

                // update shooting allowed
                // timer concept (for animations) introduced in Chapter 7
                elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                if (elapsedCooldownMilliseconds > GameConstants.BurgerTotalCooldownMilliseconds)
                {
                    canShoot = true;
                    elapsedCooldownMilliseconds = 0;
                }

                // shoot if appropriate
                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    if (canShoot)
                    {
                        canShoot = false;

                        Projectile frenchFries = new Projectile(ProjectileType.FrenchFries,
                                                                Game1.GetProjectileSprite(ProjectileType.FrenchFries),
                                                                drawRectangle.Center.X,
                                                                drawRectangle.Center.Y - GameConstants.FrenchFriesProjectileOffset,
                                                                -1 * GameConstants.FrenchFriesProjectileSpeed);

                        Game1.AddProjectile(frenchFries);
                    }
                }
            }
        }
Пример #11
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, 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 (health > 0 &&
                    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);
                }
            }
        }
Пример #12
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, 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.Y = mouse.Y;

                // clamp burger in window
                if (drawRectangle.Left < 0)
                {
                    drawRectangle.X = 0;
                }
                if (drawRectangle.Right > GameConstants.WindowWidth)
                {
                    drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
                }
                if (drawRectangle.Top > GameConstants.WindowHeight)
                {
                    drawRectangle.Y = GameConstants.WindowHeight - drawRectangle.Height;
                }
                if (drawRectangle.Bottom < 0)
                {
                    drawRectangle.Y = 0;
                }
                // update shooting allowed
                // timer concept (for animations) introduced in Chapter 7
                if (mouse.LeftButton == ButtonState.Pressed && canShoot)
                {
                    canShoot = false;
                    Texture2D  projectileTexture = Game1.GetProjectileSprite(ProjectileType.FrenchFries);
                    float      yVelocity         = GameConstants.FrenchFriesProjectileSpeed;
                    Projectile frenchProjectile  = new Projectile(ProjectileType.FrenchFries, projectileTexture,
                                                                  (mouse.X + (sprite.Width) / 2), mouse.Y, yVelocity);
                    Game1.AddProjectile(frenchProjectile);
                }
                // shoot if appropriate
                if (!canShoot)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;

                    if (elapsedCooldownMilliseconds >= GameConstants.BurgerTotalCooldownMilliseconds && mouse.LeftButton == ButtonState.Pressed)
                    {
                        elapsedCooldownMilliseconds = 0;
                        canShoot = true;
                    }
                }
            }
        }
Пример #13
0
        /// <summary>
        /// Updates the burger's location based on keyboard WSAD. 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 key)
        {
            // burger should only respond to input if it still has health
            if (health > 0)
            {
                // move burger using mouse
                int x, y;

                // clamp burger in window
                x  = key.IsKeyDown(Keys.A) ? -GameConstants.BurgerMovementAmount : 0;
                x  = key.IsKeyDown(Keys.D) ? +GameConstants.BurgerMovementAmount : x;
                y  = key.IsKeyDown(Keys.W) ? -GameConstants.BurgerMovementAmount : 0;
                y  = key.IsKeyDown(Keys.S) ? +GameConstants.BurgerMovementAmount : y;
                x += drawRectangle.X;
                y += drawRectangle.Y;
                x  = Math.Max(x, 0);
                y  = Math.Max(y, 0);
                x  = Math.Min(x, GameConstants.WindowWidth - drawRectangle.Width);
                y  = Math.Min(y, GameConstants.WindowHeight - drawRectangle.Height);
                drawRectangle.X = x;
                drawRectangle.Y = y;

                // update shooting allowed
                // timer concept (for animations) introduced in Chapter 7
                if (key.IsKeyDown(Keys.Space) && canShoot)
                {
                    Projectile prj = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries),
                                                    drawRectangle.Center.X, drawRectangle.Center.Y + GameConstants.FrenchFriesProjectileOffset,
                                                    -GameConstants.FrenchFriesProjectileSpeed);
                    Game1.AddProjectile(prj);
                    canShoot = false;
                    shootSound.Play();
                }
                // shoot if appropriate
                if (!canShoot)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                    if (elapsedCooldownMilliseconds > GameConstants.BurgerTotalCooldownMilliseconds || key.IsKeyUp(Keys.Space))
                    {
                        elapsedCooldownMilliseconds = 0;
                        canShoot = true;
                    }
                }
            }
        }
Пример #14
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, MouseState mouse)
        {
            // burger should only respond to input if it still has health

            // move burger using mouse
            if (health > 0)
            {
                if ((mouse.X > 0) && (mouse.X < GameConstants.WINDOW_WIDTH - 10))
                {
                    drawRectangle.X = mouse.X;
                }
                if ((mouse.Y > 0) && (mouse.Y < GameConstants.WINDOW_HEIGHT - 10))
                {
                    drawRectangle.Y = mouse.Y;
                }
            }

            if (health > 0 && canShoot == true && mouse.LeftButton == ButtonState.Pressed)
            {
                Projectile projectile = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries), drawRectangle.X, drawRectangle.Y - GameConstants.FRENCH_FRIES_PROJECTILE_OFFSET, GameConstants.TEDDY_BEAR_PROJECTILE_SPEED);
                canShoot = false;
                Game1.AddProjectile(projectile);
            }
            if (canShoot == false)
            {
                elapsedCooldownTime += gameTime.ElapsedGameTime.Milliseconds;
                if (elapsedCooldownTime >= GameConstants.BURGER_COOLDOWN_MILLISECONDS)
                {
                    canShoot            = true;
                    elapsedCooldownTime = 0;
                }
                else if (mouse.LeftButton == ButtonState.Released)
                {
                    canShoot = true;
                }
            }

            // clamp burger in window

            // update shooting allowed
            // timer concept (for animations) introduced in Chapter 7

            // shoot if appropriate
        }
Пример #15
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_mouse(GameTime gameTime, MouseState mouse)
        {
            // burger should only respond to input if it still has health
            if (health > 0)
            {
                // move burger using mouse
                int x = mouse.X, y = mouse.Y;

                // clamp burger in window
                x = Math.Max(x, 0);
                y = Math.Max(y, 0);
                x = Math.Min(x, GameConstants.WindowWidth - drawRectangle.Width);
                y = Math.Min(y, GameConstants.WindowHeight - drawRectangle.Height);
                drawRectangle.X = x;
                drawRectangle.Y = y;

                // update shooting allowed
                // timer concept (for animations) introduced in Chapter 7
                if (mouse.LeftButton == ButtonState.Pressed && canShoot)
                {
                    Projectile prj = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries),
                                                    drawRectangle.Center.X, drawRectangle.Center.Y + GameConstants.FrenchFriesProjectileOffset,
                                                    -GameConstants.FrenchFriesProjectileSpeed);
                    Game1.AddProjectile(prj);
                    canShoot = false;
                }
                // shoot if appropriate
                if (!canShoot)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                    if (elapsedCooldownMilliseconds > GameConstants.BurgerTotalCooldownMilliseconds || mouse.LeftButton == ButtonState.Released)
                    {
                        elapsedCooldownMilliseconds = 0;
                        canShoot = true;
                    }
                }
            }
        }
Пример #16
0
        /// <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
            elapsedShotMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedShotMilliseconds >= firingDelay)
            {
                //reset elapsed shot time and give new value to firing delay
                elapsedShotMilliseconds = 0;
                firingDelay             = GetRandomFiringDelay();

                //create x and y for projectiles
                int projectileX = drawRectangle.X + drawRectangle.Width / 2;
                int projectileY = drawRectangle.Y + drawRectangle.Height / 2 + GameConstants.TeddyBearProjectileOffset;

                //create new projectile and add it
                Projectile newProjectile = new Projectile(ProjectileType.TeddyBear, Game1.GetProjectileSprite(ProjectileType.TeddyBear),
                                                          projectileX, projectileY, GetProjectileYVelocity());

                //add projectile
                Game1.AddProjectile(newProjectile);

                //play shooting sound if not null
                if (shootSound != null)
                {
                    shootSound.Play();
                }
            }
        }
Пример #17
0
        /// <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
            this.drawRectangle.X += (int)(gameTime.ElapsedGameTime.Milliseconds * this.velocity.X);
            this.drawRectangle.Y += (int)(gameTime.ElapsedGameTime.Milliseconds * this.velocity.Y);
            // bounce as necessary
            BounceTopBottom();
            BounceLeftRight();

            // fire projectile as appropriate
            elapsedShotTime += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedShotTime > firingDelay)
            {
                elapsedShotTime = 0;
                firingDelay     = GetRandomFiringDelay();
                Game1.AddProjectile(new Projectile(ProjectileType.TeddyBear,
                                                   Game1.GetProjectileSprite(ProjectileType.TeddyBear),
                                                   this.drawRectangle.X + this.drawRectangle.Width / 2,
                                                   this.drawRectangle.Y + this.drawRectangle.Height / 2 + GameConstants.TEDDY_BEAR_PROJECTILE_OFFSET,
                                                   -GameConstants.TEDDY_BEAR_PROJECTILE_SPEED));
                this.shootSound.Play();
            }
            // timer concept (for animations) introduced in Chapter 7
        }
Пример #18
0
        /// <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
            elapsedShotMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
            if (elapsedShotMilliseconds >= firingDelay)
            {
                elapsedShotMilliseconds = 0;
                firingDelay             = GetRandomFiringDelay();

                Projectile teddyProjectile = new Projectile(ProjectileType.TeddyBear, Game1.GetProjectileSprite(ProjectileType.TeddyBear),
                                                            (drawRectangle.X + sprite.Width / 2), (drawRectangle.Y + sprite.Height), -GetProjectileYVelocity());

                Game1.AddProjectile(teddyProjectile);
            }
        }
Пример #19
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)
            {
                //drawRectangle.X = mouse.X-sprite.Width/2;
                //drawRectangle.Y = mouse.Y-sprite.Height/2;

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


                // move burger using keyboard
                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;
                }
                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;
                }
                //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 (keyboard.IsKeyDown(Keys.Space) && canShoot)
                {
                    canShoot = false;
                    Projectile fprojectile = 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(fprojectile);
                    shootSound.Play();
                }
            }
        }
Пример #20
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 key)
        {
            MouseState mouse = Mouse.GetState();

            // burger should only respond to input if it still has health
            if (health > 0)
            {
                // move burger using keyboard
                if (key.IsKeyDown(Keys.W) || key.IsKeyDown(Keys.Up))
                {
                    drawRectangle.Y -= GameConstants.BurgerMovementAmount;
                }
                if (key.IsKeyDown(Keys.S) || key.IsKeyDown(Keys.Down))
                {
                    drawRectangle.Y += GameConstants.BurgerMovementAmount;
                }
                if (key.IsKeyDown(Keys.A) || key.IsKeyDown(Keys.Left))
                {
                    drawRectangle.X -= GameConstants.BurgerMovementAmount;
                }
                if (key.IsKeyDown(Keys.D) || key.IsKeyDown(Keys.Right))
                {
                    drawRectangle.X += GameConstants.BurgerMovementAmount;
                }
                if (key.IsKeyDown(Keys.Space) && shooting == false)
                {
                    shooting = true;
                    makeShot = true;
                }
                else
                {
                    makeShot = false;
                }

                if (key.IsKeyUp(Keys.Space) && shooting == true)
                {
                    shooting = false;
                }
            }
            // clamp burger in window
            if (drawRectangle.Left < 0)
            {
                drawRectangle.X = 0;
            }
            if (drawRectangle.Right > GameConstants.WindowWidth)
            {
                drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
            }
            if (drawRectangle.Top < 0)
            {
                drawRectangle.Y = 0;
            }
            if (drawRectangle.Bottom > GameConstants.WindowHeight)
            {
                drawRectangle.Y = GameConstants.WindowHeight - drawRectangle.Height;
            }

            // update shooting allowed
            if (canShoot == false)
            {
                elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                if (elapsedCooldownMilliseconds >= GameConstants.BurgerTotalCooldownMilliseconds || mouse.LeftButton == ButtonState.Released)
                {
                    canShoot = true;
                    elapsedCooldownMilliseconds = 0;
                }
            }

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

            // shoot if appropriate
            if (health > 0)
            {
                if ((mouse.LeftButton == ButtonState.Pressed || makeShot == true) && canShoot == true)
                {
                    canShoot = false;
                    Projectile frenchFriesProjectile = new Projectile(ProjectileType.FrenchFries,
                                                                      sprite: Game1.GetProjectileSprite(ProjectileType.FrenchFries),
                                                                      x: drawRectangle.Center.X,
                                                                      y: drawRectangle.Center.Y - GameConstants.FrenchFriesProjectileOffset,
                                                                      yVelocity: -GameConstants.FrenchFriesProjectileSpeed);
                    Game1.AddProjectile(frenchFriesProjectile);
                    shootSound.Play();
                }
            }
        }
Пример #21
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="keyBoard">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 = keyBoard.X - (drawRectangle.Width / 2);
                //drawRectangle.Y = keyBoard.Y - (drawRectangle.Height / 2);

                // move burger using Keyboard
                if (keyBoard.IsKeyDown(Keys.W))
                {
                    drawRectangle.Y -= GameConstants.BurgerMovementAmount;
                }
                if (keyBoard.IsKeyDown(Keys.S))
                {
                    drawRectangle.Y += GameConstants.BurgerMovementAmount;
                }
                if (keyBoard.IsKeyDown(Keys.A))
                {
                    drawRectangle.X -= GameConstants.BurgerMovementAmount;
                }
                if (keyBoard.IsKeyDown(Keys.D))
                {
                    drawRectangle.X += GameConstants.BurgerMovementAmount;
                }


                // clamp burger in window
                //Right Clamp
                if (drawRectangle.Right > GameConstants.WindowWidth)
                {
                    drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
                }

                //Left Clamp
                if (drawRectangle.Left < 0)
                {
                    drawRectangle.X = 0;
                }

                //Bottom Clamp
                if (drawRectangle.Bottom > GameConstants.WindowHeight)
                {
                    drawRectangle.Y = GameConstants.WindowHeight - drawRectangle.Height;
                }

                //Top Clamp
                if (drawRectangle.Top < 0)
                {
                    drawRectangle.Y = 0;
                }

                // update shooting allowed
                if (keyBoard.IsKeyDown(Keys.Space) && canShoot)
                {
                    canShoot = false;
                    //Projectile initialization
                    projectile = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(
                                                    ProjectileType.FrenchFries), drawRectangle.X + drawRectangle.Width / 2,
                                                drawRectangle.Y - GameConstants.FrenchFriesProjectileOffset,
                                                GameConstants.FrenchFriesProjectileSpeed);

                    //Adding Projectile
                    Game1.AddProjectile(projectile);

                    //play shoot soundEffects
                    shootSound.Play();
                }

                // timer concept (for animations) introduced in Chapter 7
                if (!canShoot)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                }
                // shoot if appropriate
                if (elapsedCooldownMilliseconds >= GameConstants.BurgerTotalCooldownMilliseconds || keyBoard.IsKeyUp(Keys.Space))
                {
                    elapsedCooldownMilliseconds = 0;
                    canShoot = true;
                }
            }
        }
Пример #22
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))
                {
                    drawRectangle.X += GameConstants.BurgerMovementAmount;
                }
                if (keyboard.IsKeyDown(Keys.Left))
                {
                    drawRectangle.X -= GameConstants.BurgerMovementAmount;
                }
                if (keyboard.IsKeyDown(Keys.Up))
                {
                    drawRectangle.Y -= GameConstants.BurgerMovementAmount;
                }
                if (keyboard.IsKeyDown(Keys.Down))
                {
                    drawRectangle.Y += GameConstants.BurgerMovementAmount;
                }
                // clamp burger in window
                if (drawRectangle.Left < 0)
                {
                    drawRectangle.X = 0;
                }
                if (drawRectangle.Right > GameConstants.WindowWidth)
                {
                    drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
                }
                if (drawRectangle.Top < 0)
                {
                    drawRectangle.Y = 0;
                }
                if (drawRectangle.Bottom > GameConstants.WindowHeight)
                {
                    drawRectangle.Y = GameConstants.WindowHeight - drawRectangle.Height;
                }
                // update shooting allowed
                //if (mouse.LeftButton == ButtonState.Pressed && canShoot)
                if (keyboard.IsKeyDown(Keys.Space) && canShoot)
                {
                    canShoot = false;
                    Projectile frenchFries = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries),
                                                            drawRectangle.X - GameConstants.FrenchFriesProjectileOffset, drawRectangle.Y - GameConstants.FrenchFriesProjectileOffset,
                                                            GameConstants.FrenchFriesProjectileSpeed);
                    Game1.AddProjectile(frenchFries);
                    shootSound.Play();
                }
                if (canShoot == false)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                }
                // timer concept (for animations) introduced in Chapter 7
                //if (elapsedCooldownMilliseconds > GameConstants.BurgerTotalCooldownMilliseconds
                //|| mouse.LeftButton == ButtonState.Released)
                if (elapsedCooldownMilliseconds > GameConstants.BurgerTotalCooldownMilliseconds || keyboard.IsKeyUp(Keys.Space))
                {
                    canShoot = true;
                    elapsedCooldownMilliseconds = 0;
                }
                // shoot if appropriate
            }
        }
Пример #23
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, 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.X < 0)
                {
                    drawRectangle.X = 0;
                }
                if (drawRectangle.Y < 0)
                {
                    drawRectangle.Y = 0;
                }
                if (drawRectangle.X + drawRectangle.Width > GameConstants.WindowWidth)
                {
                    drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
                }
                if (drawRectangle.Y + drawRectangle.Height > GameConstants.WindowHeight)
                {
                    drawRectangle.Y = GameConstants.WindowHeight - drawRectangle.Height;
                }



                if (health > 0 && mouse.LeftButton == ButtonState.Pressed && canShoot)
                {
                    Projectile frenchfrie = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries), (int)drawRectangle.Center.X, (int)drawRectangle.Y + GameConstants.FrenchFriesProjectileOffset, GameConstants.FrenchFriesProjectileSpeed);
                    Game1.AddProjectile(frenchfrie);

                    canShoot = false;
                }

                // update shooting allowed

                if (!canShoot)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                    if (GameConstants.BurgerTotalCooldownMilliseconds <= elapsedCooldownMilliseconds || mouse.LeftButton == ButtonState.Released)
                    {
                        elapsedCooldownMilliseconds = 0;
                        canShoot = true;
                    }
                }

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

                // shoot if appropriate
            }
        }
Пример #24
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 keyboard W(up)A(left)S(down)D(right)
                if (keyboard.IsKeyDown(Keys.W))
                {
                    drawRectangle.Y -= GameConstants.BURGER_MOVEMENT_AMOUNT;
                }
                if (keyboard.IsKeyDown(Keys.S))
                {
                    drawRectangle.Y += GameConstants.BURGER_MOVEMENT_AMOUNT;
                }
                if (keyboard.IsKeyDown(Keys.A))
                {
                    drawRectangle.X -= GameConstants.BURGER_MOVEMENT_AMOUNT;
                }
                if (keyboard.IsKeyDown(Keys.D))
                {
                    drawRectangle.X += GameConstants.BURGER_MOVEMENT_AMOUNT;
                }
                // clamp burger in window
                if (drawRectangle.Left < 0)
                {
                    drawRectangle.X = 0;
                }
                if (drawRectangle.Right > GameConstants.WINDOW_WIDTH)
                {
                    drawRectangle.X = GameConstants.WINDOW_WIDTH - drawRectangle.Width;
                }
                if (drawRectangle.Top < 0)
                {
                    drawRectangle.Y = 0;
                }
                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 == true && keyboard.IsKeyDown(Keys.Space))
                {
                    canShoot = false;

                    Projectile frechfriesprojectile = new Projectile(ProjectileType.FrenchFries,
                                                                     Game1.GetProjectileSprite(ProjectileType.FrenchFries),
                                                                     drawRectangle.X + drawRectangle.Width * 1 / 2,
                                                                     drawRectangle.Y - GameConstants.FRENCH_FRIES_PROJECTILE_OFFSET,
                                                                     GameConstants.FRENCH_FRIES_PROJECTILE_SPEED);
                    Game1.AddProjectile(frechfriesprojectile);
                    shootSound.Play();
                }
                // shoot if appropriate
                if (canShoot == false)
                {
                    elapsedCooldownTime += gameTime.ElapsedGameTime.Milliseconds;

                    if (elapsedCooldownTime > GameConstants.BURGER_COOLDOWN_MILLISECONDS || keyboard.IsKeyUp(Keys.Space))
                    {
                        elapsedCooldownTime = 0;
                        canShoot            = true;
                    }
                }
            }
        }
Пример #25
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, MouseState mouse)
        {
            // burger should only respond to input if it still has health
            if (Health > 0)
            {
                drawRectangle.X = mouse.X - sprite.Width / 2;
                drawRectangle.Y = mouse.Y - sprite.Height / 2;
            }

            // move burger using mouse

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

            // update shooting allowed
            if (canShoot == false)
            {
                elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                if (elapsedCooldownMilliseconds > GameConstants.BurgerTotalCooldownMilliseconds && mouse.LeftButton == ButtonState.Released)
                {
                    canShoot = true;
                    elapsedCooldownMilliseconds = 0;
                }
            }
            // timer concept (for animations) introduced in Chapter 7

            // shoot if appropriate
            if (canShoot && Health > 0)
            {
                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    float      projectileVelocity  = GameConstants.FrenchFriesProjectileSpeed;
                    int        projectileLocationX = drawRectangle.Center.X;//In order to make it centered horizontally (barely).
                    int        projectileLocationY = drawRectangle.Center.Y + GameConstants.FrenchFriesProjectileOffset;
                    Projectile burgerAmmo          = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries), projectileLocationX, projectileLocationY - GameConstants.FrenchFriesProjectileOffset, -projectileVelocity);
                    Game1.AddProjectile(burgerAmmo);
                    canShoot = false;
                    shootSound.Play();
                }
            }
        }
Пример #26
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="keyboard">the current state of the keyboard</param>
        public void Update(GameTime gameTime, KeyboardState keyboard)
        {
            // burger should only respond to input if it still has health
            if (health > 0)
            {
                if (keyboard.IsKeyDown(Keys.D) || keyboard.IsKeyDown(Keys.Left))
                {
                    drawRectangle.X += GameConstants.BurgerMovementAmount;
                }
                if (keyboard.IsKeyDown(Keys.A) || keyboard.IsKeyDown(Keys.Right))
                {
                    drawRectangle.X -= GameConstants.BurgerMovementAmount;
                }
                if (keyboard.IsKeyDown(Keys.W) || keyboard.IsKeyDown(Keys.Up))
                {
                    drawRectangle.Y -= GameConstants.BurgerMovementAmount;
                }
                if (keyboard.IsKeyDown(Keys.S) || keyboard.IsKeyDown(Keys.Down))
                {
                    drawRectangle.Y += GameConstants.BurgerMovementAmount;
                }

                // clamp burger in window
                // Y
                if (drawRectangle.Y < 0)
                {
                    drawRectangle.Y = 0;
                }
                else if ((drawRectangle.Y + drawRectangle.Height) > GameConstants.WindowHeight)
                {
                    drawRectangle.Y = GameConstants.WindowHeight - drawRectangle.Height;
                }

                // X
                if (drawRectangle.X < 0)
                {
                    drawRectangle.X = 0;
                }
                else if ((drawRectangle.X + drawRectangle.Width) > GameConstants.WindowWidth)
                {
                    drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
                }

                // update shooting allowed
                // timer concept (for animations) introduced in Chapter 7

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

                    // creating projectile
                    ProjectileType frenchProjectile = ProjectileType.FrenchFries;
                    int            x          = drawRectangle.Center.X;
                    int            y          = drawRectangle.Center.Y - GameConstants.FrenchFriesProjectileOffset;
                    Projectile     projectile = new Projectile(frenchProjectile, Game1.GetProjectileSprite(frenchProjectile), x, y, GameConstants.FrenchFriesProjectileSpeed);
                    Game1.AddProjectile(projectile);

                    // adding sound effect
                    shootSound.Play();
                }

                if (!canShoot)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;

                    // Enable canShoot
                    if (elapsedCooldownMilliseconds >= GameConstants.BurgerTotalCooldownMilliseconds || keyboard.IsKeyUp(Keys.Space))
                    {
                        canShoot = true;
                        elapsedCooldownMilliseconds = 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 key)
        {
            // burger should only respond to input if it still has health
            if (health > 0)
            {
                // move burger using mouse
                //drawRectangle.X = mouse.X - sprite.Width / 2;
                //drawRectangle.Y = mouse.Y - sprite.Height / 2;

                //Move burger using WASD
                if (key.IsKeyDown(Keys.W))
                {
                    drawRectangle.Y -= GameConstants.BurgerMovementAmount;
                }
                if (key.IsKeyDown(Keys.S))
                {
                    drawRectangle.Y += GameConstants.BurgerMovementAmount;
                }
                if (key.IsKeyDown(Keys.A))
                {
                    drawRectangle.X -= GameConstants.BurgerMovementAmount;
                }
                if (key.IsKeyDown(Keys.D))
                {
                    drawRectangle.X += GameConstants.BurgerMovementAmount;
                }

                // clamp burger in window
                if (drawRectangle.Left < 0)
                {
                    drawRectangle.X = 0;
                }
                if (drawRectangle.Right > GameConstants.WindowWidth)
                {
                    drawRectangle.X = GameConstants.WindowWidth - drawRectangle.Width;
                }
                if (drawRectangle.Top < 0)
                {
                    drawRectangle.Y = 0;
                }
                if (drawRectangle.Bottom > GameConstants.WindowHeight)
                {
                    drawRectangle.Y = GameConstants.WindowHeight - drawRectangle.Height;
                }
            }
            // update shooting allowed
            // timer concept (for animations) introduced in Chapter 7
            if (!canShoot)
            {
                elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;

                if (elapsedCooldownMilliseconds >= GameConstants.BurgerTotalCooldownMilliseconds && key.IsKeyDown(Keys.Space))
                {
                    canShoot = true;
                    elapsedCooldownMilliseconds = 0;
                }
            }
            // shoot if appropriate
            if (key.IsKeyDown(Keys.Space) && canShoot)
            {
                canShoot = false;
                Projectile newProjectile = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries),
                                                          drawRectangle.Center.X, drawRectangle.Center.Y - GameConstants.FrenchFriesProjectileOffset, GameConstants.FrenchFriesProjectileSpeed);

                Game1.AddProjectile(newProjectile);

                shootSound.Play();
            }
        }
Пример #28
0
        /// <summary>
        /// Updates the burger's location based on keyboard. Also fires with space
        /// 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 (this.health <= 0)
            {
                return;
            }

            // move burger using keyboard
            if (keyboard.IsKeyDown(Keys.Right))
            {
                drawRectangle.X += GameConstants.BurgerMovementAmount;
            }

            if (keyboard.IsKeyDown(Keys.Left))
            {
                drawRectangle.X -= GameConstants.BurgerMovementAmount;
            }

            if (keyboard.IsKeyDown(Keys.Up))
            {
                drawRectangle.Y -= GameConstants.BurgerMovementAmount;
            }

            if (keyboard.IsKeyDown(Keys.Down))
            {
                drawRectangle.Y += GameConstants.BurgerMovementAmount;
            }


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

            // update shooting allowed
            // timer concept (for animations) introduced in Chapter 7

            // shoot if appropriate
            if ((keyboard.IsKeyDown(Keys.Space)) && (canShoot))
            {
                Projectile projectile = new Projectile(ProjectileType.FrenchFries,
                                                       Game1.GetProjectileSprite(ProjectileType.FrenchFries), drawRectangle.Center.X,
                                                       drawRectangle.Center.Y - GameConstants.FrenchFriesProjectileOffset,
                                                       -GameConstants.FrenchFriesProjectileSpeed);

                Game1.AddProjectile(projectile);
                shootSound.Play();

                canShoot = false;
            }

            if (!canShoot)
            {
                elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;

                if (elapsedCooldownMilliseconds > GameConstants.BurgerTotalCooldownMilliseconds ||
                    keyboard.IsKeyUp(Keys.Space))
                {
                    elapsedCooldownMilliseconds = 0;
                    canShoot = true;
                }
            }
        }
        /// <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 (this.health > 0)
            {
                // move burger using mouse
                this.drawRectangle.X = mouse.X;
                this.drawRectangle.Y = mouse.Y;

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

                if (mouse.LeftButton == ButtonState.Pressed && canShoot)
                {
                    canShoot = false;
                    Projectile projectile = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries),
                                                           this.drawRectangle.X + sprite.Width / 2,
                                                           (this.drawRectangle.Y + GameConstants.FrenchFriesProjectileOffset),
                                                           GameConstants.FrenchFriesProjectileSpeed);

                    Game1.AddProjectile(projectile);
                }

                // update shooting allowed
                if (!canShoot)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                    if ((elapsedCooldownMilliseconds >= GameConstants.BurgerTotalCooldownMilliseconds) || mouse.LeftButton != ButtonState.Pressed)
                    {
                        canShoot = true;
                        elapsedCooldownMilliseconds = 0;
                    }
                }
            }

            // move burger using mouse  - Done up there

            // clamp burger in window  - Done up there

            // update shooting allowed  - Done up there
            // timer concept (for animations) introduced in Chapter 7

            // shoot if appropriate
        }
Пример #30
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 key)
        {
            // burger should only respond to input if it still has health
            if (health > 0)
            {
                // move burger using mouse
                if (key.IsKeyDown(Keys.W) && drawRectangle.Y - GameConstants.BurgerMovementAmount > 0)
                {
                    drawRectangle.Y -= GameConstants.BurgerMovementAmount;
                }
                if (key.IsKeyDown(Keys.A) && drawRectangle.X - GameConstants.BurgerMovementAmount > 0)
                {
                    drawRectangle.X -= GameConstants.BurgerMovementAmount;
                }
                if (key.IsKeyDown(Keys.S) && drawRectangle.Y + sprite.Height + GameConstants.BurgerMovementAmount < GameConstants.WindowHeight)
                {
                    drawRectangle.Y += GameConstants.BurgerMovementAmount;
                }
                if (key.IsKeyDown(Keys.D) && drawRectangle.X + sprite.Width + GameConstants.BurgerMovementAmount < GameConstants.WindowWidth)
                {
                    drawRectangle.X += GameConstants.BurgerMovementAmount;
                }



                if (key.IsKeyDown(Keys.Space) && canShoot)
                {
                    Projectile NewProjectile = new Projectile(ProjectileType.FrenchFries, Game1.GetProjectileSprite(ProjectileType.FrenchFries), drawRectangle.X + GameConstants.FrenchFriesProjectileOffset, drawRectangle.Y + GameConstants.FrenchFriesProjectileOffset, GameConstants.FrenchFriesProjectileSpeed);
                    Game1.AddProjectile(NewProjectile);
                    canShoot = false;
                    shootSound.Play();
                }
                if (!canShoot)
                {
                    elapsedCooldownMilliseconds += gameTime.ElapsedGameTime.Milliseconds;
                    if (elapsedCooldownMilliseconds > GameConstants.BurgerTotalCooldownMilliseconds)
                    {
                        canShoot = true;
                        elapsedCooldownMilliseconds = 0;
                    }
                }
                if (!key.IsKeyDown(Keys.Space))
                {
                    canShoot = true;
                }
            }
            // clamp burger in window

            // update shooting allowed
            // timer concept (for animations) introduced in Chapter 7

            // shoot if appropriate
        }