public override void HandleInput(InputState input) { PlayerIndex playerIndex; if (input.IsMouseLeftButtonClick() || input.IsMenuSelect(ControllingPlayer, out playerIndex)) { LoadingScreen.Load(ScreenManager, false, PlayerIndex.One, new GameplayScreen(), new PauseMenuScreen()); ExitScreen(); } }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void HandleInput(InputState input, int playerIndex) { if (ManualCamera) { //translation controls WASD if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.A)) MoveCamera(new Vector2(-1, 0)); if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.D)) MoveCamera(new Vector2(1, 0)); if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.S)) MoveCamera(new Vector2(0, 1)); if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.W)) MoveCamera(new Vector2(0, -1)); //rotation controls QE if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Q)) Rotation += 0.01f; if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.E)) Rotation -= 0.01f; //zoom/scale controls ZX if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Z)) Scale += 0.001f; if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.X)) Scale -= 0.001f; } MousePos = input.MousePos(); MousePos /= ResolutionScale; #if WINDOWS_PHONE if(input.IsMouseLeftButtonClick()) #endif { if (MousePos.X < ScrollBar.X) Position.X -= Speed; else if (MousePos.X > BaseScreenSize.X - ScrollBar.X) Position.X += Speed; if (MousePos.Y < ScrollBar.Y) Position.Y -= Speed; else if (MousePos.Y > BaseScreenSize.Y - ScrollBar.Y) Position.Y += Speed; } // Clamp Position.X = MathHelper.Clamp(Position.X, BaseScreenSize.X / 2 / Scale * ResolutionScale, (ScrollArea.X - BaseScreenSize.X / 2 / Scale) * ResolutionScale); Position.Y = MathHelper.Clamp(Position.Y, BaseScreenSize.Y / 2 / Scale * ResolutionScale, (ScrollArea.Y - BaseScreenSize.Y / 2 / Scale) * ResolutionScale); MousePos = (Position / ResolutionScale - BaseScreenSize / 2 / Scale) + MousePos / Scale; }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputState input) { camera.HandleInput(input, ControllingPlayer == null ? (int)PlayerIndex.One : (int)ControllingPlayer); // 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; } Point mousePos = new Point((int)camera.MousePos.X, (int)camera.MousePos.Y); for (int i = 0; i < menuEntries.Count; i++) { if (menuEntries[i].GetMenuEntryHitBounds.Contains(mousePos)) { selectedEntry = i; if (input.IsMouseLeftButtonClick()) { OnSelectEntry(selectedEntry, PlayerIndex.One); } } } // 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); } }
public override void HandleInput(InputState input) { if (ScreenState != ScreenState.Active) return; 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) || input.IsMouseLeftButtonClick()) { // Raise the accepted event, then exit the screen. if (Accepted != null) Accepted(this, new PlayerIndexEventArgs(playerIndex)); ExitScreen(); } else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) { // Raise the cancelled event, then exit the screen. if (Cancelled != null) Cancelled(this, new PlayerIndexEventArgs(playerIndex)); ExitScreen(); } }
public void HandleInput(InputState input, int playerIndex) { Vector2 mousePos = Vector2.Zero; #if WINDOWS mousePos = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y); #endif #if WINDOWS_PHONE if (input.TouchState.Count > 0) mousePos = input.TouchState[0].Position; #endif mousePos /= Camera2D.ResolutionScale; Point mousePoint = new Point((int)mousePos.X, (int)mousePos.Y); if (input.IsMouseLeftButtonClick()) { for (int i = 0; i < blocks.Count; i++) { if (blocks[i].Bounds.Contains(mousePoint)) { // start a new line if (!blocks[i].IsColor) { lines.Add(new List<Block>()); lastLineIndex = lines.Count - 1; lines[lastLineIndex].Add(blocks[i]); gameContent.blockSelect.Play(); break; } else { // break the line for (int j = 0; j < lines.Count; j++) { if (lines[j].Contains(blocks[i])) { int lastIndex = lines[j].LastIndexOf(blocks[i]); lines[j].RemoveRange(lastIndex + 1, lines[j].Count - lastIndex - 1); lastLineIndex = j; gameContent.blockSelect.Play(); break; } } } } } } #if WINDOWS else if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && lastLineIndex != -1) #endif #if WINDOWS_PHONE //else if (TouchPanel.IsGestureAvailable && TouchPanel.ReadGesture().GestureType == GestureType.FreeDrag // && lastLineIndex != -1) else if (input.TouchState.Count > 0 && input.TouchState[0].State == TouchLocationState.Moved && lastLineIndex != -1) #endif { for (int i = 0; i < blocks.Count; i++) { if (blocks[i] != CurrentBlock && blocks[i].Bounds.Contains(mousePoint)) { // adding non colored blocks if (!blocks[i].IsColor) { if (IsCorresponding(blocks[i], CurrentBlock) && lines[lastLineIndex][0].Goal == blocks[i].Goal) { lines[lastLineIndex].Add(blocks[i]); gameContent.blockSelect.Play(); break; } //else lastLineIndex = -1; } else { if (lines[lastLineIndex].Contains(blocks[i])) { // remove when drag back if (blocks[i] == lines[lastLineIndex][lines[lastLineIndex].Count - 2]) { int blockLastIndex = lines[lastLineIndex].LastIndexOf(CurrentBlock); lines[lastLineIndex].RemoveAt(blockLastIndex); gameContent.blockSelect.Play(); } else { // for cross blocks int blockIndex = lines[lastLineIndex].IndexOf(blocks[i]); int blockLastIndex = lines[lastLineIndex].LastIndexOf(blocks[i]); if ((blockIndex == 0 ? true : CurrentBlock != lines[lastLineIndex][blockIndex - 1]) && CurrentBlock != lines[lastLineIndex][blockIndex + 1] && (blockLastIndex == 0 ? true : CurrentBlock != lines[lastLineIndex][blockLastIndex - 1]) && CurrentBlock != lines[lastLineIndex][blockLastIndex + 1]) { if (IsCorresponding(blocks[i], CurrentBlock) && lines[lastLineIndex][0].Goal == blocks[i].Goal) { lines[lastLineIndex].Add(blocks[i]); gameContent.blockSelect.Play(); break; } //else lastLineIndex = -1; } } } } } } /* add block both sides, line merging */ } #if WINDOWS if (input.LastMouseState.LeftButton == ButtonState.Pressed && input.CurrentMouseState.LeftButton == ButtonState.Released) #endif #if WINDOWS_PHONE if (input.TouchState.Count > 0 && input.TouchState[0].State == TouchLocationState.Released) #endif { // Remove Single block lines if (lastLineIndex != -1 && lines[lastLineIndex].Count == 1) lines.RemoveAt(lastLineIndex); lastLineIndex = -1; } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputState 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; } Vector2 mousePos = Vector2.Zero; #if WINDOWS mousePos = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y) ; #endif #if WINDOWS_PHONE if (input.TouchState.Count > 0) mousePos = input.TouchState[0].Position; #endif mousePos /= Camera2D.PhoneScale; Point mousePoint = new Point((int)mousePos.X, (int)mousePos.Y); for (int i = 0; i < menuEntries.Count; i++) { if (menuEntries[i].GetMenuEntryHitBounds.Contains(mousePoint)) { selectedEntry = i; if (input.IsMouseLeftButtonClick()) { OnSelectEntry(selectedEntry, PlayerIndex.One); } } } // 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); } }
public void HandleInput(InputState input, int playerIndex) { Vector2 mousePosition = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y) / Camera2D.ResolutionScale; Point mouseP = new Point((int)mousePosition.X, (int)mousePosition.Y); mouseOverArmy = null; for (int i = 0; i < armies.Count; i++) { if (armies[i].MouseBounds.Contains(mouseP) &&armies[i].IsAlive && selectedArmy == null && armies[i].Shape == Shape.square #if WINDOWS_PHONE && input.TouchState.Count > 0 && input.TouchState[0].State == TouchLocationState.Pressed #endif ) { mouseOverArmy = armies[i]; break; } } #if WINDOWS if (input.CurrentMouseState.LeftButton == ButtonState.Pressed) #endif #if WINDOWS_PHONE if(input.TouchState.Count > 0 && (input.TouchState[0].State == TouchLocationState.Pressed || input.TouchState[0].State == TouchLocationState.Moved)) #endif { if (input.IsMouseLeftButtonClick() && mouseOverArmy != null) { selectedArmy = mouseOverArmy; mouseOverArmy = null; selectedArmy.Reset(); } if (selectedArmy != null) selectedArmy.AddPosition(mousePosition); } #if WINDOWS if (input.CurrentMouseState.LeftButton == ButtonState.Released #endif #if WINDOWS_PHONE if(input.TouchState.Count > 0 && input.TouchState[0].State == TouchLocationState.Released #endif || (selectedArmy != null && !selectedArmy.IsAlive)) selectedArmy = null; }
public void HandleInput(InputState input, int playerIndex) { Vector2 mousePos = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y); Point mouseP = new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y); mouseOverSoldier = null; for (int i = 0; i < soldiers.Count; i++) { if (selectedSoldier == null && soldiers[i].BoundingRect.Contains(mouseP) && input.LastMouseState.LeftButton == ButtonState.Released) mouseOverSoldier = soldiers[i]; } if (input.IsMouseLeftButtonClick()) { selectedSoldier = null; if (mouseOverSoldier != null) selectedSoldier = mouseOverSoldier; } if (input.LastMouseState.LeftButton == ButtonState.Pressed && input.CurrentMouseState.LeftButton == ButtonState.Pressed) { if (selectedSoldier != null) selectedSoldier.ShowMove(mousePos); } if (input.LastMouseState.LeftButton == ButtonState.Pressed && input.CurrentMouseState.LeftButton == ButtonState.Released) { if (selectedSoldier != null && !selectedSoldier.BoundingRect.Contains(mouseP)) selectedSoldier.Move(mousePos); } }
void HandleEquipment(InputState input) { Vector2 m = mousePos * gameContent.b2Scale; Point mp = new Point((int)m.X, (int)m.Y); Equipment mouseOverEq = null; if (mouseEq == null) foreach (Equipment e in equipments) { e.isMouseOver = false; if (mouseOverEq == null && !isMenuEntrySelected && (e.MoveButtonBound.Contains(mp) || e.RotationButtonBound.Contains(mp))) { mouseOverEq = e; e.isMouseOver = true; } } if (input.IsMouseLeftButtonClick() && mouseOverEq != null) { if (mouseOverEq.MoveButtonBound.Contains(mp) || mouseOverEq.RotationButtonBound.Contains(mp)) { MouseJointDef mjd = new MouseJointDef(); mjd.maxForce = 500; //mjd.frequencyHz = 10f; mjd.dampingRatio = .1f; mjd.target = mousePos; mjd.bodyA = mouseGroundBody; mjd.bodyB = mouseOverEq.body; mouseJoint = (MouseJoint)world.CreateJoint(mjd); mouseEq = mouseOverEq; mouseEq.body.SetAngularDamping(20000); if (mouseOverEq.RotationButtonBound.Contains(mp)) { RevoluteJointDef rjd = new RevoluteJointDef(); rjd.bodyA = mouseGroundBody; rjd.bodyB = mouseOverEq.body; rjd.localAnchorA = mouseOverEq.body.Position; rjd.localAnchorB = Vector2.Zero; pin = world.CreateJoint(rjd); mouseEq.body.SetAngularDamping(20); } if (selectedEq != mouseOverEq) { if (selectedEq != null) { selectedEq.isSelected = false; selectedEq.SetMode(editMode, false); selectedEq = null; } selectedEq = mouseOverEq; selectedEq.isClamped = false; selectedEq.isSelected = true; } mouseEq.SetMode(editMode, true); } } else if (mouseOverEq != null && input.IsMouseRightButtonClick() || input.CurrentMouseState.LeftButton == ButtonState.Released) { if (mouseJoint != null && mouseEq != null) { world.DestroyJoint(mouseJoint); mouseJoint = null; if (pin != null) { world.DestroyJoint(pin); pin = null; } mouseEq.SetMode(editMode, false); mouseEq = null; } if (mouseOverEq != null && input.IsMouseRightButtonClick()) { selectedEq = null; mouseOverEq.Remove(); equipments.Remove(mouseOverEq); } } // Remove if (!equipmentAdded && (input.IsMouseLeftButtonClick() || input.IsMouseRightButtonClick()) && mouseOverEq == null && mouseEq == null && selectedEq != null) { selectedEq.isSelected = false; selectedEq.SetMode(editMode, false); selectedEq = null; } equipmentAdded = false; }
void HandleAtom(InputState input) { Atom mouseOverAtom = null; foreach (Atom a in atoms) { if (mouseAtom == null && !isMenuEntrySelected && a.eye < EyeState.Disappear && a.fixture.TestPoint(mousePos)) mouseOverAtom = a; } // click to add atoms if (mouseOverAtom == null && input.IsMouseLeftButtonClick() && isLAB && !editMode && !isMenuEntrySelected) atoms.Add(new Atom((Symbol)(gameContent.random.Next(gameContent.symbolCount - 1) + 1), mousePos * gameContent.b2Scale, gameContent, world)); if (input.IsMouseLeftButtonClick()) { if (mouseOverAtom != null) { MouseJointDef mjd = new MouseJointDef(); mjd.maxForce = 500; //mjd.frequencyHz = 10; //mjd.dampingRatio = .1f; mjd.target = mouseOverAtom.body.Position; mjd.bodyA = mouseGroundBody; mjd.bodyB = mouseOverAtom.body; mouseJoint = (MouseJoint)world.CreateJoint(mjd); mouseAtom = mouseOverAtom; mouseAtom.SetMode(editMode, true); } } else if (mouseJoint != null && mouseAtom != null && (mouseAtom.eye == EyeState.Disappear || input.CurrentMouseState.LeftButton == ButtonState.Released)) { if (mouseAtom.eye != EyeState.Disappear) // Disappear has priority over LeftButton Released { world.DestroyJoint(mouseJoint); mouseAtom.SetMode(editMode, false); mouseAtom.CreateBond(); } mouseJoint = null; mouseAtom = null; } if (input.IsMouseRightButtonClick()) { if (mouseOverAtom != null) { if (mouseOverAtom.bondedAtoms.Count > 0) { gameContent.detach[gameContent.random.Next(gameContent.detach.Length)].Play(); mouseOverAtom.DestroyBonds(); } else if (isLAB && !editMode && mouseOverAtom.bondedAtoms.Count == 0) { mouseOverAtom.Remove(); atoms.Remove(mouseOverAtom); } } } }
public void HandleInput(InputState input, int playerIndex) { if (input.IsMouseLeftButtonClick()) IsLevelUp = true; if (input.IsMouseRightButtonClick()) ReloadLevel = true; }
public void HandleInput(InputState input, int playerIndex) { player.direction = Vector2.Zero; if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.W) || input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Up)) player.direction.Y = -1; else if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.S) || input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Down)) player.direction.Y = 1; if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.A) || input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Left)) player.direction.X = -1; else if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.D) || input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Right)) player.direction.X = 1; Vector2 mousePos = input.MousePos(); mousePos /= Camera2D.ResolutionScale; mousePos += camera.Position / Camera2D.ResolutionScale - (Camera2D.BaseScreenSize / 2.0f); Vector2 playerPos = player.body.Position * gameContent.b2Scale; if (input.IsMouseLeftButtonClick()) if (Vector2.Distance(mousePos, playerPos) < Tile.Width / 2.0f) isPlayerSelected = true; #if WINDOWS_PHONE if (input.TouchState.Count > 0 && input.TouchState[0].State == TouchLocationState.Released) #else if(input.CurrentMouseState.LeftButton == ButtonState.Released) #endif isPlayerSelected = false; #if WINDOWS_PHONE if (input.TouchState.Count > 0 && input.TouchState[0].State == TouchLocationState.Moved #else if (input.CurrentMouseState.LeftButton == ButtonState.Pressed #endif && isPlayerSelected && Vector2.Distance(mousePos, playerPos) > (Tile.Width / 2.0f + 10.0f)) { float theta = (float)Math.Atan2(mousePos.Y - playerPos.Y, mousePos.X - playerPos.X); //player.direction.X = (float)Math.Cos(theta); //player.direction.Y = (float)Math.Sin(theta); if (Math.Abs(theta) <= Math.PI / 4.0f * 1.5f) player.direction.X = 1; else if (Math.Abs(theta) >= Math.PI / 4.0f * 2.5f) player.direction.X = -1; if (Math.PI / 4.0f * .5f <= Math.Abs(theta) && Math.Abs(theta) <= Math.PI / 4.0f * 3.5f) { if (theta > 0) player.direction.Y = 1; else player.direction.Y = -1; } } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputState 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; } isMouseOver = false; Vector2 mousePos = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y) / Camera2D.PhoneScale; camera.HandleInput(input, ControllingPlayer); mousePos = ((camera.Position / Camera2D.PhoneScale - ScreenManager.GameContent.PlayArea / 2 / camera.Scale) + mousePos / camera.Scale); for (int i = 0; i < menuEntries.Count; i++) { Point m = new Point((int)mousePos.X, (int)mousePos.Y); if (menuEntries[i].BoundingRectangle.Contains(m)) { isMouseOver = true; selectedEntry = i; } } // 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) if (isMouseOver && (input.IsMenuSelect(ControllingPlayer, out playerIndex) || input.IsMouseLeftButtonClick())) { OnSelectEntry(selectedEntry, PlayerIndex.One); } else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); } }