Helper for reading input from keyboard, gamepad, and touch input. This class tracks both the current and previous state of the input devices, and implements query methods for high level input actions such as "move up through the menu" or "pause the game".
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the main menu screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            base.HandleInput(input);
        }
示例#2
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];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            // 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[playerIndex];

            if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
            else
            {
                xspace.HandleInput(keyboardState, gamePadState);
            }
        }
示例#3
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            KeyboardState keyboardState = input.CurrentKeyboardState;
            KeyboardState lastKeyboardState = input.LastKeyboardState;
            if ((keyboardState.IsKeyDown(Keys.Up) && !lastKeyboardState.IsKeyDown(Keys.Up)) || (keyboardState.IsKeyDown(Keys.W) && !lastKeyboardState.IsKeyDown(Keys.W)))
            {
                selectedEntry--;
                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            if (keyboardState.IsKeyDown(Keys.Down) && !lastKeyboardState.IsKeyDown(Keys.Down) || (keyboardState.IsKeyDown(Keys.S) && !lastKeyboardState.IsKeyDown(Keys.S)))
            {
                selectedEntry++;
                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }

            if ((keyboardState.IsKeyDown(Keys.Space) && !lastKeyboardState.IsKeyDown(Keys.Space)) || (keyboardState.IsKeyDown(Keys.Enter) && !lastKeyboardState.IsKeyDown(Keys.Enter)))
            {
                OnSelectEntry(selectedEntry);
            }
            else if (keyboardState.IsKeyDown(Keys.Escape) && !lastKeyboardState.IsKeyDown(Keys.Escape))
            {
                OnCancel();
            }
        }
示例#4
0
        public override void HandleInput(InputState input)
        {
            base.HandleInput(input);

            for (int i = 0; i < 6; i++)
            {
                if (Settings.players[i].active == false && input.IsPlayerTurnLeft((PlayerNumber)i))
                {
                    Settings.players[i].active = true;
                    Settings.Game.num_players++;
                }
                else if (Settings.players[i].active == true && input.IsPlayerTurnRight((PlayerNumber)i))
                {
                    Settings.players[i].active = false;
                    Settings.Game.num_players--;
                }
            }

            if (Settings.Game.num_players > 1 && input.MenuSelect)
            {
                LoadingScreen.Load(ScreenManager, true, new GamePlayScreen());
                ExitScreen();
            }

            if (input.PauseGame)
            {
                const string message = "Are you sure you want to quit this game?";
                MessageBoxScreen confirmQuitMessageBox = new MessageBoxScreen(message);
                confirmQuitMessageBox.Accepted += ConfirmQuitMessageBoxAccepted;
                ScreenManager.AddScreen(confirmQuitMessageBox);
            }
        }
示例#5
0
        public override void HandleInput(InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            //Go back to the previous screen if the player presses the back button
            if (input.IsPauseGame(null))
            {
                Exit();
            }

            // Return to the main menu when a tap gesture is recognized
            if (input.Gestures.Count > 0)
            {
                GestureSample sample = input.Gestures[0];
                if (sample.GestureType == GestureType.Tap)
                {
                    Exit();

                    input.Gestures.Clear();
                }
            }
        }
        public override void HandleInput(InputState input)
        {
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Y, ControllingPlayer, out player))
            {
            #if XBOX
                Debug.Assert (ControllingPlayer != null);
                HighScores2.GoLoad(ControllingPlayer ?? PlayerIndex.One);
            #else

                HighScores2.DoWindowsLoadGame();
            #endif

                ScreenManager.AddScreen(new HighScoreScreen(), ControllingPlayer);
            }

            if (input.IsMenuCancel(ControllingPlayer, out player))
            {
                MediaPlayer.Stop();
            }

            songSelectionBox.HandleInput(input);
            if (songSelectionBox.SongCount <= 0 &&
                input.IsNewButtonPress(Buttons.A, null, out player))
            {
                return;
            }
            base.HandleInput(input);
        }
