コード例 #1
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method, this will only be called when the gameplay screen is active.
        /// </summary>
        /// <param name="input">The InputState instance that relays the state of input.</param>
        public void HandleInput(InputState input)
        {
            //Enable the GUI to handle input as well.
            _GUI.HandleInput(input);

            //If the GUI hasn't been clicked.
            if (!_IsGUIClicked)
            {
                #region Mouse Clicks
                //If a left mouse click has occured, see what the user wants to be selected.
                if (input.IsNewLeftMouseClick())
                {
                    //If the click wasn't on any of the animation bars, select the closest bone to the mouse.
                    //if (!Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), _AnimationBars.Position, _AnimationBars.Width, _AnimationBars.Height))
                    {
                        //The bone index.
                        int index = -1;
                        //The shortest distance.
                        float shortest = -1;

                        //Loop through all bones in all skeletons and find the closest one.
                        foreach (Bone b in _Character.Skeleton.Bones)
                        {
                            //The average distance to the bone.
                            float distance = Vector2.Distance(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Vector2.Divide(Vector2.Add(b.TransformedPosition,
                                Helper.CalculateOrbitPosition(b.TransformedPosition, b.TransformedRotation, b.Length)), 2));

                            //Determine the shortest distance and the bone.
                            if (shortest == -1) { index = b.Index; shortest = distance; }
                            else if ((shortest != -1) && (distance < shortest))
                            {
                                //The selected index.
                                index = b.Index;
                                //The shortest distance so far.
                                shortest = distance;
                            }
                        }

                        //Pass along the new selected bone index.
                        _SelectedBoneIndex = index;
                    }
                }
                #endregion

                #region Keyboard Presses
                //If the user presses the TAB button, loop through all bones in the skeleton.
                if (input.IsNewKeyPress(Keys.Tab))
                {
                    //Increment the counter.
                    _SelectedBoneIndex++;
                    //Check the bounds of the selected bone index.
                    if (_SelectedBoneIndex >= _Character.Skeleton.Bones.Count) { _SelectedBoneIndex = 0; }
                }

                //If the user holds down CTRL.
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.LeftControl) || input.CurrentKeyboardStates[0].IsKeyDown(Keys.RightControl))
                {
                    //Add a new bone to the skeleton.
                    if (input.IsNewKeyPress(Keys.B)) { DisplayCreateBoneDialog(_SelectedBoneIndex); }
                    //If the user presses the K button, insert a new keyframe after the selected one.
                    if (input.IsNewKeyPress(Keys.K)) { AddKeyframe(GetAnimationBar().SelectedFrameNumber + 1); }
                    //If the user presses the DELETE button, delete the selected keyframe.
                    if (input.IsNewKeyPress(Keys.Delete)) { DeleteKeyframe(GetAnimationBar().SelectedFrameNumber); }
                }

                //If the animation has been paused.
                if (!IsAnyAnimationPlaying())
                {
                    //If the user holds down CTRL.
                    if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.LeftControl) || input.CurrentKeyboardStates[0].IsKeyDown(Keys.RightControl))
                    {
                        //Move the selected bone.
                        if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Right)) { MoveBone(_SelectedBoneIndex, new Vector2(1, 0)); }
                        else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Left)) { MoveBone(_SelectedBoneIndex, new Vector2(-1, 0)); }
                        else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Up)) { MoveBone(_SelectedBoneIndex, new Vector2(0, -1)); }
                        else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Down)) { MoveBone(_SelectedBoneIndex, new Vector2(0, 1)); }
                    }
                    //Otherwise rotate the selected bone.
                    else
                    {
                        //If a bone is selected and the user presses an arrow button, rotate the bone.
                        if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Right))
                        {
                            //Rotate the bone and acknowledge that it has been modified.
                            _Character.Skeleton.Bones[_SelectedBoneIndex].Rotation += .1f;
                            _ModifiedBone[_SelectedBoneIndex] = true;
                        }
                        else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Left))
                        {
                            //Rotate the bone and acknowledge that it has been modified.
                            _Character.Skeleton.Bones[_SelectedBoneIndex].Rotation -= .1f;
                            _ModifiedBone[_SelectedBoneIndex] = true;
                        }
                    }
                }
                #endregion
            }
        }
