/// <summary>
        /// If the sprite has animations for walking in the
        /// four directions then it switches between the
        /// animations depending on the direction
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            PreviousKey = CurrentKey;
            CurrentKey  = Keyboard.GetState();

            IsActive = false;

            Vector2 newDirection = movement.ChangeDirection(CurrentKey);

            if (newDirection != Vector2.Zero)
            {
                Direction = newDirection;
                IsActive  = true;
            }

            if (CanWalk)
            {
                Walk();
            }

            if (CurrentKey.IsKeyDown(Keys.Space) &&
                PreviousKey.IsKeyUp(Keys.Space) && (BulletController != null))
            {
                BulletController.AddBullet(this);
            }

            base.Update(gameTime);
        }
예제 #2
0
        protected override void Update(GameTime gameTime)
        {
            PreviousKey = CurrentKey;
            CurrentKey  = Keyboard.GetState();


            if (_currentState is MenuState)
            {
                if (Graphics.IsFullScreen)
                {
                    Graphics.ToggleFullScreen();
                }
                if (CurrentKey.IsKeyDown(Keys.Escape) && PreviousKey.IsKeyUp(Keys.Escape))
                {
                    Exit();
                }
            }

            if (CurrentKey.IsKeyDown(Keys.F11) && PreviousKey.IsKeyUp(Keys.F11) && !(_currentState is MenuState))
            {
                Graphics.ToggleFullScreen();
            }

            ScreenWidth  = GraphicsDevice.Viewport.Bounds.Width;
            ScreenHeight = GraphicsDevice.Viewport.Bounds.Height;


            if (_nextState != null)
            {
                _currentState = _nextState;
                _currentState.LoadContent();

                _nextState = null;
            }

            _currentState.Update(gameTime);

            _currentState.PostUpdate(gameTime);

            base.Update(gameTime);
        }