Esempio n. 1
0
        /// <summary>
        /// Gets player horizontal movement and jump commands from input.
        /// </summary>
        private void GetInput(
            KeyboardState keyboardState,
            GamePadState gamePadState,
            TouchCollection touchState,
            AccelerometerState accelState,
            DisplayOrientation orientation)
        {
            // Get analog horizontal movement.
            movement = gamePadState.ThumbSticks.Left.X * MoveStickScale;

            // Ignore small movements to prevent running in place.
            if (Math.Abs(movement) < 0.5f)
            {
                movement = 0.0f;
            }

            // Move the player with accelerometer
            if (Math.Abs(accelState.Acceleration.Y) > 0.10f)
            {
                // set our movement speed
                movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f);

                // if we're in the LandscapeLeft orientation, we must reverse our movement
                if (orientation == DisplayOrientation.LandscapeRight)
                {
                    movement = -movement;
                }
            }

            // If any digital horizontal movement input is found, override the analog movement.
            if (gamePadState.IsButtonDown(Buttons.DPadLeft) ||
                keyboardState.IsKeyDown(Keys.Left) ||
                keyboardState.IsKeyDown(Keys.A))
            {
                movement = -1.0f;
            }
            else if (gamePadState.IsButtonDown(Buttons.DPadRight) ||
                     keyboardState.IsKeyDown(Keys.Right) ||
                     keyboardState.IsKeyDown(Keys.D))
            {
                movement = 1.0f;
            }

            // Check if the player wants to jump.
            isJumping =
                gamePadState.IsButtonDown(JumpButton) ||
                keyboardState.IsKeyDown(Keys.Space) ||
                keyboardState.IsKeyDown(Keys.Up) ||
                keyboardState.IsKeyDown(Keys.W) ||
                touchState.AnyTouch();

            // Check if the player wants to attack.
            isAttacking =
                keyboardState.IsKeyDown(Keys.Q) ||
                keyboardState.IsKeyDown(Keys.LeftShift) ||
                keyboardState.IsKeyDown(Keys.RightShift);
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the Keyboard and GamePad inputs
        /// </summary>
        private void HandleInput()
        {
            // get all of our input states
            keyboardState      = Keyboard.GetState();
            gamePadState       = GamePad.GetState(PlayerIndex.One);
            touchState         = TouchPanel.GetState();
            accelerometerState = Accelerometer.GetState();

            // Exit the game when back is pressed.
            if (gamePadState.Buttons.Back == ButtonState.Pressed || keyboardState.IsKeyDown(Keys.Escape))
            {
                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)
                {
                    this.life--;
                    if (this.life >= 1)
                    {
                        level.StartNewLife();
                        level.HealthPlayer = 150;
                    }
                    else
                    {
                        pause.ExitClicked = true;
                    }
                }
                else if (level.TimeRemaining == TimeSpan.Zero)
                {
                    if (level.ReachedExit)
                    {
                        LoadNextLevel(this);
                        timerSwitchGame = TimeSpan.FromSeconds(0);
                    }
                    else if (life > 1)
                    {
                        ReloadCurrentLevel();
                    }
                    else if (life == 1)
                    {
                        Exit();
                    }
                }
            }

            wasContinuePressed = continuePressed;
        }
Esempio n. 3
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]);
                }
            }
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            TouchCollection touchState = TouchPanel.GetState();

            if (touchState.AnyTouch())
            {
                if (this.OnTouch != null)
                {
                    this.OnTouch();
                }
            }
        }
        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;
        }
Esempio n. 6
0
File: Game.cs Progetto: sq/SampleFNA
        private void HandleInput(GameTime gameTime)
        {
            // get all of our input states
            keyboardState      = Keyboard.GetState();
            touchState         = TouchPanel.GetState();
            gamePadState       = virtualGamePad.GetState(touchState, GamePad.GetState(PlayerIndex.One));
            accelerometerState = Accelerometer.GetState();

#if !NETFX_CORE && !JSIL
            // Exit the game when back is pressed.
            if (gamePadState.Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }
#endif

            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();
                }
                else if (level.TimeRemaining == TimeSpan.Zero)
                {
                    if (level.ReachedExit)
                    {
                        LoadNextLevel();
                    }
                    else
                    {
                        ReloadCurrentLevel();
                    }
                }
            }

            wasContinuePressed = continuePressed;

            virtualGamePad.Update(gameTime);
        }
Esempio n. 7
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            //// get all of our input states
            keyboardState      = Keyboard.GetState();
            touchState         = TouchPanel.GetState();
            accelerometerState = Accelerometer.GetState();

            if (maze.player.IsAlive == false)
            {
                if (keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.AnyTouch() == true)
                {
                    maze.StartRoom().StartNewLife();
                }
            }

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


            wasContinuePressed = continuePressed;
        }
