Example #1
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)
 {
 }
Example #2
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }
Example #3
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");
            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            if (input.IsPauseGame(ControllingPlayer))
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
            else
            {
                float leftRightRot = 0;
                float leftRightRoll = 0;
                float upDownRot = 0;

                float turningSpeed = (float)gameti.ElapsedGameTime.TotalMilliseconds / 1000.0f; //Test
                turningSpeed *= 1.6f * gameSpeed;
                KeyboardState keys = Keyboard.GetState();
                if (keys.IsKeyDown(Keys.D) || keys.IsKeyDown(Keys.Right))
                    leftRightRot += turningSpeed * turnMod;
                if (keys.IsKeyDown(Keys.A) || keys.IsKeyDown(Keys.Left))
                    leftRightRot -= turningSpeed * turnMod;

                if (keys.IsKeyDown(Keys.S) || keys.IsKeyDown(Keys.Down))
                    upDownRot += turningSpeed * turnMod;
                if (keys.IsKeyDown(Keys.W) || keys.IsKeyDown(Keys.Up))
                    upDownRot -= turningSpeed * turnMod;

                MouseState state = Mouse.GetState();
                int x = 0;
                int y = 0;
                Mouse.SetPosition(x, y);//Hier wird die Maus Position auf x=0 und y= 0 gesetzt
                int mausX = state.X;
                int mausY = state.Y;
                //Hier wird geprüft ob die Maus bewegt wurde
                if (mausX != x || mausY != y )
                {
                    mousePlay(mausX, mausY, leftRightRot, leftRightRoll, upDownRot, turningSpeed);
                }
                  if (keys.IsKeyDown(Keys.Q) || state.XButton1 == ButtonState.Pressed)
                    leftRightRoll -= turningSpeed * turnMod * 1.5f;
                  if (keys.IsKeyDown(Keys.E) || state.XButton2 == ButtonState.Pressed)
                    leftRightRoll += turningSpeed * turnMod * 1.5f;

                Quaternion additionalRot = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, -1), leftRightRoll) * Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), upDownRot) * Quaternion.CreateFromAxisAngle(new Vector3(0, -1, 0), leftRightRot);
                xwingRotation *= additionalRot;

                if (state.LeftButton == ButtonState.Pressed || keys.IsKeyDown(Keys.Space))
                {
                    double currentTime = gameti.TotalGameTime.TotalMilliseconds;    //
                    if (currentTime - lastBulletTime > 150)
                    {
                        Bullet newBullet = new Bullet();
                        newBullet.position = xwingPosition;
                        newBullet.rotation = xwingRotation;
                        newBullet.persistence = currentTime; //Lebenszeit initialisieren
                        bulletList.Add(newBullet);

                        lastBulletTime = currentTime;
                        countBullets++;
                        weaponSound.Play();
                    }
                }
            }
        }
Example #4
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.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

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

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

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

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }