Пример #1
0
        /// <summary>
        /// Handles input, performs physics, and animates the player sprite.
        /// </summary>
        /// <remarks>
        /// We pass in all of the input states so that our game is only polling the hardware
        /// once per frame. We also pass the game's orientation because when using the accelerometer,
        /// we need to reverse our motion when the orientation is in the LandscapeRight orientation.
        /// </remarks>
        public void Update(
            GameTime gameTime,
            KeyboardState keyboardState,
            GamePadState gamePadState,
            TouchCollection touchState,
            AccelerometerState accelState,
            DisplayOrientation orientation,
            Viewport viewport)
        {
            if (!IsRespawnable)
            {
                return;
            }

            GetInput(keyboardState, gamePadState, touchState, accelState, orientation);

            if (isThrowGrenade)
            {
                sprite.PlayAnimation(grenadeAnimation);
                m_bomb.Update(gameTime, Position, flip);
            }
            else
            {
                ApplyPhysics(gameTime);

                if (IsAlive && IsOnGround && !isRolling)
                {
                    if (Math.Abs(Velocity.X) - 0.02f > 0)
                    {
                        sprite.PlayAnimation(runAnimation);
                    }
                    else
                    {
                        sprite.PlayAnimation(idleAnimation);
                    }
                }

                //weapon.Update(gameTime, Position, flip);
                m_handgun.Update(gameTime, Position, flip);
                m_shotgun.Update(gameTime, Position, flip);
                m_knife.Update(gameTime, Position, flip);
                m_bomb.Update(gameTime, Position, flip);

                //Sprite effects
                if (pulseRed)
                {
                    pulseRedTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (pulseRedTime > MAX_PULSE_TIME)
                    {
                        pulseRed     = false;
                        pulseRedTime = 0.0f;
                    }
                }
            }
            // Clear input.
            movement  = 0.0f;
            isJumping = false;
        }