Esempio n. 8
0
        /// <summary>
        /// Gets player horizontal movement and jump commands from input.
        /// </summary>
        private void GetInput(
            KeyboardState keyboardState, 
            GamePadState gamePadState, 
            TouchCollection touchState,
            AccelerometerState accelState, 
            DisplayOrientation orientation)
        {
            // Get analog horizontal movement.
            movement = gamePadState.ThumbSticks.Left.X * MoveStickScale;

            // Ignore small movements to prevent running in place.
            if (Math.Abs(movement) < 0.5f)
                movement = 0.0f;

            // Move the player with accelerometer
            if (Math.Abs(accelState.Acceleration.Y) > 0.10f)
            {
                // set our movement speed
                movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f);

                // if we're in the LandscapeLeft orientation, we must reverse our movement
                if (orientation == DisplayOrientation.LandscapeRight)
                    movement = -movement;
            }

            // If any digital horizontal movement input is found, override the analog movement.
            if (gamePadState.IsButtonDown(Buttons.DPadLeft) ||
                keyboardState.IsKeyDown(Keys.Left) ||
                keyboardState.IsKeyDown(Keys.A))
            {
                movement = -1.0f;
            }
            else if (gamePadState.IsButtonDown(Buttons.DPadRight) ||
                     keyboardState.IsKeyDown(Keys.Right) ||
                     keyboardState.IsKeyDown(Keys.D))
            {
                movement = 1.0f;
            }

            // Check if the player wants to jump.
            isJumping =
                gamePadState.IsButtonDown(JumpButton) ||
                keyboardState.IsKeyDown(Keys.Space) ||
                keyboardState.IsKeyDown(Keys.Up) ||
                keyboardState.IsKeyDown(Keys.W) ||
                touchState.AnyTouch();
        }
        private void HandleInput()
        {
            // get all of our input states
            keyboardState = Keyboard.GetState();
            gamePadState = GamePad.GetState(PlayerIndex.One);
            touchState = TouchPanel.GetState();
            accelerometerState = Accelerometer.GetState();

            // 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();
                }
                else if (level.TimeRemaining == TimeSpan.Zero)
                {
                    if (!level.ReachedExit)
                        ReloadCurrentLevel();
                    //    LoadNextLevel();
                    //else

                }
            }
            wasContinuePressed = continuePressed;
        }
Esempio n. 10
0
        /// <summary>
        /// Gets player horizontal movement and jump commands from input.
        /// </summary>
        private void GetInput(
            KeyboardState keyboardState, 
            GamePadState gamePadState, 
            TouchCollection touchState,
            AccelerometerState accelState, 
            DisplayOrientation orientation)
        {
            // Get analog horizontal movement.
            movement = gamePadState.ThumbSticks.Left.X * MoveStickScale;

            // Ignore small movements to prevent running in place.
            if (Math.Abs(movement) < 0.5f)
                movement = 0.0f;

            // Move the player with accelerometer
            if (Math.Abs(accelState.Acceleration.Y) > 0.10f)
            {
                // set our movement speed
                movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f);

                // if we're in the LandscapeLeft orientation, we must reverse our movement
                if (orientation == DisplayOrientation.LandscapeRight)
                    movement = -movement;
            }

            // If any digital horizontal movement input is found, override the analog movement.
            if (keyboardState.IsKeyDown(Keys.Left) ||
                keyboardState.IsKeyDown(Keys.A))

            {
                movement = -1.0f;
            }
            else if (keyboardState.IsKeyDown(Keys.Right) ||
                     keyboardState.IsKeyDown(Keys.D))
            {
                movement = 1.0f;
            }

            // Weapon switching
            if (gamePadState.IsButtonDown(Buttons.DPadLeft))
            {
                weapon.Reset();
                weapon = m_handgun;
            }
            else if (gamePadState.IsButtonDown(Buttons.DPadUp))
            {
                weapon.Reset();
                weapon = m_shotgun;
            }
            else if (gamePadState.IsButtonDown(Buttons.DPadRight))
            {
                weapon.Reset();
                weapon = m_knife;
            }
            if (gamePadState.IsButtonDown(SwitchButton) && !old_gamePadState.IsButtonDown(SwitchButton))
            {
                weapon.Reset();
                if (weapon == m_handgun)
                    weapon = m_shotgun;
                else if (weapon == m_shotgun)
                    weapon = m_knife;
                else
                    weapon = m_handgun;
            }

            // Check if the player wants to jump.
            isJumping =
                gamePadState.IsButtonDown(JumpButton) ||
                keyboardState.IsKeyDown(Keys.Space) ||
                keyboardState.IsKeyDown(Keys.Up) ||
                keyboardState.IsKeyDown(Keys.W) ||
                touchState.AnyTouch();

            if (gamePadState.IsButtonDown(RollButton) && !old_gamePadState.IsButtonDown(RollButton))
            {
                if (canRollAgain && isOnGround)
                {
                    isRolling = true;
                    canRollAgain = false;
                }
            }

            isThrowGrenade = false;
            if (!isRolling)
            {
                // release the charged bomb
                if (old_gamePadState.IsButtonDown(GrenadeButton) && !gamePadState.IsButtonDown(GrenadeButton))
                {
                    m_bomb.Shoot();
                }
                // charge up the bomb throw if button held
                if (gamePadState.IsButtonDown(GrenadeButton) && isOnGround && m_bomb.CanAttack)
                {
                    isThrowGrenade = true;
                    m_bomb.Charging(this.position);
                }
                // other attacks
                else if ((gamePadState.IsButtonDown(FireButton) && !old_gamePadState.IsButtonDown(FireButton)) ||
                        (keyboardState.IsKeyDown(Keys.Z)) ||
                        (gamePadState.IsButtonDown(FireButton2) && !old_gamePadState.IsButtonDown(FireButton2)))
                {
                    weapon.Shoot();
                }

            }

            old_gamePadState = gamePadState;
        }
        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]);
                }
            }
        }
