示例#1
0
        /// <summary>
        /// Update the user-controlled movement of the party.
        /// </summary>
        /// <returns>The controlled movement for this update.</returns>
        private static Vector2 UpdateUserMovement(GameTime gameTime)
        {
            Vector2 desiredMovement = Vector2.Zero;

            // accumulate the desired direction from user input
            if (InputManager.IsActionPressed(InputManager.Action.MoveCharacterUp))
            {
                if (CanPartyLeaderMoveUp())
                {
                    desiredMovement.Y -= partyLeaderMovementSpeed;
                }
            }
            if (InputManager.IsActionPressed(InputManager.Action.MoveCharacterDown))
            {
                if (CanPartyLeaderMoveDown())
                {
                    desiredMovement.Y += partyLeaderMovementSpeed;
                }
            }
            if (InputManager.IsActionPressed(InputManager.Action.MoveCharacterLeft))
            {
                if (CanPartyLeaderMoveLeft())
                {
                    desiredMovement.X -= partyLeaderMovementSpeed;
                }
            }
            if (InputManager.IsActionPressed(InputManager.Action.MoveCharacterRight))
            {
                if (CanPartyLeaderMoveRight())
                {
                    desiredMovement.X += partyLeaderMovementSpeed;
                }
            }

            // if there is no desired movement, then we can't determine a direction
            if (desiredMovement == Vector2.Zero)
            {
                return(Vector2.Zero);
            }

            return(desiredMovement);
        }