示例#7
0
        public override void HandleInput(AxiosGameScreen gameScreen, InputState input, GameTime gameTime)
        {
            base.HandleInput(gameScreen, input, gameTime);
            //if (gameScreen.Console != null && gameScreen.Console.Active)
            //    return;
            PlayerIndex p;
            Animate = false;

            if (input.IsKeyPressed(Keys.A, PlayerIndex.One, out p))
            {
                Move(Direction.Left);
            }

            if (input.IsKeyPressed(Keys.W, PlayerIndex.One, out p) && !jumping)
            {
                Move(Direction.Up);
                jumping = true;
            }
            //else if (input.IsKeyPressed(Keys.S, PlayerIndex.One, out p))
            //{
            //    Move(Direction.Down);
            //}
            if (input.IsKeyPressed(Keys.D, PlayerIndex.One, out p))
            {
                Move(Direction.Right);
            }
            else
            {
                //BodyPart.LinearVelocity = Vector2.Zero;
            }
        }
示例#8
0
 public bool Evaluate(InputState state, PlayerIndex? controllingPlayer, out PlayerIndex player)
 {
     ButtonPress buttonTest;
     KeyPress keyTest;
     if (newPressOnly)
     {
         buttonTest = state.IsNewButtonPress;
         keyTest = state.IsNewKeyPress;
     }
     else
     {
         buttonTest = state.IsButtonPressed;
         keyTest = state.IsKeyPressed;
     }
     foreach (Buttons button in buttons)
     {
         if (buttonTest(button, controllingPlayer, out player))
             return true;
     }
     foreach (Keys key in keys)
     {
         if (keyTest(key, controllingPlayer, out player))
             return true;
     }
     player = PlayerIndex.One;
     return false;
 }
示例#9
0
        public override void HandleInput(InputState input)
        {
            if (isLoading == true)
            {
                base.HandleInput(input);
                return;
            }

            foreach (var gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.Tap)
                {
                    // Create a new instance of the gameplay screen
                    gameplayScreen = new GameplayScreen();
                    gameplayScreen.ScreenManager = ScreenManager;

                    // Start loading the resources in additional thread
                    thread = new System.Threading.Thread(
                        new System.Threading.ThreadStart(gameplayScreen.LoadAssets));
                    isLoading = true;
                    thread.Start();
                }
            }

            base.HandleInput(input);
        }
示例#10
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            // Read in our gestures
            foreach(GestureSample gesture in input.Gestures) {
                if (single) { // if it is single player, just start the game
                    if(Configuration.GAME_TEST) {
                        SwitchScreen(Configuration.DEF_GAME);
                    } else {
                        SwitchScreen(game.ScreenType);
                    }
                    return;
                }

                if (gesture.GestureType == GestureType.Tap && !done) {
                    done = true;
                    text = "Waiting for other players...";

                    Sync((JArray data, double rand) => {
                        timeLeftTimer.Dispose(); // dispose of the timer so we don't decrement the time anymore
                        if(Configuration.GAME_TEST) {
                            SwitchScreen(Configuration.DEF_GAME);
                        } else {
                            SwitchScreen(game.ScreenType);
                        }
                    }, "tutorial", 13); // give other players 13 seconds to continue
                }
            }

            base.HandleInput(gameTime, input);
        }
示例#11
0
        public override void OnInput(InputState input)
        {
            Keys[] pressedKeys = input.NewPressedKeys().ToArray();
            for (int i = pressedKeys.Length - 1; i >= 0; i--)
            {
                Keys pressedKey = pressedKeys[i];
                int pressedKeyNum = (int)pressedKey;

                if (pressedKey >= Keys.A && pressedKey <= Keys.Z)
                {
                    Value += (char)((input.IsKeyPressed(Keys.LeftShift) || input.IsKeyPressed(Keys.RightShift)) ? pressedKeyNum : pressedKeyNum + 32);
                }
                else if (pressedKey == Keys.Space) Value += " ";
                else if (pressedKey == Keys.Back && Value.Length > 0) Value = Value.Substring(0, Value.Length - 1);

                //if (input.Mapping.Chars().ContainsKey(pressedKey)) Value += input.IsKeyPress(input.Mapping.Shift) ? input.Mapping.Chars()[pressedKey] : (char)(input.Mapping.Chars()[pressedKey] + 32);
                //else if (input.Mapping.Numbers().ContainsKey(pressedKey)) Value += input.Mapping.Numbers()[pressedKey].ToString();
                //else if (pressedKey == input.Mapping.Hyphen || pressedKey == Key.Minus) Value += input.IsKeyPress(Key.ShiftLeft) ? "_" : "-";
                //else if (pressedKey == input.Mapping.Point) Value += input.IsKeyPress(Key.ShiftLeft) ? ":" : ".";
                //else if (pressedKey == input.Mapping.Comma) Value += input.IsKeyPress(Key.ShiftLeft) ? ";" : ",";
                //else if (pressedKey == input.Mapping.Space) Value += " ";
                //else if (pressedKey == input.Mapping.Back && Value.Length > 0) Value = Value.Substring(0, Value.Length - 1);
            }
            base.OnInput(input);
        }