Esempio n. 12
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;
        }
Esempio n. 13
0
        private void HandleInput()
        {
            // get all of our input states
            keyboardState = Keyboard.GetState();
            gamePadState = GamePad.GetState(PlayerIndex.One);
            touchState = TouchPanel.GetState();
            accelerometerState = Accelerometer.GetState();

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

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

            wasContinuePressed = continuePressed;
        }
Esempio n. 14
0
        /// <summary>
        /// Gets player horizontal movement and jump commands from input.
        /// </summary>
        private void GetInput(
            KeyboardState keyboardState,
            GamePadState gamePadState,
            TouchCollection touchState,
            AccelerometerState accelState,
            DisplayOrientation orientation)
        {
            // Get analog horizontal movement.
            movement = gamePadState.ThumbSticks.Left.X * MoveStickScale;

            // Ignore small movements to prevent running in place.
            if (Math.Abs(movement) < 0.5f)
            {
                movement = 0.0f;
            }

            // Move the player with accelerometer
            if (Math.Abs(accelState.Acceleration.Y) > 0.10f)
            {
                // set our movement speed
                movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f);

                // if we're in the LandscapeLeft orientation, we must reverse our movement
                if (orientation == DisplayOrientation.LandscapeRight)
                {
                    movement = -movement;
                }
            }

            // If any digital horizontal movement input is found, override the analog movement.
            if (keyboardState.IsKeyDown(Keys.Left) ||
                keyboardState.IsKeyDown(Keys.A))

            {
                movement = -1.0f;
            }
            else if (keyboardState.IsKeyDown(Keys.Right) ||
                     keyboardState.IsKeyDown(Keys.D))
            {
                movement = 1.0f;
            }

            // Weapon switching
            if (gamePadState.IsButtonDown(Buttons.DPadLeft))
            {
                weapon.Reset();
                weapon = m_handgun;
            }
            else if (gamePadState.IsButtonDown(Buttons.DPadUp))
            {
                weapon.Reset();
                weapon = m_shotgun;
            }
            else if (gamePadState.IsButtonDown(Buttons.DPadRight))
            {
                weapon.Reset();
                weapon = m_knife;
            }
            if (gamePadState.IsButtonDown(SwitchButton) && !old_gamePadState.IsButtonDown(SwitchButton))
            {
                weapon.Reset();
                if (weapon == m_handgun)
                {
                    weapon = m_shotgun;
                }
                else if (weapon == m_shotgun)
                {
                    weapon = m_knife;
                }
                else
                {
                    weapon = m_handgun;
                }
            }


            // Check if the player wants to jump.
            isJumping =
                gamePadState.IsButtonDown(JumpButton) ||
                keyboardState.IsKeyDown(Keys.Space) ||
                keyboardState.IsKeyDown(Keys.Up) ||
                keyboardState.IsKeyDown(Keys.W) ||
                touchState.AnyTouch();

            if (gamePadState.IsButtonDown(RollButton) && !old_gamePadState.IsButtonDown(RollButton))
            {
                if (canRollAgain && isOnGround)
                {
                    isRolling    = true;
                    canRollAgain = false;
                }
            }

            isThrowGrenade = false;
            if (!isRolling)
            {
                // release the charged bomb
                if (old_gamePadState.IsButtonDown(GrenadeButton) && !gamePadState.IsButtonDown(GrenadeButton))
                {
                    m_bomb.Shoot();
                }
                // charge up the bomb throw if button held
                if (gamePadState.IsButtonDown(GrenadeButton) && isOnGround && m_bomb.CanAttack)
                {
                    isThrowGrenade = true;
                    m_bomb.Charging(this.position);
                }
                // other attacks
                else if ((gamePadState.IsButtonDown(FireButton) && !old_gamePadState.IsButtonDown(FireButton)) ||
                         (keyboardState.IsKeyDown(Keys.Z)) ||
                         (gamePadState.IsButtonDown(FireButton2) && !old_gamePadState.IsButtonDown(FireButton2)))
                {
                    weapon.Shoot();
                }
            }

            old_gamePadState = gamePadState;
        }
        private void HandleInput(GameTime gameTime)
        {
            // get all of our input states
            previousKeyboardState = keyboardState;
            keyboardState = Keyboard.GetState();
            touchState = TouchPanel.GetState();
            gamePadState = virtualGamePad.GetState(touchState, GamePad.GetState(PlayerIndex.One));
            accelerometerState = Accelerometer.GetState();
            MouseState mouseState = Mouse.GetState();

            Vector2 playerPos = Vector2.Transform(level.Player.Position, globalTransformation);
            Vector2 lookDir = Vector2.Normalize(mouseState.Position.ToVector2() - playerPos);
            spotlight.Rotation = (float) Math.Atan2(lookDir.Y, lookDir.X);

            #if !NETFX_CORE
            // Exit the game when back is pressed.
            if (gamePadState.Buttons.Back == ButtonState.Pressed)
                Exit();
            #endif
            if (keyboardState.IsKeyDown(ConsoleToggleOpenKey) && !previousKeyboardState.IsKeyDown(ConsoleToggleOpenKey))
                Console.ToggleOpenClose();

            var continuePressed = false;
            if (!Console.IsAcceptingInput)
            {
                penumbraController.InputEnabled = true;

                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();
                    }
                    else if (level.TimeRemaining == TimeSpan.Zero)
                    {
                        if (level.ReachedExit)
                            LoadNextLevel();
                        else
                            ReloadCurrentLevel();
                    }
                }
            }
            else
            {
                penumbraController.InputEnabled = false;
            }
            wasContinuePressed = continuePressed;

            virtualGamePad.Update(gameTime);
        }