コード例 #2
0
ファイル: DebugSystem.cs プロジェクト: LaudableBauble/Bedlam
        /// <summary>
        /// Handle all input to the debug system.
        /// </summary>
        /// <param name="input">The input to consider.</param>
        public void HandleInput(InputState input)
        {
            if (input.IsNewKeyPress(Keys.F1)) { Debug(); }

            if (input.IsKeyDown(Keys.LeftShift))
            {
                if (input.IsNewKeyPress(Keys.Q)) { _World.Gravity = new Vector2(0, 0); }
                if (input.IsNewKeyPress(Keys.W)) { _World.Gravity = new Vector2(1, 0); }
                if (input.IsNewKeyPress(Keys.E)) { _World.Gravity = new Vector2(10, 0); }
                if (input.IsNewKeyPress(Keys.R)) { _World.Gravity = new Vector2(100, 0); }
                if (input.IsNewKeyPress(Keys.T)) { _World.Gravity = new Vector2(1000, 0); }
            }
            else
            {
                if (input.IsNewKeyPress(Keys.Q)) { _World.Gravity = new Vector2(0, -10); }
                if (input.IsNewKeyPress(Keys.W)) { _World.Gravity = new Vector2(0, -1); }
                if (input.IsNewKeyPress(Keys.E)) { _World.Gravity = new Vector2(0, 1); }
                if (input.IsNewKeyPress(Keys.R)) { _World.Gravity = new Vector2(0, 10); }
                if (input.IsNewKeyPress(Keys.T)) { _World.Gravity = new Vector2(0, 100); }
            }

            /*if (input.CurrentKeyboardStates[i].IsKeyDown(Keys.Z)) { System.UpdateSpeed = 0.1f; }
            if (input.CurrentKeyboardStates[i].IsKeyDown(Keys.X)) { System.UpdateSpeed = 0.01f; }
            if (input.CurrentKeyboardStates[i].IsKeyDown(Keys.C)) { System.UpdateSpeed = 0.001f; }
            if (input.CurrentKeyboardStates[i].IsKeyDown(Keys.V)) { System.UpdateSpeed = 0.0001f; }
            if (input.CurrentKeyboardStates[i].IsKeyDown(Keys.B)) { System.UpdateSpeed = 0.0f; }*/
        }
コード例 #3
0
ファイル: LevelEditor.cs プロジェクト: LaudableBauble/Bedlam
        /// <summary>
        /// Handle user input.
        /// </summary>
        /// <param name="input">The helper for reading input from the user.</param>
        public void HandleInput(InputState input)
        {
            //Let the GUI handle user input.
            _GUI.HandleInput(input);
            //Enable the DebugSystem to handle input.
            _DebugSystem.HandleInput(input);

            #region Camera
            //If the CTRL button is not held down.
            if (!input.IsKeyDown(Keys.LeftControl))
            {
                //Manage the camera movement.
                if (input.IsKeyDown(Keys.W)) { MoveCamera(new Vector2(0, -1)); }
                if (input.IsKeyDown(Keys.S)) { MoveCamera(new Vector2(0, 1)); }
                if (input.IsKeyDown(Keys.A)) { MoveCamera(new Vector2(-1, 0)); }
                if (input.IsKeyDown(Keys.D)) { MoveCamera(new Vector2(1, 0)); }

                //Let the user zoom in and out.
                if (input.IsKeyDown(Keys.Z)) { _Camera.Zoom(-.05f); }
                if (input.IsKeyDown(Keys.X)) { _Camera.Zoom(.05f); }
            }
            #endregion

            #region Editing
            //If the CTRL button is down.
            if (input.IsKeyDown(Keys.LeftControl))
            {
                //Manage the item movement.
                if (input.IsKeyDown(Keys.W)) { MoveItem(new Vector2(0, -5)); }
                if (input.IsKeyDown(Keys.S)) { MoveItem(new Vector2(0, 5)); }
                if (input.IsKeyDown(Keys.A)) { MoveItem(new Vector2(-5, 0)); }
                if (input.IsKeyDown(Keys.D)) { MoveItem(new Vector2(5, 0)); }

                //Let the user rotate the item.
                if (input.IsKeyDown(Keys.Q)) { RotateItem(-.01f); }
                if (input.IsKeyDown(Keys.E)) { RotateItem(.01f); }

                //Let the user scale the item.
                if (input.IsKeyDown(Keys.Z)) { ScaleItem(new Vector2(-.05f, -.05f)); }
                if (input.IsKeyDown(Keys.X)) { ScaleItem(new Vector2(.05f, .05f)); }

                //Let the user copy the item.
                if (input.IsNewKeyPress(Keys.V)) { CopyItem(Helper.GetMousePosition()); }
            }

            //If the GUI hasn't been clicked.
            if (!_IsGUIClicked)
            {
                //Select an item.
                if (input.IsNewLeftMouseClick()) { SelectItem(GetItemAtPosition(Helper.GetMousePosition())); }

                //If the user wants to seize and move an item with the mouse.
                if (input.IsNewLeftMousePress() && _SelectedItem != null)
                {
                    //Handle the item grapple.
                    GrappleItem();
                }
            }

            //If the user disengages the grapple function.
            if (input.IsNewLeftMouseReleased())
            {
                //If the grapple joint exists.
                if (_MouseGrappleJoint != null)
                {
                    //Remove the grapple joint from the world simulation.
                    _Level.World.RemoveJoint(_MouseGrappleJoint);
                    _MouseGrappleJoint = null;
                }

                //Reset the grapple point.
                _ItemGrapplePoint = Vector2.Zero;
            }
            #endregion

            //Quickie.
            if (input.IsKeyDown(Keys.N)) { SetUpTreeView(); }
            if (input.IsNewKeyPress(Keys.M)) { ToggleGUI(); }

            //Let the level handle user input.
            _Level.HandleInput(input);
        }