示例#1
0
        public override void Update(GameTime gameTime)
        {
            KeyboardInputManager.Begin();

            // Move camera
            if (KeyboardInputManager.IsKeyDown(Keys.Left))
            {
                _cameraPosition.X += 12f * DeltaTime;
            }

            if (KeyboardInputManager.IsKeyDown(Keys.Right))
            {
                _cameraPosition.X -= 12f * DeltaTime;
            }

            if (KeyboardInputManager.IsKeyDown(Keys.Up))
            {
                _cameraPosition.Y -= 12f * DeltaTime;
            }

            if (KeyboardInputManager.IsKeyDown(Keys.Down))
            {
                _cameraPosition.Y += 12f * DeltaTime;
            }

            // We make it possible to rotate the player body
            if (KeyboardInputManager.IsKeyDown(Keys.A))
            {
                _playerBodyComponent.ApplyTorque(10);
            }

            if (KeyboardInputManager.IsKeyDown(Keys.D))
            {
                _playerBodyComponent.ApplyTorque(-10);
            }

            if (KeyboardInputManager.IsKeyPressed(Keys.Space))
            {
                _playerBodyComponent.ApplyLinearImpulse(new Vector2(0f, 10f));
            }

            Camera2D.Position = _cameraPosition;

            KeyboardInputManager.End();

            base.Update(gameTime);
        }
示例#2
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);
        }