Esempio n. 16
0
        /// <summary>
        /// Handles input for horizontal movement and jumps.
        /// </summary>
        public void ReadInput(
            KeyboardState keyboardState,
            GamePadState gamePadState,
            TouchCollection touchState,
            AccelerometerState accelState,
            DisplayOrientation orientation)
        {
            //360 Controller movements
            movement = gamePadState.ThumbSticks.Left.X * MoveStickScale;

            #if WINDOWS_PHONE
            if (PhoneMainMenuScreen.GameOptions.controlOptions != 2)
                movement = VirtualThumbsticks.LeftThumbstick.X * MoveStickScale;
            #endif

            //Stops animating in place for analog controls
            if (Math.Abs(movement) < 0.5f)
                movement = 0.0f;

            #if WINDOWS_PHONE
            if (PhoneMainMenuScreen.GameOptions.controlOptions != 1)
            {
                // Move the player with accelerometer
                if (Math.Abs(accelState.Acceleration.Y) > 0.10f)
                {
                    // set our movement speed
                    movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f);

                    // if we're in the LandscapeLeft orientation, we must reverse our movement
                    if (orientation == DisplayOrientation.LandscapeRight)
                        movement = -movement;
                }
            }
            #endif

            //Keyboard movements (overwrites analog stick)
            if (keyboardState.IsKeyDown(Keys.A) || gamePadState.IsButtonDown(Buttons.DPadLeft))
                movement = -1.0f;
            else if (keyboardState.IsKeyDown(Keys.D) || gamePadState.IsButtonDown(Buttons.DPadRight))
                movement = 1.0f;

            //checks for jumps
            jumping = gamePadState.IsButtonDown(Buttons.A) ||
                      keyboardState.IsKeyDown(Keys.Space) ||
                      keyboardState.IsKeyDown(Keys.Down);
            #if WINDOWS_PHONE
            if (PhoneMainMenuScreen.GameOptions.controlOptions == 2)
            {
                jumping = touchState.AnyTouch();
            }

            if (PhoneMainMenuScreen.GameOptions.controlOptions != 2)
            {
                if (VirtualThumbsticks.RightThumbstickCenter != null)
                {
                    jumping = true;
                }
            }
            #endif
        }