public override void Update(GameTime gameTime)
        {
            var rotationToVector = _shipEntity.RotationToVector();

            _textEntity.SetPosition(new Vector2(_shipEntity.Position.X, _shipEntity.Position.Y + 100f));
            _textComponent.Text = $"Rotation to Vector: {rotationToVector}" +
                                  $"\nButton Touched: {_touchGamepadButtonsComponent.ButtonTouched}";

            // F = m * a
            var linearImpulse = _bodyComponent.Mass * 4;

            // T = I * a
            var angularImpulse = _bodyComponent.Inertia * 0.1f;

            // Change Angle
            if (_touchGamepadButtonsComponent.IsTouched(Buttons.Button02))
            {
                _bodyComponent.ApplyAngularImpulse(-angularImpulse);
            }
            else if (_touchGamepadButtonsComponent.IsTouched(Buttons.Button03))
            {
                _bodyComponent.ApplyAngularImpulse(angularImpulse);
            }
            else
            {
                _bodyComponent.AngularVelocity = 0f;
            }

            // Change Linear Impulse
            if (_touchGamepadButtonsComponent.IsTouched(Buttons.Button01))
            {
                _bodyComponent.ApplyLinearImpulse(new Vector2(-linearImpulse * rotationToVector.X, -linearImpulse * rotationToVector.Y));
            }

            if (_touchGamepadButtonsComponent.IsTouched(Buttons.Button04))
            {
                _bodyComponent.ApplyLinearImpulse(new Vector2(linearImpulse / 4 * rotationToVector.X, linearImpulse / 4 * rotationToVector.Y));
            }

            base.Update(gameTime);
        }
Ejemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            var rotationToVector = _carEntity.RotationToVector();

            // F = m * a
            var linearImpulse = _bodyComponent.Mass * 4;

            // T = I * a
            var angularImpulse = _bodyComponent.Inertia * 0.1f;

            _textEntity.SetPosition(new Vector2(_carEntity.Position.X, _carEntity.Position.Y + 150f));
            _textComponent.Text = $"Rotation to Vector: {rotationToVector}" +
                                  $"\nAngular Velocity: {_bodyComponent.AngularVelocity}" +
                                  $"\nLinear Velocity: {_bodyComponent.LinearVelocity}";

            // Change Angle
            if (_touchJoystickComponent.Direction.X != 0)
            {
                if ((_touchJoystickComponent.Direction.X == -1 && _bodyComponent.AngularVelocity < 0.5f) ||
                    (_touchJoystickComponent.Direction.X == 1 && _bodyComponent.AngularVelocity > -0.5f))
                {
                    _bodyComponent.ApplyAngularImpulse(_touchJoystickComponent.Direction.X * -angularImpulse);
                }
            }
            else
            {
                _bodyComponent.AngularVelocity = 0f;
            }

            // Change Linear Impulse
            if (_touchJoystickComponent.Direction.Y != 0)
            {
                _bodyComponent.ApplyLinearImpulse(new Vector2(
                                                      _touchJoystickComponent.Direction.Y * linearImpulse * rotationToVector.X,
                                                      _touchJoystickComponent.Direction.Y * linearImpulse * rotationToVector.Y));
            }
            else
            {
                _bodyComponent.LinearVelocity = Vector2.Zero;
            }

            base.Update(gameTime);
        }