Example #1
0
        private void HandleInput()
        {
            accelState = Accelerometer.GetState();
            touchState = TouchPanel.GetState();
            bool          buttonTouched = false;
            KeyboardState keyboardState = Keyboard.GetState();
            GamePadState  gamepadState  = GamePad.GetState(PlayerIndex.One);

            // Exit the game when back is pressed.
            if (gamepadState.Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }

            //interpert touch screen presses
            foreach (TouchLocation location in touchState)
            {
                switch (location.State)
                {
                case TouchLocationState.Pressed:
                    buttonTouched = true;
                    break;

                case TouchLocationState.Moved:
                    break;

                case TouchLocationState.Released:
                    break;
                }
            }


            bool continuePressed =
                gamepadState.IsButtonDown(ContinueButton) ||
                keyboardState.IsKeyDown(Keys.Space) ||
                buttonTouched;

            // Perform the appropriate action to advance the game and
            // to get the player back to playing.
            if (!wasContinuePressed && continuePressed)
            {
                if (!level.Player.IsAlive)
                {
                    level.StartNewLife();
                }
                else if (level.TimeRemaining == TimeSpan.Zero)
                {
                    if (level.ReachedExit)
                    {
                        LoadNextLevel();
                    }
                    else
                    {
                        ReloadCurrentLevel();
                    }
                }
            }

            wasContinuePressed = continuePressed;
        }
Example #2
0
        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;

            // get all of our input states
            keyboardState      = Keyboard.GetState();
            gamePadState_1     = GamePad.GetState(PlayerIndex.One);
            gamePadState_2     = GamePad.GetState(PlayerIndex.Two);
            gamePadStates[0]   = gamePadState_1;
            gamePadStates[1]   = gamePadState_2;
            touchState         = TouchPanel.GetState();
            accelerometerState = Accelerometer.GetState();

            // Exit the game when back is pressed.
            //if (gamePadState_1.Buttons.Back == ButtonState.Pressed)
            //    Exit();

            if (input.IsPauseGame(null))
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
            else
            {
                foreach (Player player in PlatformerGame.Players)
                {
                    bool continuePressed =
                        keyboardState.IsKeyDown(Keys.Space) ||
                        gamePadStates[PlatformerGame.Players.IndexOf(player)].IsButtonDown(Buttons.A) ||
                        touchState.AnyTouch();

                    if (!player.IsAlive)
                    {
                        level.StartNewLife(player);
                    }
                    if (level.ReachedExit)
                    {
                        LoadNextLevel();
                    }
                }
                //check if both player is in the "no-man lands"
                if (players[0].Position.X == -999.9f && players[1].Position.X == -999.9f)
                {
                    //players[attacker_id].Reset(Vector2.Zero);
                    level.StartNewLife(players[attacker_id]);
                }
            }
        }
        private void HandleInput()
        {
            // get all of our input states
#if !IPHONE
            keyboardState = Keyboard.GetState();
            gamePadState  = GamePad.GetState(PlayerIndex.One);
#endif
            touchState = TouchPanel.GetState();

#if WINDOWS_PHONE
            accelerometerState = Accelerometer.GetState();
#endif

#if !IPHONE
            // Exit the game when back is pressed.
            if ((gamePadState.Buttons.Back == ButtonState.Pressed) || (keyboardState.IsKeyDown(Keys.Escape)))
            {
                Exit();
            }
#endif
            bool continuePressed =
#if !IPHONE
                keyboardState.IsKeyDown(Keys.Space) ||
                gamePadState.IsButtonDown(Buttons.A) ||
#endif
                touchState.AnyTouch();

            // Perform the appropriate action to advance the game and
            // to get the player back to playing.
            if (!wasContinuePressed && continuePressed)
            {
                if (!level.Player.IsAlive)
                {
                    level.StartNewLife();
                }
                else if (level.TimeRemaining == TimeSpan.Zero)
                {
                    if (level.ReachedExit)
                    {
                        LoadNextLevel();
                    }
                    else
                    {
                        ReloadCurrentLevel();
                    }
                }
            }

            wasContinuePressed = continuePressed;
        }
Example #4
0
        private void HandleInput()
        {
            // get all of our input states
            keyboardState      = Keyboard.GetState();
            gamePadState       = GamePad.GetState(PlayerIndex.One);
            touchState         = TouchPanel.GetState();
            accelerometerState = Accelerometer.GetState();

            //Pause game when p is pressed
            if (keyboardState.IsKeyDown(Keys.P) && state == Gamestate.Game)
            {
                state = Gamestate.Pause;
            }

            //Reset Level if paused and r is pressed
            if (keyboardState.IsKeyDown(Keys.R) && state == Gamestate.Pause)
            {
                ReloadCurrentLevel();
                state = Gamestate.Game;
            }

            //Resume Game upon Enter
            if (keyboardState.IsKeyDown(Keys.Space) && state != Gamestate.Game)
            {
                state = Gamestate.Game;
            }

            // Exit the game when back is pressed.
            if (gamePadState.Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }

            bool continuePressed =
                keyboardState.IsKeyDown(Keys.Space) ||
                gamePadState.IsButtonDown(Buttons.A) ||
                touchState.AnyTouch();

            // Perform the appropriate action to advance the game and
            // to get the player back to playing.
            if (!wasContinuePressed && continuePressed)
            {
                if (!level.Player.IsAlive)
                {
                    level.StartNewLife();
                    ReloadCurrentLevel();
                }
                else if (level.TimeRemaining == TimeSpan.Zero)
                {
                    if (level.ReachedExit)
                    {
                        LoadNextLevel();
                    }
                    else
                    {
                        ReloadCurrentLevel();
                    }
                }
            }

            wasContinuePressed = continuePressed;
        }