示例#1
0
        /// <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.MenuUp)
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (input.MenuDown)
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }

            // Accept or cancel the menu?
            if (input.MenuSelect)
            {
                OnSelectEntry(selectedEntry);
            }
            else if (input.MenuCancel)
            {
                OnCancel();
            }
        }
示例#2
0
 /// <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)
 {
 }
示例#3
0
        /// <summary>
        /// Input helper method provided by GameScreen.  Packages up the various input
        /// values for ease of use.  Here it checks for pausing and handles controlling
        /// the player's tank.
        /// </summary>
        /// <param name="input">The state of the gamepads</param>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            if (input.PauseGame)
            {
                if (gameOver == true)
                {
                    foreach (GameScreen screen in ScreenManager.GetScreens())
                        screen.ExitScreen();

                    ScreenManager.AddScreen(new BackgroundScreen());
                    ScreenManager.AddScreen(new MainMenuScreen());
                }
                else
                {
                    ScreenManager.AddScreen(new PauseMenuScreen());
                }
            }
            else
            {
                // This section handles tank movement.  We only allow one "movement" action
                // to occur at once so that touchpad devices don't get double hits.
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Left) || input.CurrentGamePadStates[0].DPad.Left == ButtonState.Pressed)
                {
                    if (player.ducking)
                        player.Velocity.X = -0.3f;
                    else
                        player.Velocity.X = -1.0f;
                    player.FacingLeft = true;
                }
                else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Right) || input.CurrentGamePadStates[0].DPad.Right == ButtonState.Pressed)
                {
                    if (player.ducking)
                        player.Velocity.X = 0.3f;
                    else
                        player.Velocity.X = 1.0f;

                    player.FacingLeft = false;

                }
                else
                {
                    player.Velocity.X = 0;
                }

                if ((input.CurrentKeyboardStates[0].IsKeyDown(Keys.Down) || input.CurrentGamePadStates[0].DPad.Down == ButtonState.Pressed)
                        && !player.Jumping && !player.Falling)
                {
                    player.LookingUp = false;
                    player.ducking = true;
                }
                else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Up) || input.CurrentGamePadStates[0].DPad.Up == ButtonState.Pressed)
                {
                    player.LookingUp = true;
                    player.ducking = false;
                }
                else
                {
                    player.ducking = false;
                    player.LookingUp = false;
                }

                // B button, or pressing on the upper half of the pad fires the weapon.
                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.LeftControl) || input.CurrentGamePadStates[0].IsButtonDown(Buttons.A))
                {
                    //if (player.FireTimer <= 0.0f && player.IsAlive && !gameOver)
                    if (!player.pulledTrigger && player.IsAlive && !gameOver)
                    {
                        Bullet bullet = CreatePlayerBullet();
                        if (player.LookingUp)
                        {
                            if (player.FacingLeft == true)
                                bullet.Position = new Vector2((int)player.Position.X + 8, player.Position.Y + 17);
                            else
                                bullet.Position = new Vector2((int)player.Position.X + 23, player.Position.Y + 17);

                            bullet.Velocity = new Vector2(0.0f, -256.0f);
                        }
                        else if (player.FacingLeft)
                        {
                            if (player.ducking)
                            {
                                bullet.Position = new Vector2((int)player.Position.X, player.Position.Y + 25);
                            }
                            else
                            {
                                bullet.Position = new Vector2((int)player.Position.X, player.Position.Y + 47);
                            }
                            bullet.Velocity = new Vector2(-256.0f, 0.0f);

                        }
                        else
                        {
                            if (player.ducking)
                            {
                                bullet.Position = new Vector2((int)(player.Position.X + player.Width), player.Position.Y + 25);
                            }
                            else
                            {
                                bullet.Position = new Vector2((int)(player.Position.X + player.Width), player.Position.Y + 47);
                            }
                            bullet.Velocity = new Vector2(256.0f, 0.0f);
                        }
                        //player.FireTimer = 0.1f;
                        player.pulledTrigger = true;
                        particles.CreatePlayerFireSmoke(player);
                        playerFired.Play();
                    }
                }
                else
                {
                    player.pulledTrigger = false;
                }

                if ((input.CurrentKeyboardStates[0].IsKeyDown(Keys.LeftAlt) || input.CurrentGamePadStates[0].IsButtonDown(Buttons.B))
                        && !player.Falling && !player.ducking)
                    player.Jumping = true;
            }
        }