Пример #1
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input.IsMenuSelect())
            {
                okSoundEffect.Play();

                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                {
                    Accepted(this, new PlayerInputEventArgs(true));
                }

                ExitScreen();
            }
            else if (input.IsMenuCancel())
            {
                cancelSoundEffect.Play();

                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                {
                    Cancelled(this, new PlayerInputEventArgs(false, true));
                }

                ExitScreen();
            }
            return;
        }
Пример #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>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Variables that will be set during input checking
            int toggleDirection;

            if (typingInput) // The user is typing input
            {
                bool inputAccepted = input.IsMenuSelect();
                bool inputCancelled = input.IsMenuCancel();
                bool inputBackspace = input.IsBackspace();
                String keysTyped = input.TypeableInput();

                if (inputAccepted || inputCancelled)
                {
                    typingInput = false;
                }
                if (inputAccepted || inputCancelled || inputBackspace || keysTyped != String.Empty)
                {
                    OnTyped(selectedEntry, inputAccepted, inputCancelled, inputBackspace, keysTyped);
                }
            }
            else // The user is performing normal menu input
            {
                // Move to the previous menu entry?
                if (input.IsMenuUp())
                {
                    if (!graphicalSelect)
                    {
                        menuScrollSoundEffect.Play();
                    }
                    do
                    {
                        selectedEntry--;
                        if (selectedEntry < 0)
                        {
                            selectedEntry = menuEntries.Count - 1;
                        }
                    } while (!menuEntries[selectedEntry].Enabled);
                }

                // Move to the next menu entry?
                if (input.IsMenuDown())
                {
                    if (!graphicalSelect)
                    {
                        menuScrollSoundEffect.Play();
                    }
                    do
                    {
                        selectedEntry++;
                        if (selectedEntry >= menuEntries.Count)
                        {
                            selectedEntry = 0;
                        }
                    } while (!menuEntries[selectedEntry].Enabled);
                }

                // Accept or cancel the menu?
                if (menuEntries[selectedEntry].Toggleable && input.IsMenuToggle(out toggleDirection))
                {
                    if (!graphicalSelect)
                    {
                        menuSelectSoundEffect.Play();
                    }
                    OnSelectEntry(selectedEntry, input.IsMenuSelect(), false, toggleDirection);
                }
                else if (input.IsMenuSelect())
                {
                    if (!graphicalSelect)
                    {
                        menuSelectSoundEffect.Play();
                    }
                    OnSelectEntry(selectedEntry, true, false, 0);
                }
                else if (input.IsMenuCancel())
                {
                    menuCancelSoundEffect.Play();
                    OnCancel();
                }
            }
            return;
        }
Пример #4
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            if (gameState.usersPlayer == null)
            {
                return;
            }

            // Look up inputs for the active player profile.

            KeyboardState keyboardState = input.currentKeyboardState;
            GamePadState gamePadState = input.currentGamePadState;

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&  input.gamePadWasConnected;

            if (input.IsPauseGame() || gamePadDisconnected)
            {
                pauseSoundEffect.Play();
                ScreenManager.AddScreen(new PauseMenuScreen());
            }
            else
            {
                /* ===== COPY PASTE PLAYER 2 ====== */

                // Otherwise move the player position.
                /*Vector2 p2movement = Vector2.Zero;

                if (keyboardState.IsKeyDown(Keys.A))
                    p2movement.X--;

                if (keyboardState.IsKeyDown(Keys.D))
                    p2movement.X++;

                if (keyboardState.IsKeyDown(Keys.W))
                    p2movement.Y--;

                if (keyboardState.IsKeyDown(Keys.S))
                    p2movement.Y++;

                if (p2movement.Length() > 1)
                    p2movement.Normalize();

                if (keyboardState.IsKeyDown(Keys.T))
                {
                    Command c = new Command();
                    c.entity_id = secondPlayer.id;
                    c.direction = p2movement;
                    c.ct = CommandType.SHOOT;
                    c.position = secondPlayer.worldPosition;
                    commandBuffer.Add(c);
                }

                Command c3 = new Command();
                c3.entity_id = secondPlayer.id;
                c3.direction = p2movement;
                c3.ct = CommandType.MOVE;
                commandBuffer.Add(c3);*/

                /* ===== COPY PASTE PLAYER 2 ====== */

                // Otherwise move the player position.
                Vector2 movement = Vector2.Zero;

                if (keyboardState.IsKeyDown(Keys.Left))
                    movement.X--;

                if (keyboardState.IsKeyDown(Keys.Right))
                    movement.X++;

                if (keyboardState.IsKeyDown(Keys.Up))
                    movement.Y--;

                if (keyboardState.IsKeyDown(Keys.Down))
                    movement.Y++;

                Vector2 thumbstick = gamePadState.ThumbSticks.Left;

                movement.X += thumbstick.X;
                movement.Y -= thumbstick.Y;

                if (movement.Length() > 1)
                    movement.Normalize();

                if ((keyboardState.IsKeyDown(Keys.Z) || gamePadState.Triggers.Right > 0.5) && attackButtonOK)
                {
                    Command c = new Command();
                    c.entity_id = gameState.usersPlayer.id;
                    c.direction = movement;
                    c.ct = CommandType.SHOOT;
                    c.position = gameState.usersPlayer.worldPosition;
                    commandBuffer.Add(c);
                    //Console.WriteLine("Shoot");
                    attackButtonOK = false;
                }
                else if (keyboardState.IsKeyUp(Keys.Z) || gamePadState.Triggers.Right < 0.5)
                {
                    attackButtonOK = true;
                }

                if ((keyboardState.IsKeyDown(Keys.X) || gamePadState.Triggers.Left > 0.5) && attackButtonOK)
                {
                    Command c = new Command();
                    c.entity_id = gameState.usersPlayer.id;
                    c.ct = CommandType.ATTACK;
                    c.position = gameState.usersPlayer.worldPosition;
                    c.direction = movement;
                    commandBuffer.Add(c);
                    attackButtonOK = false;
                }
                else if (keyboardState.IsKeyUp(Keys.X) || gamePadState.Triggers.Left < 0.5)
                {
                    attackButtonOK = true;
                }

                if (keyboardState.IsKeyDown(Keys.R) && canCreate && isServer)
                {
                    gameState.createEnemy(1280 / 2, 720 / 2 + 200, Enemy.Type.Goblin);
                    canCreate = false;
                } else if (keyboardState.IsKeyUp(Keys.R)) {
                    canCreate = true;
                }

                //if (movement != Vector2.Zero || gameState.isMoving)
                //{
                        Command c2 = new Command();
                        c2.entity_id = gameState.usersPlayer.id;
                        c2.direction = movement;
                        c2.ct = CommandType.MOVE;
                        commandBuffer.Add(c2);
                        gameState.isMoving = false;
                //}

            }
        }