コード例 #1
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputHelper input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }
コード例 #2
0
ファイル: MenuScreen.cs プロジェクト: guozanhua/KinectRagdoll
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputHelper input)
        {
            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                _selectedEntry--;

                if (_selectedEntry < 0)
                    _selectedEntry = _menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {
                _selectedEntry++;

                if (_selectedEntry >= _menuEntries.Count)
                    _selectedEntry = 0;
            }

#if !XBOX
            // Mouse or touch on a menu item
            if (input.CurrentMouseState.X != input.LastMouseState.X ||
                input.CurrentMouseState.Y != input.LastMouseState.Y)
            {
                int hoverIndex = GetMenuEntryAt(ref input.CurrentMouseState);
                if (hoverIndex > -1)
                {
                    _selectedEntry = hoverIndex;
                }
            }

            if (input.CurrentMouseState.LeftButton == ButtonState.Released &&
                input.LastMouseState.LeftButton == ButtonState.Pressed)
            {
                int index = GetMenuEntryAt(ref input.LastMouseState);
                if (index > -1)
                {
                    _selectedEntry = index;
                    OnSelectEntry(_selectedEntry, input.DefaultPlayerIndex);
                }
            }
#endif

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(_selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
コード例 #3
0
ファイル: LogoScreen.cs プロジェクト: guozanhua/KinectRagdoll
 public override void HandleInput(InputHelper input)
 {
     if (input.CurrentKeyboardState.GetPressedKeys().Length > 0 ||
         input.CurrentGamePadState.IsButtonDown(Buttons.A | Buttons.Start | Buttons.Back) ||
         input.CurrentMouseState.LeftButton == ButtonState.Pressed)
     {
         _duration = TimeSpan.Zero;
     }
 }
コード例 #4
0
        public override void HandleGamePadInput(InputHelper input)
        {
            Vector2 force = 100*input.CurrentGamePadState.ThumbSticks.Left;
            _rectangles[0].Body.ApplyForce(force);

            float rotation = 200*input.CurrentGamePadState.Triggers.Left;
            _rectangles[0].Body.ApplyTorque(rotation);

            rotation = -200*input.CurrentGamePadState.Triggers.Right;
            _rectangles[0].Body.ApplyTorque(rotation);

            base.HandleGamePadInput(input);
        }
コード例 #5
0
        public override void HandleKeyboardInput(InputHelper input)
        {
            const float forceAmount = 100;
            Vector2 force = Vector2.Zero;

            if (input.CurrentKeyboardState.IsKeyDown(Keys.A))
            {
                force += new Vector2(-forceAmount, 0);
            }
            if (input.CurrentKeyboardState.IsKeyDown(Keys.S))
            {
                force += new Vector2(0, -forceAmount);
            }
            if (input.CurrentKeyboardState.IsKeyDown(Keys.D))
            {
                force += new Vector2(forceAmount, 0);
            }
            if (input.CurrentKeyboardState.IsKeyDown(Keys.W))
            {
                force += new Vector2(0, forceAmount);
            }

            _rectangles[0].Body.ApplyForce(force);

            const float torqueAmount = 200;
            float torque = 0;

            if (input.CurrentKeyboardState.IsKeyDown(Keys.E))
            {
                torque += torqueAmount;
            }
            if (input.CurrentKeyboardState.IsKeyDown(Keys.Q))
            {
                torque -= torqueAmount;
            }

            _rectangles[0].Body.ApplyTorque(torque);

            base.HandleKeyboardInput(input);
        }
コード例 #6
0
        public override void HandleInput(InputHelper input)
        {
            //Xbox
            if (input.IsNewButtonPress(Buttons.Start))
            {
                EnableOrDisableFlag(DebugViewFlags.Shape);
                EnableOrDisableFlag(DebugViewFlags.DebugPanel);
                EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
            }
            if (input.IsNewButtonPress(Buttons.Back))
            {
                ExitScreen();
            }

            //Windows
            if (input.IsNewKeyPress(Keys.F1))
            {
                EnableOrDisableFlag(DebugViewFlags.Shape);
            }
            else if (input.IsNewKeyPress(Keys.F2))
            {
                EnableOrDisableFlag(DebugViewFlags.DebugPanel);
            }
            else if (input.IsNewKeyPress(Keys.F3))
            {
                EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
            }
            else if (input.IsNewKeyPress(Keys.F4))
            {
                EnableOrDisableFlag(DebugViewFlags.AABB);
            }
            else if (input.IsNewKeyPress(Keys.F5))
            {
                EnableOrDisableFlag(DebugViewFlags.CenterOfMass);
            }
            else if (input.IsNewKeyPress(Keys.F6))
            {
                EnableOrDisableFlag(DebugViewFlags.Joint);
            }
            else if (input.IsNewKeyPress(Keys.F7))
            {
                EnableOrDisableFlag(DebugViewFlags.ContactPoints);
                EnableOrDisableFlag(DebugViewFlags.ContactNormals);
            }
            else if (input.IsNewKeyPress(Keys.F8))
            {
                EnableOrDisableFlag(DebugViewFlags.PolygonPoints);
            }

            if (input.IsNewKeyPress(Keys.Escape))
            {
                ExitScreen();
            }

            if (World != null)
            {
#if XBOX
                GamePad(input.CurrentGamePadState, input.LastGamePadState);
#else
                Mouse(input);
#endif
            }

            base.HandleInput(input);
        }
コード例 #7
0
        private void Mouse(InputHelper state)
        {
            Vector2 position = Camera2D.ConvertScreenToWorld(state.MousePosition);

            if (state.IsOldButtonPress(MouseButtons.LeftButton))
            {
                MouseUp();
            }
            else if (state.IsNewButtonPress(MouseButtons.LeftButton))
            {
                MouseDown(position);
            }

            if (_fixedMouseJoint != null)
            {
                _fixedMouseJoint.WorldAnchorB = position;
            }
        }
コード例 #8
0
ファイル: GameScreen.cs プロジェクト: guozanhua/KinectRagdoll
 public virtual void HandleKeyboardInput(InputHelper input)
 {
     //Disabled in release versions of FPE
     //if (input.IsKeyDown(Keys.PageUp))
     //    ScreenManager.Camera.Zoom += 0.02f;
     //if (input.IsKeyDown(Keys.PageDown))
     //    ScreenManager.Camera.Zoom -= 0.02f;
     //if (input.IsKeyDown(Keys.Delete))
     //    ScreenManager.Camera.Rotation += 0.01f;
     //if (input.IsKeyDown(Keys.End))
     //    ScreenManager.Camera.Rotation -= 0.01f;
     //if (input.IsKeyDown(Keys.Left))
     //    ScreenManager.Camera.MoveCamera(new Vector2(-0.5f, 0));
     //if (input.IsKeyDown(Keys.Right))
     //    ScreenManager.Camera.MoveCamera(new Vector2(+0.5f, 0));
     //if (input.IsKeyDown(Keys.Down))
     //    ScreenManager.Camera.MoveCamera(new Vector2(0, -0.5f));
     //if (input.IsKeyDown(Keys.Up))
     //    ScreenManager.Camera.MoveCamera(new Vector2(0, +0.5f));
     //if (input.IsNewKeyPress(Keys.Home))
     //    ScreenManager.Camera.ResetCamera();
 }
コード例 #9
0
ファイル: GameScreen.cs プロジェクト: guozanhua/KinectRagdoll
 public virtual void HandleGamePadInput(InputHelper input)
 {
     //Disabled in release versions of FPE
     if (input.CurrentGamePadState.Buttons.RightShoulder == ButtonState.Pressed)
         ScreenManager.Camera.Zoom += 0.02f;
     if (input.CurrentGamePadState.Buttons.LeftShoulder == ButtonState.Pressed)
         ScreenManager.Camera.Zoom -= 0.02f;
     ScreenManager.Camera.MoveCamera(input.CurrentGamePadState.ThumbSticks.Right/2f);
     if (input.CurrentGamePadState.Buttons.RightStick == ButtonState.Pressed)
         ScreenManager.Camera.ResetCamera();
 }
コード例 #10
0
ファイル: GameScreen.cs プロジェクト: guozanhua/KinectRagdoll
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(InputHelper input)
 {
     if (input.GamePadWasConnected[0])
     {
         HandleGamePadInput(input);
     }
     else
     {
         HandleKeyboardInput(input);
     }
 }