Ejemplo n.º 1
0
        /// <summary>
        /// Handle input for the sample
        /// </summary>
        void HandleInput()
        {
            KeyboardState previousKeyboardState = currentKeyboardState;
            GamePadState  previousGamePadState  = currentGamePadState;

            currentGamePadState  = GamePad.GetState(PlayerIndex.One);
            currentKeyboardState = Keyboard.GetState();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            if (previousGamePadState.Buttons.A == ButtonState.Released &&
                currentGamePadState.Buttons.A == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.A) &&
                currentKeyboardState.IsKeyDown(Keys.A))
            {
                pathFinder.IsSearching = !pathFinder.IsSearching;
            }

            if (previousGamePadState.Buttons.B == ButtonState.Released &&
                currentGamePadState.Buttons.B == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.B) &&
                currentKeyboardState.IsKeyDown(Keys.B))
            {
                map.MapReload = true;
            }

            if (previousGamePadState.Buttons.X == ButtonState.Released &&
                currentGamePadState.Buttons.X == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.X) &&
                currentKeyboardState.IsKeyDown(Keys.X))
            {
                pathFinder.NextSearchType();
            }

            if (previousGamePadState.Buttons.Y == ButtonState.Released &&
                currentGamePadState.Buttons.Y == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.Y) &&
                currentKeyboardState.IsKeyDown(Keys.Y))
            {
                map.CycleMap();
            }

            if (previousGamePadState.DPad.Right == ButtonState.Released &&
                currentGamePadState.DPad.Right == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.Right) &&
                currentKeyboardState.IsKeyDown(Keys.Right))
            {
                pathFinder.TimeStep += .1f;
            }

            if (previousGamePadState.DPad.Left == ButtonState.Released &&
                currentGamePadState.DPad.Left == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.Left) &&
                currentKeyboardState.IsKeyDown(Keys.Left))
            {
                pathFinder.TimeStep -= .1f;
            }

            pathFinder.TimeStep = MathHelper.Clamp(pathFinder.TimeStep, 0f, 1f);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle input for the sample
        /// </summary>
        void HandleInput()
        {
            KeyboardState previousKeyboardState = currentKeyboardState;
            GamePadState  previousGamePadState  = currentGamePadState;

            currentGamePadState  = GamePad.GetState(PlayerIndex.One);
            currentKeyboardState = Keyboard.GetState();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            if (previousGamePadState.Buttons.A == ButtonState.Released &&
                currentGamePadState.Buttons.A == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.A) &&
                currentKeyboardState.IsKeyDown(Keys.A))
            {
                pathFinder.IsSearching = !pathFinder.IsSearching;
            }

            if (previousGamePadState.Buttons.B == ButtonState.Released &&
                currentGamePadState.Buttons.B == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.B) &&
                currentKeyboardState.IsKeyDown(Keys.B))
            {
                map.MapReload = true;
            }

            if (previousGamePadState.Buttons.X == ButtonState.Released &&
                currentGamePadState.Buttons.X == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.X) &&
                currentKeyboardState.IsKeyDown(Keys.X))
            {
                pathFinder.NextSearchType();
            }

            if (previousGamePadState.Buttons.Y == ButtonState.Released &&
                currentGamePadState.Buttons.Y == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.Y) &&
                currentKeyboardState.IsKeyDown(Keys.Y))
            {
                map.CycleMap();
            }

            if (previousGamePadState.DPad.Right == ButtonState.Released &&
                currentGamePadState.DPad.Right == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.Right) &&
                currentKeyboardState.IsKeyDown(Keys.Right))
            {
                pathFinder.TimeStep += .1f;
            }

            if (previousGamePadState.DPad.Left == ButtonState.Released &&
                currentGamePadState.DPad.Left == ButtonState.Pressed ||
                previousKeyboardState.IsKeyUp(Keys.Left) &&
                currentKeyboardState.IsKeyDown(Keys.Left))
            {
                pathFinder.TimeStep -= .1f;
            }

            pathFinder.TimeStep = MathHelper.Clamp(pathFinder.TimeStep, 0f, 1f);

            TouchCollection rawTouch = TouchPanel.GetState();

            // Use raw touch for the sliders
            if (rawTouch.Count > 0)
            {
                // Only grab the first one
                TouchLocation touchLocation = rawTouch[0];

                // Create a collidable rectangle to determine if we touched the controls
                Rectangle touchRectangle = new Rectangle((int)touchLocation.Position.X,
                                                         (int)touchLocation.Position.Y, 10, 10);

                // Have the sliders rely on the raw touch to function properly
                if (barTimeStep.Intersects(touchRectangle))
                {
                    pathFinder.TimeStep = (float)(touchRectangle.X - barTimeStep.X) / (float)barTimeStep.Width;
                }
            }

            // Next we handle all of the gestures. since we may have multiple gestures available,
            // we use a loop to read in all of the gestures. this is important to make sure the
            // TouchPanel's queue doesn't get backed up with old data
            while (TouchPanel.IsGestureAvailable)
            {
                // Read the next gesture from the queue
                GestureSample gesture = TouchPanel.ReadGesture();

                // Create a collidable rectangle to determine if we touched the controls
                Rectangle touch = new Rectangle((int)gesture.Position.X, (int)gesture.Position.Y, 20, 20);

                // We can use the type of gesture to determine our behavior
                switch (gesture.GestureType)
                {
                case GestureType.Tap:
                    if (buttonStartStop.Intersects(touch))
                    {
                        pathFinder.IsSearching = !pathFinder.IsSearching;
                    }
                    else if (buttonReset.Intersects(touch))
                    {
                        map.MapReload = true;
                    }
                    else if (buttonPathfinding.Intersects(touch))
                    {
                        pathFinder.NextSearchType();
                    }
                    else if (buttonNextMap.Intersects(touch))
                    {
                        map.CycleMap();
                    }
                    break;
                }
            }
        }