コード例 #1
0
        public void Update(float dtime, InputHelper input)
        {
            HandleInput(input);

            Tangent.X = (float)Math.Cos(BodyTorso.Rotation);
            Tangent.Y = (float)Math.Sin(BodyTorso.Rotation);
            Normal.X = -Tangent.Y;
            Normal.Y = Tangent.X;

            if (LegState == LegStates.Leaping && BodyTorso.LinearVelocity.Y > 0 && IsLandable)
            {
                LegState = LegStates.Squatting;
            }

            if (LegState != LegStateOld)
            {
                switch (LegState)
                {
                    case LegStates.Standing:
                        SpriteLeg.Texture = TextureStanding;
                        break;
                    case LegStates.Squatting:
                        SpriteLeg.Texture = TextureSquatting;
                        break;
                    case LegStates.Leaping:
                        SpriteLeg.Texture = TextureLeaping;
                        break;
                    case LegStates.Walking1:
                        SpriteLeg.Texture = TextureWalking1;
                        break;
                    case LegStates.Walking2:
                        SpriteLeg.Texture = TextureWalking2;
                        break;
                    case LegStates.Walking3:
                        SpriteLeg.Texture = TextureWalking3;
                        break;
                    default:
                        break;
                }
            }
            LegStateOld = LegState;
        }
コード例 #2
0
 /// <summary>
 /// Moves the camera forward one timestep.
 /// </summary>
 /// <param name="input">
 /// the an InputHelper input representing the current 
 /// input state.
 /// </param>
 public void Update(InputHelper input)
 {
     if (!_transitioning)
     {
         if (_trackingBody == null)
         {
             if (_clampingEnabled(this))
                 _targetPosition = Vector2.Clamp(_position + new Vector2(
                         _horizontalCameraMovement(input, this),
                         _verticalCameraMovement(input, this)),
                         _minPosition,
                         _maxPosition);
             else
                 _targetPosition += new Vector2(
                     _horizontalCameraMovement(input, this),
                     _verticalCameraMovement(input, this));
         }
         else
         {
             if (_clampingEnabled(this))
                 _targetPosition = Vector2.Clamp(
                     _trackingBody.Position,
                     _minPosition,
                     _maxPosition);
             else
                 _targetPosition = _trackingBody.Position;
         }
         if (_zoomIn(input))
             _targetZoom = Math.Min(_maxZoom, _zoom + _zoomRate);
         if (_zoomOut(input))
             _targetZoom = Math.Max(_minZoom, _zoom - _zoomRate);
         //these might need to be swapped
         if (_rotateLeft(input))
             _targetRotation = (_rotation + _rotationRate) % (float)(Math.PI * 2);
         if (_rotateRight(input))
             _targetRotation = (_rotation - _rotationRate) % (float)(Math.PI * 2);
         if (input.IsCurPress(Buttons.RightStick))
         {
             _transitioning = true;
             _targetPosition = _origPosition;
             _targetRotation = _origRotation;
             _targetZoom = _origZoom;
             _trackingBody = null;
         }
     }
     else if (_transition < 1)
     {
         _transition += _transitionSpeed;
     }
     if (_transition >= 1f ||
         (_position == _origPosition &&
         _rotation == _origRotation &&
         _zoom == _origZoom))
     {
         _transition = 0;
         _transitioning = false;
     }
     _position = Vector2.SmoothStep(_position, _targetPosition, _smoothingSpeed);
     _rotation = MathHelper.SmoothStep(_rotation, _targetRotation, _smoothingSpeed);
     _zoom = MathHelper.SmoothStep(_zoom, _targetZoom, _smoothingSpeed);
 }
コード例 #3
0
        public void HandleInput(InputHelper input)
        {
            if (IsGrounded)
            {
                if (input.CurrentKeyboardState.IsKeyDown(KeyUp) && IsLandable)
                {
                    Jump();
                }
                else if (input.CurrentKeyboardState.IsKeyDown(KeyDown) && input.LastKeyboardState.IsKeyUp(KeyDown))
                {
                    Squat();
                }
                else if(input.LastKeyboardState.IsKeyDown(KeyDown) && input.CurrentKeyboardState.IsKeyUp(KeyDown))
                {
                    Stand();
                }

                if (input.CurrentKeyboardState.IsKeyDown(KeyLeft))
                {
                    IsWalking = true;
                    timerWalking.Start();
                    BodyTorso.ApplyForce(Tangent * WalkForce * -1);
                }
                else if (input.CurrentKeyboardState.IsKeyDown(KeyRight))
                {
                    IsWalking = true;
                    timerWalking.Start();
                    BodyTorso.ApplyForce(Tangent * WalkForce);
                }
                else
                {
                    IsWalking = false;
                    timerWalking.Stop();
                }

            }
            else
            {
                if (input.CurrentKeyboardState.IsKeyDown(KeyLeft))
                {
                    BodyTorso.ApplyForce(Tangent * GlideForce * -1);
                }
                if (input.CurrentKeyboardState.IsKeyDown(KeyRight))
                {
                    BodyTorso.ApplyForce(Tangent * GlideForce);
                }
            }
        }