Exemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            MouseInputManager.Begin();
            KeyboardInputManager.Begin();

            // Change Gravity
            if (KeyboardInputManager.IsKeyPressed(Keys.VolumeUp))
            {
                Gravity += new Vector2(0f, -5);
            }
            if (KeyboardInputManager.IsKeyPressed(Keys.VolumeDown))
            {
                Gravity -= new Vector2(0f, -5);
            }

            // Change Impulse
            if (KeyboardInputManager.IsKeyPressed(Keys.Up))
            {
                _impulse += 10f;
            }
            if (KeyboardInputManager.IsKeyPressed(Keys.Down))
            {
                _impulse -= 10f;
            }

            if (_impulse == 0f)
            {
                _impulse = _playerBodyComponent.Mass * 10 / DeltaTime;
            }

            #region Camera
            _cameraPosition.X = MouseInputManager.GetPosition().X;
            _cameraPosition.Y = InvertPositionY(MouseInputManager.GetPosition().Y);

            Camera2D.Position = _cameraPosition;

            if (KeyboardInputManager.IsKeyDown(Keys.OemPlus))
            {
                Camera2D.Zoom -= new Vector2(0.01f);
            }

            if (KeyboardInputManager.IsKeyDown(Keys.OemMinus))
            {
                Camera2D.Zoom += new Vector2(0.01f);
            }

            if (KeyboardInputManager.IsKeyPressed(Keys.R))
            {
                Camera2D.Reset();
            }
            #endregion

            #region Player
            if (KeyboardInputManager.IsKeyDown(Keys.Right))
            {
                _playerBodyComponent.SetLinearVelocityX(100f);
                _isMoving = true;
            }

            if (KeyboardInputManager.IsKeyDown(Keys.Left))
            {
                _playerBodyComponent.SetLinearVelocityX(-100f);
                _isMoving = true;
            }

            if (!_isMoving)
            {
                _playerBodyComponent.SetLinearVelocityX(0f);
                _impulse = _playerBodyComponent.Mass * 10 / DeltaTime;
            }

            if (KeyboardInputManager.IsKeyPressed(Keys.Space))
            {
                _playerBodyComponent.ApplyLinearImpulseY(_impulse);
            }
            #endregion

            KeyboardInputManager.End();
            MouseInputManager.End();

            _textComponent.Text = BuildDebugText();
            _isMoving           = false;

            base.Update(gameTime);
        }