示例#12
0
        /// <summary>
        /// Evaluates the action against a given inputState.
        /// </summary>
        /// <param name="state">The InputState to test for the action.</param>
        /// <param name="controllingPlayer">The player to test, or null to allow any player.</param>
        /// <param name="player">If controllingPlayer is null, this is the player that performed the action.</param>
        /// <returns>True if the action occured, false otherwise.</returns>
        public bool Evaluate(InputState state, PlayerIndex? controllingPlayer, out PlayerIndex player)
        {
            // Figure out which delegate methods to map from the state which takes care of our "newPressOnly" logic
            ButtonPress buttonTest;
            KeyPress keyTest;
            if (newPressOnly)
            {
                buttonTest = state.IsNewButtonPress;
                keyTest = state.IsNewKeyPress;
            }
            else
            {
                buttonTest = state.IsButtonPressed;
                keyTest = state.IsKeyPressed;
            }

            // Now we simply need to invoke the appropriate methods for each button and key in our collections
            foreach (Buttons button in buttons)
            {
                if (buttonTest(button, controllingPlayer, out player))
                    return true;
            }
            foreach (Keys key in keys)
            {
                if (keyTest(key, controllingPlayer, out player))
                    return true;
            }

            // If we got here, the action is not matched.
            player = PlayerIndex.One;
            return false;
        }
示例#13
0
 /// <summary>
 /// Creates a new instance of the <see cref="Button"/> class.
 /// </summary>
 /// <param name="regularTexture">The name of the button's texture.</param>
 /// <param name="pressedTexture">The name of the texture to display when the 
 /// button is pressed.</param>
 /// <param name="input">A <see cref="GameStateManagement.InputState"/> object
 /// which can be used to retrieve user input.</param>
 /// <param name="cardGame">The associated card game.</param>
 /// <remarks>Texture names are relative to the "Images" content 
 /// folder.</remarks>
 public Button(string regularTexture, string pressedTexture, InputState input,
     CardsGame cardGame)
     : base(cardGame, null)
 {
     this.input = input;
     this.regularTexture = regularTexture;
     this.pressedTexture = pressedTexture;
 }
示例#14
0
 /// <summary>
 /// Constructs a new screen manager component.
 /// </summary>
 public ScreenManager(Game game)
     : base(game)
 {
     // we must set EnabledGestures before we can query for them, but
     // we don't assume the game wants to read them.
     TouchPanel.EnabledGestures = GestureType.None;
     this.input = new InputState(this);
 }
        /// <summary>
        /// Handle user input.
        /// </summary>
        /// <param name="input">User input information.</param>
        public override void HandleInput(InputState input)
        {
            if (input.IsPauseGame(null))
            {
                PauseCurrentGame();
            }

            base.HandleInput(input);
        }
 public override void HandleInput(InputState input)
 {
     // look for any taps that occurred and select any entries that were tapped
     foreach (GestureSample gesture in input.Gestures)
     {
         //check against the panel
     }
     base.HandleInput(input);
 }
		public override void HandleInput (InputState input)
		{
			if (isLoading == true)
            {
#if ANDROID || IOS || LINUX || WINDOWS
                // Exit the screen and show the gameplay screen 
					// with pre-loaded assets
				ExitScreen ();
				ScreenManager.AddScreen (gameplayScreen, null);
#endif						
				base.HandleInput (input);
				return;
			}
			PlayerIndex player;
			if (input.IsNewKeyPress (Microsoft.Xna.Framework.Input.Keys.Space, ControllingPlayer, out player) ||
			    input.IsNewKeyPress (Microsoft.Xna.Framework.Input.Keys.Enter, ControllingPlayer, out player) ||
			    input.MouseGesture.HasFlag(MouseGestureType.LeftClick) ||
			    input.IsNewButtonPress (Microsoft.Xna.Framework.Input.Buttons.Start, ControllingPlayer, out player)) {
				// Create a new instance of the gameplay screen
				gameplayScreen = new GameplayScreen ();
				gameplayScreen.ScreenManager = ScreenManager;

                // Start loading the resources in additional thread
#if !LINUX && !WINDOWS
#if MACOS
				// create a new thread using BackgroundWorkerThread as method to execute
				thread = new Thread (LoadAssetsWorkerThread as ThreadStart);
#else     
				thread = new System.Threading.Thread (new System.Threading.ThreadStart (gameplayScreen.LoadAssets));    
#endif
				isLoading = true;
				// start it
				thread.Start ();
#else
                isLoading = true;
#endif
			}

			foreach (var gesture in input.Gestures) {
				if (gesture.GestureType == GestureType.Tap) {
					// Create a new instance of the gameplay screen
					gameplayScreen = new GameplayScreen ();
					gameplayScreen.ScreenManager = ScreenManager;

#if ANDROID || IOS	|| LINUX || WINDOWS
                    isLoading = true;									
#else						
					// Start loading the resources in additional thread
					thread = new System.Threading.Thread (new System.Threading.ThreadStart (gameplayScreen.LoadAssets));
					isLoading = true;
					thread.Start ();
#endif					
				}
			}

			base.HandleInput (input);
		}
 public override void HandleInput(InputState input)
 {
     PlayerIndex player;
     if (input.IsMenuSelect(null, out player))
     {
         exit = true;
         ControllingPlayer = player;
     }
     base.HandleInput(input);
 }
