/// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null) throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[playerIndex];

            if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new SimpleScreen(ScreenType.Pause), ControllingPlayer);
            }
            else
            {
                if (!level.IsLevelUp)
                    level.HandleInput(input, playerIndex);
            }
        }
        /// <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)) Position.X += Speed;
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.D)) Position.X -= Speed;
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.S)) Position.Y -= Speed;
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.W)) Position.Y += Speed;

                //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 CZ
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.C)) Scale += 0.001f;
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Z)) Scale -= 0.001f;
            }

            /*
            Vector2 mousePos = new Vector2(input.CurrentMouseState[0].X, input.CurrentMouseState[0].Y);
            if (mousePos.X < ScrollBar.X) Position.X -= Speed;
            else if (mousePos.X > viewportSize.X - ScrollBar.X) Position.X += Speed;

            if (mousePos.Y < ScrollBar.Y) Position.Y -= Speed;
            else if (mousePos.Y > viewportSize.Y - ScrollBar.Y) Position.Y += Speed;
            */

            // Clamp
            //Position.X = MathHelper.Clamp(Position.X, viewportSize.X / 2 / Scale,
            //    (ScrollWidth - viewportSize.X / 2 / Scale));
            //Position.Y = MathHelper.Clamp(Position.Y, viewportSize.Y / 2 / Scale,
            //    (ScrollHeight - viewportSize.Y / 2 / Scale));
        }
        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();
            }
        }
        /// <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 CX
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.C)) Scale += 0.001f;
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.X)) Scale -= 0.001f;
            }

            Vector2 mousePos = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y) / PhoneScale;
            if (mousePos.X < ScrollBar.X) Position.X -= Speed;
            else if (mousePos.X > BaseScreenSize.X / PhoneScale - ScrollBar.X) Position.X += Speed;

            if (mousePos.Y < ScrollBar.Y) Position.Y -= Speed;
            else if (mousePos.Y > BaseScreenSize.Y / PhoneScale - ScrollBar.Y) Position.Y += Speed;

            // Clamp
            Position.X = MathHelper.Clamp(Position.X, BaseScreenSize.X / 2 / Scale,
                (ScrollArea.X - BaseScreenSize.X / 2 / Scale));
            Position.Y = MathHelper.Clamp(Position.Y, BaseScreenSize.Y / 2 / Scale,
                (ScrollArea.Y - BaseScreenSize.Y / 2 / Scale));
        }
        public override void HandleInput(InputState input)
        {
            if (input.IsLeftClicked())
            {
                LoadingScreen.Load(ScreenManager, false, PlayerIndex.One,
                    new GameplayScreen(), new PauseMenuScreen());

                ExitScreen();
            }
        }
        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;
            }

            #if WINDOWS
            MousePos = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y);
            #endif
            #if WINDOWS_PHONE
            MousePos = Vector2.Zero;

            if (input.TouchState.Count > 0) MousePos = input.TouchState[0].Position;
            #endif
            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,
                (ScrollArea.X - BaseScreenSize.X / 2 / Scale));
            Position.Y = MathHelper.Clamp(Position.Y, BaseScreenSize.Y / 2 / Scale,
                (ScrollArea.Y - BaseScreenSize.Y / 2 / Scale));

            MousePos = (Position - BaseScreenSize / 2 / Scale) + MousePos / Scale;
        }
        /// <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)) Position.X += Speed;
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.D)) Position.X -= Speed;
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.S)) Position.Y -= Speed;
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.W)) Position.Y += Speed;

                //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 CZ
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.C)) Scale += 0.001f;
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Z)) Scale -= 0.001f;
            }
        }
        public override void HandleInput(InputState input)
        {
            MouseState mouseState = input.CurrentMouseState[0];
            MouseState prevMouseState = input.LastMouseState[0];

            if (mouseState.LeftButton == ButtonState.Pressed && prevMouseState.LeftButton == ButtonState.Released
                && gameContent.viewport.TitleSafeArea.Contains(new Point(mouseState.X, mouseState.Y))
                && time > MaxWaitTime)
            {
                if (type == ScreenType.Intro)
                    LoadingScreen.Load(ScreenManager, false, PlayerIndex.One, new GameplayScreen());
                else if (type == ScreenType.Inter || type == ScreenType.Pause)
                    this.ExitScreen();
                else if (type == ScreenType.GameOver)
                    LoadingScreen.Load(ScreenManager, false, null, new SimpleScreen(ScreenType.Intro));
            }

            base.HandleInput(input);
        }
        public override void HandleInput(InputState input)
        {
            MouseState mouseState = input.CurrentMouseState[0];
            Point pos = new Point(mouseState.X, mouseState.Y);

            if (mouseState.LeftButton == ButtonState.Pressed
                && input.LastMouseState[0].LeftButton == ButtonState.Released
                && ScreenManager.GraphicsDevice.Viewport.TitleSafeArea.Contains(pos)
                && time > 0.5f)
            {
                if (type == "gameOver")
                    LoadingScreen.Load(ScreenManager, false, null, new IntroScreen("intro"));

                else if (type == "intro")
                    ScreenManager.AddScreen(new IntroScreen("info"), PlayerIndex.One);
                else
                    ScreenManager.AddScreen(new GameplayScreen(), PlayerIndex.One);

                ScreenManager.RemoveScreen(this);
            }
        }
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void HandleInput(InputState input, PlayerIndex? controllingPlayer)
        {
            if (ManualCamera)
            {
                //translation controls, left stick xbox or WASD keyboard
                if (Keyboard.GetState().IsKeyDown(Keys.A)
                    || GamePad.GetState(PlayerIndex.One).DPad.Left == ButtonState.Pressed
                    || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X < 0) Position.X += Speed;
                if (Keyboard.GetState().IsKeyDown(Keys.D)
                    || GamePad.GetState(PlayerIndex.One).DPad.Right == ButtonState.Pressed
                    || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X > 0) Position.X -= Speed;
                if (Keyboard.GetState().IsKeyDown(Keys.S)
                    || GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed
                    || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y < 0) Position.Y -= Speed;
                if (Keyboard.GetState().IsKeyDown(Keys.W)
                    || GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed
                    || GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y > 0) Position.Y += Speed;

                //rotation controls, right stick or QE keyboard
                if (Keyboard.GetState().IsKeyDown(Keys.Q)
                    || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X < 0) Rotation += 0.01f;
                if (Keyboard.GetState().IsKeyDown(Keys.E)
                    || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X > 0) Rotation -= 0.01f;

                //zoom/scale controls, left/right triggers or CZ keyboard
                if (Keyboard.GetState().IsKeyDown(Keys.C)
                    || GamePad.GetState(PlayerIndex.One).Triggers.Right > 0) Scale += 0.001f;
                if (Keyboard.GetState().IsKeyDown(Keys.Z)
                    || GamePad.GetState(PlayerIndex.One).Triggers.Left > 0) Scale -= 0.001f;
            }

            mousePos = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y) / PhoneScale;

            #if WINDOWS_PHONE
            //if (!input.IsMouseLeftButtonClick()) mousePos = viewportSize / 2 / PhoneScale;
            #endif
        }
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null) throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            prevMouseState = mouseState; mouseState = Mouse.GetState();

            if (prevMouseState.LeftButton == ButtonState.Released &&
                mouseState.LeftButton == ButtonState.Pressed && level.IsSolved)
                LoadNextLevel();
            else
                level.HandleInput(input);
        }
        /// <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)
 {
     prevMouseState = input.LastMouseState;
     mouseState = input.CurrentMouseState;
     mousePos = new Point(mouseState.X, mouseState.Y);
 }
 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;
 }
