public override void HandleInput(InputState input) { if (firstRun) { ScreenManager.AddScreen(new PauseScreen(GetTitle(), GetDetails(), this)); firstRun = false; } if (input.PauseGame) { ScreenManager.AddScreen(new PauseScreen(GetTitle(), GetDetails(), this)); } if (input.CurrentGamePadState.IsConnected) { HandleGamePadInput(input); } else { HandleKeyboardInput(input); } base.HandleInput(input); }
public override void HandleInput(InputState input) { Random rand = new Random(); if (firstRun) { ScreenManager.AddScreen(new PauseScreen(GetTitle(), GetDetails(), this)); firstRun = false; } if (input.PauseGame) { ScreenManager.AddScreen(new PauseScreen(GetTitle(), GetDetails(), this)); } if (input.CurrentMouseState.RightButton == ButtonState.Pressed && broke && count > 10) { broke = false; weldJoint = new WeldJoint(bodyA, bodyB, new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y)); weldJoint.Breakpoint = 5.0f; weldJoint.Broke += weldJoint_Broke; PhysicsSimulator.Add(weldJoint); count = 0; } else if (input.CurrentMouseState.MiddleButton == ButtonState.Pressed && input.LastMouseState.MiddleButton == ButtonState.Released && count > 10) { table.Add(new Table(new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y), rand.Next(100, 300), rand.Next(20, 50))); table[table.Count - 1].Load(PhysicsSimulator, ScreenManager.GraphicsDevice); count = 0; } count++; base.HandleInput(input); }
private void HandleKeyboardInput(InputState input) { const float forceAmount = 1000; Vector2 force = Vector2.Zero; force.Y = -force.Y; 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); } _agent.ApplyForce(force); const float torqueAmount = 14000; float torque = 0; if (input.CurrentKeyboardState.IsKeyDown(Keys.Left)) { torque -= torqueAmount; } if (input.CurrentKeyboardState.IsKeyDown(Keys.Right)) { torque += torqueAmount; } _agent.ApplyTorque(torque); }
private void HandleGamePadInput(InputState input) { Vector2 force = 1000 * input.CurrentGamePadState.ThumbSticks.Left; force.Y = -force.Y; _agent.ApplyForce(force); float rotation = -14000 * input.CurrentGamePadState.Triggers.Left; _agent.ApplyTorque(rotation); rotation = 14000 * input.CurrentGamePadState.Triggers.Right; _agent.ApplyTorque(rotation); }
/// <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.MenuUp) { _selectedEntry--; if (_selectedEntry < 0) _selectedEntry = _menuEntries.Count - 1; } // Move to the next menu entry? if (input.MenuDown) { _selectedEntry++; if (_selectedEntry >= _menuEntries.Count) _selectedEntry = 0; } // Accept or cancel the menu? if (input.MenuSelect) { OnSelectEntry(_selectedEntry); } }
private void HandleMouseInput(InputState input) { Vector2 point = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y); if (input.LastMouseState.LeftButton == ButtonState.Released && input.CurrentMouseState.LeftButton == ButtonState.Pressed) { //create mouse spring _pickedGeom = PhysicsSimulator.Collide(point); if (_pickedGeom != null) { _mousePickSpring = SpringFactory.Instance.CreateFixedLinearSpring(PhysicsSimulator, _pickedGeom.Body, _pickedGeom.Body. GetLocalPosition(point), point, 100, 50); } } else if (input.LastMouseState.LeftButton == ButtonState.Pressed && input.CurrentMouseState.LeftButton == ButtonState.Released) { //destroy mouse spring if (_mousePickSpring != null && _mousePickSpring.IsDisposed == false) { _mousePickSpring.Dispose(); _mousePickSpring = null; } } //move anchor point if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && _mousePickSpring != null) { _mousePickSpring.WorldAttachPoint = point; } }
/// <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) { //Xbox if (input.LastGamePadState.Buttons.Y != ButtonState.Pressed && input.CurrentGamePadState.Buttons.Y == ButtonState.Pressed) { _debugViewEnabled = !_debugViewEnabled; _physicsSimulator.EnableDiagnostics = _debugViewEnabled; } //Windows if (!input.LastKeyboardState.IsKeyDown(Keys.F1) && input.CurrentKeyboardState.IsKeyDown(Keys.F1)) { _debugViewEnabled = !_debugViewEnabled; _physicsSimulator.EnableDiagnostics = _debugViewEnabled; } #if !XBOX HandleMouseInput(input); #endif }
public override void HandleInput(InputState input) { if (input.CurrentKeyboardState.IsKeyDown(Keys.Escape)) ScreenManager.Game.Exit(); base.HandleInput(input); }