示例#19
0
 public override void HandleInput(GameTime gameTime, InputState input)
 {
     //input.
     if (input.CurrentKeyboardStates[0].GetPressedKeys().Length > 0 ||
         input.CurrentGamePadStates[0].IsButtonDown(Buttons.A | Buttons.Start | Buttons.Back) ||
         input.MouseState.LeftButton == ButtonState.Pressed)
     {
         _duration = TimeSpan.Zero;
     }
 }
示例#20
0
 /// <summary>
 /// Creates a new instance of the <see cref="BetGameComponent"/> class.
 /// </summary>
 /// <param name="players">A list of participating players.</param>
 /// <param name="input">An instance of 
 /// <see cref="GameStateManagement.InputState"/> which can be used to 
 /// check user input.</param>
 /// <param name="theme">The name of the selcted card theme.</param>
 /// <param name="cardGame">An instance of <see cref="CardsGame"/> which
 /// is the current game.</param>
 public BetGameComponent(List<Player> players, InputState input,
     string theme, CardsGame cardGame)
     : base(cardGame.Game)
 {
     this.players = players;
     this.theme = theme;
     this.cardGame = cardGame;
     this.input = input;
     chipsAssets = new Dictionary<int, Texture2D>();
 }
示例#21
0
        public override void HandleInput(InputState input)
        {
            tracker.HandleInput(input);

            if(ChildCount > 0)
            {
                // Only the child that currently has focus gets input
                int current = tracker.CurrentPage;
                this[current].HandleInput(input);
            }
        }
        /// <summary>
        /// Input helper method provided by GameScreen.  Packages up the various /// input values for ease of use.
        /// </summary>
        /// <param name="input">The state of the gamepads</param>
        public override void HandleInput(InputState input)
        {
            PlayerIndex player;

            if (input == null)
                throw new ArgumentNullException("input");

            if (input.IsNewKeyPress(Keys.F12, out player))
            {
                if (!Windows.UI.ViewManagement.ApplicationView
                        .GetForCurrentView().IsFullScreen)
                    Windows.UI.ViewManagement.ApplicationView
                        .GetForCurrentView().TryEnterFullScreenMode();
                else
                    Windows.UI.ViewManagement.ApplicationView
                        .GetForCurrentView().ExitFullScreenMode();
            }

            if (gameOver)
            {
                if (input.IsPauseGame())
                {
                    FinishCurrentGame();
                }

                if (input.IsNewKeyPress(Keys.Space, out player)
                    || input.IsNewKeyPress(Keys.Enter, out player))
                {
                    FinishCurrentGame();
                }

                if (input.IsNewGamePadButtonPress(Buttons.A, out player)
                    || input.IsNewGamePadButtonPress(Buttons.Start, out player))
                {
                    FinishCurrentGame();
                }

                if (input.IsNewMouseButtonPress(MouseButtons.LeftButton,
                                                out player))
                {
                    FinishCurrentGame();
                }

                foreach (GestureSample gestureSample in input.Gestures)
                {
                    if (gestureSample.GestureType == GestureType.Tap)
                    {
                        FinishCurrentGame();
                    }
                }

                return;
            }
        }
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            base.HandleInput(gameTime, input);

            PlayerIndex playerIndex;

            if (pauseAction.Evaluate(input, ControllingPlayer, out playerIndex))
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), null);
            }
        }
示例#24
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];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];
        }
示例#25
0
 public master(PhysicsSimulator physics, Game game)
 {
     //random = new Random();
     this.physics = physics;
     this.game = game;
     input = new InputState();
     bullets = new unitm<bullet>(300, UnitID.bullet, this);
     //pickups = new unitm<pickup>(12, UnitID.pickup, this);
     players = new unitm<player>(towersmash.maxnumplayers, UnitID.player, this);
     towers = new unitm<tower>(30, UnitID.tower, this);
     obstacles = new obstaclem(pvp.arenarect, this);
     particles = new particleeffects(this);
 }
示例#26
0
 public override void HandleInput(InputState input)
 {
     // look for any taps that occurred and select any entries that were tapped
     foreach (GestureSample gesture in input.Gestures)
     {
         if (gesture.GestureType == GestureType.Tap)
         {
             //out we go.
             ExitSelf();
         }
     }
     base.HandleInput(input);
 }
        public override void HandleInput(InputState input)
        {
            // cancel the current screen if the user presses the back button
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, null, out player))
            {
                ExitScreen();
            }

            if(RootControl != null)
                RootControl.HandleInput(input);

            base.HandleInput(input);
        }
 public override void HandleInput(InputState input)
 {
     foreach(GestureSample gs in input.Gestures)
     {
         if (gs.GestureType == GestureType.Tap)
         {
             Vector2 finalPosition = GetFinalPosition();
             Rectangle location = new Rectangle((int)finalPosition.X, (int)finalPosition.Y, (int)Size.X, (int)Size.Y);
             if(location.Contains(new Point((int)gs.Position.X, (int)gs.Position.Y)))
             {
                 levelScreen.OnLevelSelected(myWave);
             }
         }
     }
 }
示例#29
0
        public bool Evaluate(InputState state)
        {
            ButtonPress buttonTest;

            if (newPressOnly)
                buttonTest = state.IsNewButtonPress;
            else
                buttonTest = state.IsButtonPressed;

            foreach (Buttons button in buttons)
                if (buttonTest(button))
                    return true;

            return false;
        }
        /// <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];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            // if the user pressed the back button, we return to the main menu
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                LoadingScreen.Load(ScreenManager, false, ControllingPlayer,
                                    new MenuBackgroundScreen("mainMenuBackground"),
                                    new MainMenuScreen());
            }
            else
            {
                // 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();

                playerPosition += movement * 2;
            }
        }
示例#31
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(GameTime gameTime, InputState input)
 {
 }
示例#32
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // we cancel the current menu screen if the user presses the back button
            PlayerIndex player;

            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                OnCancel(player);
            }

            if (input.IsMenuDown(ControllingPlayer))
            {
                if (selectedEntry < menuEntries.Count - 1)
                {
                    selectedEntry += 1;
                }
            }

            if (input.IsMenuUp(ControllingPlayer))
            {
                if (selectedEntry > 0)
                {
                    selectedEntry -= 1;
                }
            }

            if (input.IsMenuSelect(ControllingPlayer, out player))
            {
                menuEntries[selectedEntry].OnSelectEntry(player);
            }

            if (input.MouseGesture.HasFlag(MouseGestureType.LeftClick))
            {
                Point clickLocation = new Point((int)input.CurrentMousePosition.X, (int)input.CurrentMousePosition.Y);
                // iterate the entries to see if any were tapped
                for (int i = 0; i < menuEntries.Count; i++)
                {
                    MenuEntry menuEntry = menuEntries[i];

                    if (GetMenuEntryHitBounds(menuEntry).Contains(clickLocation))
                    {
                        // select the entry. since gestures are only available on Windows Phone,
                        // we can safely pass PlayerIndex.One to all entries since there is only
                        // one player on Windows Phone.
                        OnSelectEntry(i, PlayerIndex.One);
                    }
                }
            }

            if (input.MouseGesture.HasFlag(MouseGestureType.Move))
            {
                Point clickLocation = new Point((int)input.CurrentMousePosition.X, (int)input.CurrentMousePosition.Y);
                // iterate the entries to see if any were tapped
                for (int i = 0; i < menuEntries.Count; i++)
                {
                    MenuEntry menuEntry = menuEntries[i];

                    if (GetMenuEntryHitBounds(menuEntry).Contains(clickLocation))
                    {
                        // select the entry. since gestures are only available on Windows Phone,
                        // we can safely pass PlayerIndex.One to all entries since there is only
                        // one player on Windows Phone.
                        //OnSelectEntry(i, PlayerIndex.One);
                        selectedEntry = i;
                    }
                }
            }

            // look for any taps that occurred and select any entries that were tapped
            foreach (GestureSample gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.Tap)
                {
                    // convert the position to a Point that we can test against a Rectangle
                    Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);

                    // iterate the entries to see if any were tapped
                    for (int i = 0; i < menuEntries.Count; i++)
                    {
                        MenuEntry menuEntry = menuEntries[i];

                        if (GetMenuEntryHitBounds(menuEntry).Contains(tapLocation))
                        {
                            // select the entry. since gestures are only available on Windows Phone,
                            // we can safely pass PlayerIndex.One to all entries since there is only
                            // one player on Windows Phone.
                            OnSelectEntry(i, PlayerIndex.One);
                        }
                    }
                }
            }
        }