Beispiel #16
0
 public void HandleInput(InputState input, int playerIndex)
 {
 }
        public void HandleInput(InputState input, int playerIndex)
        {
            mousePos = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y) / Camera2D.PhoneScale;

            camera.HandleInput(input, (PlayerIndex)playerIndex);

            mousePos = ((camera.Position / Camera2D.PhoneScale - gameContent.PlayArea / 2 / camera.Scale)
                + mousePos / camera.Scale) ;

            mousePos /= gameContent.b2Scale;

            if (editMode) HandleEquipment(input);

            if (!(isLAB && editMode)) HandleAtom(input);

            if (mouseJoint != null) mouseJoint.SetTarget(mousePos);
        }
Beispiel #18
0
 public void HandleInput(InputState input, int playerIndex)
 {
     if (input.IsMouseLeftButtonClick()) IsLevelUp = true;
     if (input.IsMouseRightButtonClick()) ReloadLevel = true;
 }
        /// <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;
            }

            // 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);
            }
        }
 /// <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)
 {
 }
        void HandleEquipment(InputState input)
        {
            Vector2 m = mousePos * gameContent.scale;
            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.IsLeftClicked() && 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.IsRightClicked()
                || input.CurrentMouseState[0].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.IsRightClicked())
                {
                    selectedEq = null;

                    mouseOverEq.Remove(); equipments.Remove(mouseOverEq);
                }
            }

            // Remove
            if (!equipmentAdded && (input.IsLeftClicked() || input.IsRightClicked()) && 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.IsLeftClicked() && isLAB && !editMode && !isMenuEntrySelected)
                atoms.Add(new Atom((Symbol)(gameContent.random.Next(gameContent.symbolCount - 1) + 1),
                        mousePos * gameContent.scale, gameContent, world));

            if (input.IsLeftClicked())
            {
                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[0].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.IsRightClicked())
            {
                if (mouseOverAtom != null)
                {
                    if (mouseOverAtom.bondedAtoms.Count > 0)
                    {
                        Cue cue = gameContent.soundBank.GetCue("detach"); cue.Play();
                        mouseOverAtom.DestroyBonds();
                    }
                    else if (isLAB && !editMode && mouseOverAtom.bondedAtoms.Count == 0)
                    {
                        mouseOverAtom.Remove(); atoms.Remove(mouseOverAtom);
                    }
                }
            }
        }
        public void HandleInput(InputState input, int playerIndex)
        {
            mousePos = new Vector2(input.CurrentMouseState[0].X, input.CurrentMouseState[0].Y);

            camera.HandleInput(input, (PlayerIndex)playerIndex);
            if (isLAB)
            {
                if (targetScale != camera.Scale)
                {
                    if (scale > targetScale) scale = Math.Max(scale - 0.01f, targetScale);
                    else if (scale < targetScale) scale = Math.Min(scale + 0.01f, targetScale);

                    camera.Scale = scale;
                }
            }

            mousePos = ((camera.Position - gameContent.viewportSize / 2 / camera.Scale)
                + mousePos / camera.Scale) / gameContent.scale;

            if (editMode) HandleEquipment(input);

            if (!(isLAB && editMode)) HandleAtom(input);

            if (mouseJoint != null) mouseJoint.SetTarget(mousePos);
        }
        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);
            }
        }
        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;
            }
        }
        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;
        }
        /// <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;
            }

            bool mouseOver = false;
            Point mousePos = new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y);
            for (int i = 0; i < menuEntries.Count; i++)
            {
                if (menuEntries[i].BoundingRectangle.Contains(mousePos))
                {
                    mouseOver = 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)
                || (mouseOver && input.IsLeftClicked()))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
        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)
        {
            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);
            }
        }
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (time < maxWaitTime) return;

            prevMouseState = mouseState; mouseState = Mouse.GetState();

            // 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;
            }

            // 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 = PlayerIndex.One;

            if (prevMouseState.LeftButton == ButtonState.Released && mouseState.LeftButton == ButtonState.Pressed
                && ScreenManager.Game.GraphicsDevice.Viewport.TitleSafeArea.Contains
                (new Point(mouseState.X, mouseState.Y)))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }