Exemplo n.º 1
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or canceling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (input.CurrentKeyboardState.IsKeyDown(Key.Up) && input.LastKeyboardState.IsKeyDown(Key.Up) == false)
            {
                _selectedEntry--;

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

            // Move to the next menu entry?
            if (input.CurrentKeyboardState.IsKeyDown(Key.Down) && input.LastKeyboardState.IsKeyDown(Key.Down) == false)
            {
                _selectedEntry++;

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

            // Accept or cancel the menu?
            if (input.CurrentKeyboardState.IsKeyDown(Key.Enter) && input.LastKeyboardState.IsKeyDown(Key.Enter) == false)
            {
                OnSelectEntry(_selectedEntry);
            }
        }
Exemplo n.º 2
0
        public override void HandleInput(InputState input)
        {
            const float forceAmount = 60;
            Vector2 force = Vector2.Zero;
            force.Y = -force.Y;

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

            _rectangle.ApplyForce(force);

            const float torqueAmount = 40;
            float torque = 0;

            if (input.IsKeyPressed(Key.Left))
            {
                torque += torqueAmount;
            }
            if (input.IsKeyPressed(Key.Right))
            {
                torque -= torqueAmount;
            }

            _rectangle.ApplyTorque(torque);

            base.HandleInput(input);
        }
Exemplo n.º 3
0
        private void HandleKeyboardInput(InputState input)
        {
            const float forceAmount = 100;
            Vector2 force = Vector2.Zero;
            force.Y = -force.Y;

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

            _rectangles.ApplyForce(force);

            const float torqueAmount = 200;
            float torque = 0;

            if (input.CurrentKeyboardState.IsKeyDown(Key.Left))
            {
                torque += torqueAmount;
            }
            if (input.CurrentKeyboardState.IsKeyDown(Key.Right))
            {
                torque -= torqueAmount;
            }

            _rectangles.ApplyTorque(torque);
        }
Exemplo n.º 4
0
        /// <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(InputState input)
        {
            //Keyboard Input
            if (!input.LastKeyboardState.IsKeyDown(Key.F1) && input.CurrentKeyboardState.IsKeyDown(Key.F1))
            {
                DebugViewEnabled = !DebugViewEnabled;

                if (DebugViewEnabled == false)
                    TxtDebug.Text = "";
            }

            if (!input.LastKeyboardState.IsKeyDown(Key.Escape) && input.CurrentKeyboardState.IsKeyDown(Key.Escape))
            {
                ScreenManager.GoToMainMenu();
            }

            //Mouse
            Point p = Transform.Inverse.Transform(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y));
            Vector2 position = new Vector2((float)p.X, (float)p.Y);
            if (input.CurrentMouseState.IsLeftButtonDown == false && input.LastMouseState.IsLeftButtonDown)
            {
                MouseUp();
            }
            else if (input.CurrentMouseState.IsLeftButtonDown && input.LastMouseState.IsLeftButtonDown == false)
            {
                MouseDown(position);
            }

            MouseMove(position);

            //DebugView
            if (DebugView != null)
            {
                if (DebugViewEnabled)
                    DebugView.AppendFlags(DebugViewFlags.DebugPanel);
                else
                    DebugView.RemoveFlags(DebugViewFlags.DebugPanel);
            }
        }
Exemplo n.º 5
0
        public override void HandleInput(InputState input)
        {
            HandleKeyboardInput(input);

            base.HandleInput(input);
        }