示例#33
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];
            GamePadState  gamePadState      = input.CurrentGamePadStates[playerIndex];
            KeyboardState lastKeyboardState = input.LastKeyboardStates[playerIndex];
            GamePadState  lastGamePadState  = input.LastGamePadStates[playerIndex];

            // 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[playerIndex];



            if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
            else
            {
                // not sure if need this use player.position3
                Vector2 movement = Vector2.Zero;
                //windows 8 gestures monogame
                while (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gesture = TouchPanel.ReadGesture();

                    if (gesture.GestureType == GestureType.FreeDrag)
                    {
                        player.Position3 += gesture.Delta;
                    }
                }
                //mouse

                Vector2 mousePosition = new Vector2(currentMouseState.X, currentMouseState.Y);


                if (currentMouseState.RightButton == ButtonState.Pressed)
                {
                    Vector2 posDelta = mousePosition - player.Position3;
                    posDelta.Normalize();
                    posDelta         = posDelta * playerMoveSpeed;
                    player.Position3 = player.Position3 + posDelta;
                }
                // Otherwise move the player position.

                if (keyboardState.IsKeyDown(Keys.F))
                {
                }
                if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left))
                {
                    // player.Position3.X--;
                    movement.X--;
                    //add for scroll background
                    newBackground.BackgroundOffset -= 1;
                    newBackground.ParallaxOffset   -= 2;
                }



                if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right))
                {
                    // player.Position3.X++;
                    movement.X++;
                    //add for scroll backgorund
                    newBackground.BackgroundOffset += 1;
                    newBackground.ParallaxOffset   += 2;
                }


                if (keyboardState.IsKeyDown(Keys.W) || keyboardState.IsKeyDown(Keys.Up))
                {
                    // player.Position3.Y--;//
                    movement.Y--;
                }

                if (keyboardState.IsKeyDown(Keys.S) || keyboardState.IsKeyDown(Keys.Down))
                {
                    // player.Position3.Y++;//
                    movement.Y++;
                }

                Vector2 thumbstick = gamePadState.ThumbSticks.Left;
                // player.Position3.X += thumbstick.X;
                // player.Position3.X += thumbstick.Y;
                movement.X += thumbstick.X;
                movement.Y -= thumbstick.Y;
                // Make sure that the player does not go out of bounds
                player.Position3.X = MathHelper.Clamp(player.Position3.X, 0, ScreenManager.GraphicsDevice.Viewport.Width - (player.PlayerAnimation.FrameWidth * player.Scale));
                player.Position3.Y = MathHelper.Clamp(player.Position3.Y, 0, ScreenManager.GraphicsDevice.Viewport.Height - (player.PlayerAnimation.FrameHeight * player.Scale));



                //fire weapon normal

                if (currentMouseState.LeftButton == ButtonState.Pressed && previousMouseState.LeftButton == ButtonState.Released ||
                    keyboardState.IsKeyDown(Keys.Space) && lastKeyboardState.IsKeyUp(Keys.Space))
                {
                    AddProjectile(player.Position3 + new Vector2(player.Width / 2, player.Height / 2));

                    //todo
                    //weaon fire not hitting bottom


                    //AudioManager.PlaySound("laserSound");
                }



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



                //new player move
                player.Position3 += movement * playerMoveSpeed;
            }
        }
示例#34
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)
 {
 }