Beispiel #1
0
        /// <summary>
        /// Update the gun position and animated muzzle fire
        /// </summary>
        public override void Update(GameTime gameTime, Vector2 position, SpriteEffects flip)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Vector2 offset = (flip == SpriteEffects.None) ? new Vector2(45, 0) : new Vector2(-45, 0);

            Flip     = flip;
            Position = position + offset;

            sprite.PlayAnimation(baseGraphic);

            if (isShooting)
            {
                muzzleAnimationTimer += elapsed;
                muzzle.PlayAnimation(muzzleFire);
                if (muzzleAnimationTimer > 0.20f)
                {
                    muzzleAnimationTimer = 0.0f;
                    isShooting           = false;
                    muzzle.StopAnimation();
                }
            }

            if (!canShoot)
            {
                rateOfFire += elapsed;
                if (rateOfFire > MAXFIRERATE)
                {
                    rateOfFire = 0f;
                    canShoot   = true;
                }
            }

            // Update call for bullets
            foreach (HandgunBullet bullet in _bullets)
            {
                bullet.Update(gameTime);
            }
        }