当前位置: 首页>>代码示例>>C#>>正文


C# TouchCollection.AnyTouch方法代码示例

本文整理汇总了C#中TouchCollection.AnyTouch方法的典型用法代码示例。如果您正苦于以下问题:C# TouchCollection.AnyTouch方法的具体用法?C# TouchCollection.AnyTouch怎么用?C# TouchCollection.AnyTouch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TouchCollection的用法示例。


在下文中一共展示了TouchCollection.AnyTouch方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleInput

        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;
        }
开发者ID:rahulpshephertz,项目名称:Platformer,代码行数:36,代码来源:GamePage.xaml.cs

示例2: GetInput

        /// <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();
        }
开发者ID:nkast,项目名称:MonoGame.Samples,代码行数:50,代码来源:Player.cs

示例3: GetInput

        /// <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
//.........这里部分代码省略.........
开发者ID:peterhoang,项目名称:Super-Duper-Game,代码行数:101,代码来源:Player.cs

示例4: HandleInput

        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]);
                }
            }
        }
开发者ID:peterhoang,项目名称:Super-Duper-Game,代码行数:52,代码来源:PlatformerGame.cs

示例5: HandleInput

        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;
        }
开发者ID:zmthy,项目名称:play-dead,代码行数:22,代码来源:PlatformerGame.cs

示例6: HandleInput

        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);
        }
开发者ID:infinitespace-studios,项目名称:penumbra,代码行数:57,代码来源:PlatformerGame.cs

示例7: ReadInput

        /// <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
        }
开发者ID:Mechalon,项目名称:Caffeine-Junkies-Game,代码行数:63,代码来源:Player.cs


注:本文中的TouchCollection.AnyTouch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。