IsNewKeyPress() public method

Helper for checking if a key was newly pressed during this update. The controllingPlayer parameter specifies which player to read input for. If this is null, it will accept input from any player. When a keypress is detected, the output playerIndex reports which player pressed it.
public IsNewKeyPress ( Keys key ) : bool
key Keys
return bool
        /// <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;
            }
        }
Beispiel #2
0
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Remove all MedalsMenuScreens open
                GameScreen[] screens = ScreenManager.GetScreens();
                for (int i = screens.Length - 1; i >= 0; i--)
                {
                    if (screens[i] is MedalsMenuScreen)
                    {
                        screens[i].ExitScreen();
                    }
                }
            }
            else if (input.IsNewButtonPress(Buttons.LeftShoulder, ControllingPlayer, out playerIndex) ||
                     input.IsNewKeyPress(Keys.Left, ControllingPlayer, out playerIndex))
            {
                if (medalStartIndex != 0)
                {
                    screenChangeSFX.Play(0.5f, -0.1f, 0.0f);
                    // Remove this page of medals
                    OnCancel(playerIndex);
                }
            }
            else if (input.IsNewButtonPress(Buttons.RightShoulder, ControllingPlayer, out playerIndex) ||
                     input.IsNewKeyPress(Keys.Right, ControllingPlayer, out playerIndex))
            {
                // Add a new page of medals if needed
                if (medalStartIndex + MEDALS_PER_SCREEN < ActivePlayer.Profile.MedalList.Count)
                {
                    screenChangeSFX.Play(0.5f, 0.1f, 0.0f);
                    ScreenManager.AddScreen(new MedalsMenuScreen(medalStartIndex + MEDALS_PER_SCREEN, 0),
                                            ActivePlayer.PlayerIndex);
                }
            }
        }
        public override void HandleInput(InputState input)
        {
            //base.HandleInput(input);
            PlayerIndex junk;
            for (int i = 0; i < 4; i++)
            {
                //If the player hit A to join
                if (input.IsNewButtonPress(Buttons.A, (PlayerIndex)i, out junk) && !towersmash.players[i])
                {
                    towersmash.players[i] = true;
                }
                    //else if the player hit B to leave
                else if (input.IsNewButtonPress(Buttons.B, (PlayerIndex)i, out junk) && towersmash.players[i])
                {
                    towersmash.players[i] = false;
                }
                //If the player moves up the list
                if (towersmash.players[i] && input.IsNewButtonPress(Buttons.RightShoulder, (PlayerIndex)i, out junk))
                {
                    player_selection[i]++;
                    if (player_selection[i] > character_number)
                        player_selection[i] = 0;
                }
                //If the player moves down the list
                if (towersmash.players[i] && input.IsNewButtonPress(Buttons.LeftShoulder, (PlayerIndex)i, out junk))
                {
                    player_selection[i]--;
                    if (player_selection[i] < 0)
                        player_selection[i] = character_number;
                }
            }
            //If anyone wants to start the game
            if(input.IsNewButtonPress(Buttons.Start, null, out junk))
            {
                towersmash.updatenumberofplayers();
                if (towersmash.numberofplayers > 1)
                {
                    base.OnCancel(junk);
                    LoadingScreen.Load(ScreenManager, true, junk, new pvp(ScreenManager));
                }
                else
                {
                    MessageBoxScreen messagebox = new MessageBoxScreen("Must have at least 2 players ready for battle!");
                    ScreenManager.AddScreen(messagebox, null);
                }
            }
            //If anyone wants to go back to the main menu
            if (input.IsNewButtonPress(Buttons.Back, null, out junk))
            {
                base.OnCancel(junk);
            }

            //Quick hack for me on the keyboard
            if (input.IsNewKeyPress(Keys.Enter, null, out junk))
            {
                towersmash.numberofplayers = 2;
                towersmash.players[0] = true;
                towersmash.players[1] = true;
                towersmash.players[2] = false;
                towersmash.players[3] = false;
                towersmash.characters[0] = playertype.bashy;
                towersmash.characters[1] = playertype.shifty;
                base.OnCancel(junk);
                LoadingScreen.Load(ScreenManager, true, junk, new pvp(ScreenManager));
            }
        }
Beispiel #4
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 WINDOWS
            // Take care of Keyboard input
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

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

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }
            else if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out player) ||
                input.IsNewKeyPress(Keys.Space, ControllingPlayer, out player))
            {
                OnSelectEntry(selectedEntry, player);
            }


            MouseState state = Mouse.GetState();
            if (state.LeftButton == ButtonState.Released)
            {
                if (isMouseDown)
                {
                    isMouseDown = false;
                    // convert the position to a Point that we can test against a Rectangle
                    Point clickLocation = new Point(state.X, state.Y);

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

                        if (menuEntry.Destination.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);
                        }
                    }
                }
            }
            else if (state.LeftButton == ButtonState.Pressed)
            {
                isMouseDown = true;

                // convert the position to a Point that we can test against a Rectangle
                Point clickLocation = new Point(state.X, state.Y);

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

                    if (menuEntry.Destination.Contains(clickLocation))
                        selectedEntry = i;
                }
            }
#elif XBOX
            // Take care of Gamepad input
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

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

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }
            else if (input.IsNewButtonPress(Buttons.A, ControllingPlayer, out player))
                OnSelectEntry(selectedEntry, player);

#elif WINDOWS_PHONE
            // 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 (menuEntry.Destination.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);
                        }
                    }
                }
            }
#endif
        }
		public override void HandleInput (InputState input)
		{
			if (isLoading == true) {
				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 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 ();

			}

			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);
		}
Beispiel #6
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 WINDOWS
            // Take care of Keyboard input
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

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

                if (selectedEntry >= menuEntries.Count)
                {
                    selectedEntry = 0;
                }
            }
            else if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out player) ||
                     input.IsNewKeyPress(Keys.Space, ControllingPlayer, out player))
            {
                OnSelectEntry(selectedEntry, player);
            }


            MouseState state = Mouse.GetState();
            if (state.LeftButton == ButtonState.Released)
            {
                if (isMouseDown)
                {
                    isMouseDown = false;
                    // convert the position to a Point that we can test against a Rectangle
                    Point clickLocation = new Point(state.X, state.Y);

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

                        if (menuEntry.Destination.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);
                        }
                    }
                }
            }
            else if (state.LeftButton == ButtonState.Pressed)
            {
                isMouseDown = true;

                // convert the position to a Point that we can test against a Rectangle
                Point clickLocation = new Point(state.X, state.Y);

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

                    if (menuEntry.Destination.Contains(clickLocation))
                    {
                        selectedEntry = i;
                    }
                }
            }
#elif XBOX
            // Take care of Gamepad input
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

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

                if (selectedEntry >= menuEntries.Count)
                {
                    selectedEntry = 0;
                }
            }
            else if (input.IsNewButtonPress(Buttons.A, ControllingPlayer, out player))
            {
                OnSelectEntry(selectedEntry, player);
            }
#elif WINDOWS_PHONE
            // 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 (menuEntry.Destination.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);
                        }
                    }
                }
            }
#endif
        }
        public void HandleInput(InputState input)
        {
            int oldSelected = selected;
            int oldLibrary = libraryIndex;

            if (input.IsMenuDown(screen.ControllingPlayer))
            {
                if (selected < library.Count - 1)
                {
                    ++selected;
                    if (selected == numEntries + index)
                    {
                        ++index;
                    }
                    loadAroundIndex(selected);
                }
            }
            if (input.IsMenuUp(screen.ControllingPlayer))
            {
                if (selected > 0)
                {
                    --selected;
                    if (selected == index - 1)
                    {
                        --index;
                    }
                    loadAroundIndex(selected);
                }
            }

            PlayerIndex player;

            if (input.IsNewButtonPress(Buttons.X, screen.ControllingPlayer, out player))
            {
                MediaPlayer.Play(library[selected]);
            }

            if (input.IsNewButtonPress(Buttons.LeftShoulder, screen.ControllingPlayer, out player) ||
                input.IsNewKeyPress(Keys.Left, screen.ControllingPlayer, out player))
            {
                if (libraryIndex > 0)
                {
                    --libraryIndex;
                    mediaSourceName = MediaSource.GetAvailableMediaSources()[libraryIndex].Name;
                    library = new MediaLibrary(MediaSource.GetAvailableMediaSources()[libraryIndex]).Songs;
                    index = 0;
                    selected = 0;
                    initializeSongDataArray();
                }
            }
            if (input.IsNewButtonPress(Buttons.RightShoulder, screen.ControllingPlayer, out player) ||
                input.IsNewKeyPress(Keys.Right, screen.ControllingPlayer, out player))
            {
                if (libraryIndex < MediaSource.GetAvailableMediaSources().Count - 1)
                {
                    ++libraryIndex;
                    mediaSourceName = MediaSource.GetAvailableMediaSources()[libraryIndex].Name;
                    library = new MediaLibrary(MediaSource.GetAvailableMediaSources()[libraryIndex]).Songs;
                    index = 0;
                    selected = 0;
                    initializeSongDataArray();
                }
            }

            if (input.IsNewButtonPress(Buttons.RightTrigger, screen.ControllingPlayer, out player))
            {
                if (library.Count > 0)
                {
                    char c = '0';
                    // Skip ahead artist letter

                    if (SongDataArray[selected].Artist.Length > 0)
                    {
                        c = SongDataArray[selected].Artist.ToLower()[0];
                    }
                    int newIndex;
                    for (newIndex = selected; newIndex < library.Count; ++newIndex)
                    {
                        loadAroundIndex(newIndex);
                        if (SongDataArray[newIndex].Artist.Length == 0)
                            continue;
                        if (SongDataArray[newIndex].Artist.ToLower()[0] != c)
                            break;
                    }
                    selected = Math.Min(newIndex, library.Count - 1);
                    index = selected;
                }
            }

            if (input.IsNewButtonPress(Buttons.LeftTrigger, screen.ControllingPlayer, out player))
            {
                if (library.Count > 0)
                {
                    char c = 'z';
                    // Skip back artist letter
                    if (SongDataArray[selected].Artist.Length > 0)
                    {
                        c = SongDataArray[selected].Artist.ToLower()[0];
                    }
                    int newIndex;
                    bool nextLetter = false;
                    for (newIndex = selected; newIndex >= 0; --newIndex)
                    {
                        loadAroundIndex(newIndex);
                        if (SongDataArray[newIndex].Artist.Length == 0)
                            continue;
                        if (SongDataArray[newIndex].Artist.ToLower()[0] != c && nextLetter)
                        {
                            newIndex++;
                            break;
                        }
                        if (SongDataArray[newIndex].Artist.ToLower()[0] != c)
                        {
                            c = SongDataArray[newIndex].Artist.ToLower()[0];
                            nextLetter = true;
                        }
                    }
                    selected = Math.Max(newIndex, 0);
                    index = selected;
                }
            }

            if (oldSelected != selected || libraryIndex != oldLibrary)
            {
                if (library.Count > selected)
                {
                    MediaPlayer.Play(library[selected]);
                    NarlyGame.currentSong = library[selected].Name;
                }
            }
        }
        private void HandleCamera(InputState input, GameTime gameTime)
        {
            Vector2 camMove = Vector2.Zero;

            if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Up))
            {
                camMove.Y -= 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Down))
            {
                camMove.Y += 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Left))
            {
                camMove.X -= 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Right))
            {
                camMove.X += 10f * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.PageUp))
            {
                Camera.Zoom += 5f * (float)gameTime.ElapsedGameTime.TotalSeconds * Camera.Zoom / 20f;
            }
            if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.PageDown))
            {
                Camera.Zoom -= 5f * (float)gameTime.ElapsedGameTime.TotalSeconds * Camera.Zoom / 20f;
            }
            if (camMove != Vector2.Zero)
            {
                Camera.MoveCamera(camMove);
            }
            PlayerIndex i;
            if (input.IsNewKeyPress(Keys.Home, PlayerIndex.One, out i))
            {
                Camera.ResetCamera();
            }
        }
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            #if DEBUG
            // Control debug view
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Start, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.Shape);
                EnableOrDisableFlag(DebugViewFlags.DebugPanel);
                EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
                EnableOrDisableFlag(DebugViewFlags.Joint);
                EnableOrDisableFlag(DebugViewFlags.ContactPoints);
                EnableOrDisableFlag(DebugViewFlags.ContactNormals);
                EnableOrDisableFlag(DebugViewFlags.Controllers);
            }

            if (input.IsNewKeyPress(Keys.F1, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.Shape);
            }
            if (input.IsNewKeyPress(Keys.F2, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.DebugPanel);
                EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
            }
            if (input.IsNewKeyPress(Keys.F3, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.Joint);
            }
            if (input.IsNewKeyPress(Keys.F4, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.ContactPoints);
                EnableOrDisableFlag(DebugViewFlags.ContactNormals);
            }
            if (input.IsNewKeyPress(Keys.F5, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.PolygonPoints);
            }
            if (input.IsNewKeyPress(Keys.F6, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.Controllers);
            }
            if (input.IsNewKeyPress(Keys.F7, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.CenterOfMass);
            }
            if (input.IsNewKeyPress(Keys.F8, ControllingPlayer.Value, out player))
            {
                EnableOrDisableFlag(DebugViewFlags.AABB);
            }

            #endif

            if (_userAgent != null)
            {
                HandleUserAgent(input);
            }

            if (EnableCameraControl)
            {
                HandleCamera(input, gameTime);
            }

            if (HasCursor)
            {
                HandleCursor(input);
            }

            PlayerIndex i;
            if (input.IsNewButtonPress(Buttons.Back, PlayerIndex.One, out i) || input.IsNewKeyPress(Keys.Escape, PlayerIndex.One, out i))
            {
                //if (this.ScreenState == GameStateManagement.ScreenState.Active && this.TransitionPosition == 0 && this.TransitionAlpha == 1)
                //{ //Give the screens a chance to transition
                    CleanUp();
                    ExitScreen();

                //}
            }
            base.HandleInput(gameTime, input);
        }
Beispiel #10
0
 public override void HandleKeyboardInput(InputState input)
 {
     PlayerIndex player;
     if (input.IsNewKeyPress(Keys.Space, out player) || input.IsNewKeyPress(Keys.Enter, out player))
     {
         OnSelectEntry(selectedEntry, PlayerIndex.One);
     }
     else if (input.IsNewKeyPress(Keys.Escape, out player))
     {
         OnCancel(player);
     }
     else if (input.IsNewKeyPress(Keys.Up, out player))
     {
         if (selectedEntry > 0)
             selectedEntry--;
     }
     else if (input.IsNewKeyPress(Keys.Down, out player))
     {
         if (selectedEntry < menuEntries.Count - 1)
             selectedEntry++;
     }
     else 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();
     }
 }
Beispiel #11
0
        public override void HandleInput(InputState input)
        {
            if (input.IsNewKeyPress(Keys.Escape)) ScreenManager.AddScreen(new PauseMenuScreen());
            //if(input.IsNewKeyPress(Keys.Back)) MapGeneration.Generate(map);
            if (_endOfWave && _waveFade>=1f)
            {
                if (!_trading && _tradecost > 0 && (Ship.Instance.PowerUpMeter > 0 || Ship.Instance.PowerUpLevel > 0) &&
                    (input.IsNewKeyPress(Keys.X) || input.IsNewKeyPress(Keys.Space) ||
                     (input.CurrentGamePadState.Buttons.A == ButtonState.Pressed &&
                      input.LastGamePadState.Buttons.A == ButtonState.Released) ||
                     (input.CurrentGamePadState.Triggers.Right > 0.2f && input.LastGamePadState.Triggers.Right < 0.2f)))
                {
                    _trading = true;
                    DoTrade();

                }
            }

            if (_endOfWave && _waveFade>=1f) return;

            if (_gameOver && _goTimer >= 1f)
            {
                if (input.IsNewKeyPress(Keys.X) || input.IsNewKeyPress(Keys.Space) || input.IsNewKeyPress(Keys.Enter) || input.IsNewKeyPress(Keys.Escape))
                    LoadingScreen.Load(ScreenManager, false, new MainMenuScreen());
            }

            playerShip.HandleInput(input);
            base.HandleInput(input);
        }
 /// <summary>
 /// Responds to user input, capturing...
 /// </summary>
 public override void HandleInput(InputState input)
 {
     if (parentSlideMenu.IsPlaying) // If Playing, don't accept input
         return;
     PlayerIndex requesteeIndex;
     //press c to "capture"
     if(input.IsNewKeyPress(Keys.C, null,out requesteeIndex)){
         Captured();
     }
     //press "b" or the left arrow key to go back one slide
     if(input.IsNewKeyPress(Keys.B,null, out requesteeIndex)||input.IsNewKeyPress(Keys.Left, null, out requesteeIndex)){
         parentSlideMenu.PreviousSlide(requesteeIndex);
         this.ExitScreen();
     }
     //press u to undo last capture for this slide
     if (input.IsNewKeyPress(Keys.U, null, out requesteeIndex))
     {
         if (slideObjects.Count > 0)
         {
             slideObjects.RemoveAt(slideObjects.Count - 1);
         }
     }
     //press right arrow key to move forward one slide
     if (input.IsNewKeyPress(Keys.Right, null, out requesteeIndex))
     {
         parentSlideMenu.NextSlide(requesteeIndex);
     }
     //press "n" to create a new slide
     if (input.IsNewKeyPress(Keys.N, null, out requesteeIndex))
     {
         parentSlideMenu.NewSlide(requesteeIndex);
     }
     //press "z" to go to change to avatar1
     if (input.IsNewKeyPress(Keys.Z, null, out requesteeIndex))
     {
         parentSlideMenu.ChangeToAvatar(0);
         Console.Out.WriteLine("Changed to 0");
     }
     //press "x" to go to change to avatar2
     if (input.IsNewKeyPress(Keys.X, null, out requesteeIndex))
     {
         parentSlideMenu.ChangeToAvatar(1);
         Console.Out.WriteLine("Changed to 1");
     }
     //press "a" to go to change to avatar2
     if (input.IsNewKeyPress(Keys.A, null, out requesteeIndex))
     {
         parentSlideMenu.ChangeToAvatar(2);
         Console.Out.WriteLine("changed to 2");
     }
     //press "m" to go to slideMenu
     if (input.IsNewKeyPress(Keys.M, null, out requesteeIndex))
     {
         //TO DO implement menu!
     }
     if (input.IsNewKeyPress(Keys.Q, null, out requesteeIndex))
     {
         // DEBUGGING FUNCTION
         Console.Out.WriteLine("Num Slides in ScreenManager: " + ScreenManager.NumScreens);
         Console.Out.WriteLine("Num Hidden Slides in ScreenManager: " + ScreenManager.NumScreensHidden);
     }
     //Press 'r' to start recording. If you're recording, it will stop recording
     if (input.IsNewKeyPress(Keys.R, null, out requesteeIndex))
     {
         beginRecording();
     }
     //Press 'p' to play recording. If already playing, will stop it.
     if (input.IsNewKeyPress(Keys.P, null, out requesteeIndex))
     {
         playAudio();
     }
     if (input.IsNewKeyPress(Keys.W, null, out requesteeIndex))
     {
         // DEBUGGING FOR PLAY ALL FUNCTIONALITY
         parentSlideMenu.PlayAll(2000);
     }
 }
        /// <summary>
        /// Responds to user input, capturing...
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (parentSlideMenu.IsPlayingSlideshow) // If Playing, don't accept input
                return;
            PlayerIndex requesteeIndex;
            //SkeletonTracker skel = ScreenManager.Skeleton;
            //int leftHandX = skel.GetDisplayPosition(skel.Joints[JointType.HandLeft]);
              //  if(ScreenManager.Skeleton.
            #region keyboard commands
            //press c to "capture"
            if(input.IsNewKeyPress(Keys.C, null,out requesteeIndex)){
                Captured();
            }
            //press a to  cycle through avatars
            if (input.IsNewKeyPress(Keys.A, null, out requesteeIndex))
            {
                ScreenManager.CycleAvatar();
            }
            //press the left arrow key to go back one slide
            if(input.IsNewKeyPress(Keys.Left, null, out requesteeIndex)){
               // parentSlideMenu.PreviousSlide(requesteeIndex);
               // parentSlideMenu.PreviousSlide();
                //this.ExitScreen();
                PreviousSlide();
            }
               // press "b" to change the background
            if(input.IsNewKeyPress(Keys.B,null, out requesteeIndex)){

                backgroundIndex = (backgroundIndex + 1) % 4;

                //TODO: use gesture recognition to generate background indices.
                ChangeBackground(backgroundIndex);
            }
            //press u to undo last capture for this slide
            if (input.IsNewKeyPress(Keys.U, null, out requesteeIndex))
            {
                Undo();
                /*
                if (slideObjects.Count > 0)
                {
                    slideObjects.RemoveAt(slideObjects.Count - 1);
                }
                 * */
            }
            //press right arrow key to move forward one slide
            if (input.IsNewKeyPress(Keys.Right, null, out requesteeIndex))
            {
               // parentSlideMenu.NextSlide();
                NextSlide();
            }
            //press "n" to create a new slide
            if (input.IsNewKeyPress(Keys.N, null, out requesteeIndex))
            {
                parentSlideMenu.NewSlide();
            }
            //press "z" to go to change to avatar1
            if (input.IsNewKeyPress(Keys.Z, null, out requesteeIndex))
            {
                parentSlideMenu.ChangeToAvatar(0);
                //Console.Out.WriteLine("Changed to 0");
            }
            //press "x" to go to change to avatar2
            if (input.IsNewKeyPress(Keys.X, null, out requesteeIndex))
            {
                parentSlideMenu.ChangeToAvatar(1);
                //Console.Out.WriteLine("Changed to 1");
            }

            //press "v" to toggle voice recognition on or off
            if (input.IsNewKeyPress(Keys.V, null, out requesteeIndex))
            {
                ScreenManager.speechRecognitionOn = !ScreenManager.speechRecognitionOn;
            }
            if (input.IsNewKeyPress(Keys.Q, null, out requesteeIndex))
            {
                // DEBUGGING FUNCTION
                Console.Out.WriteLine("Num Slides in ScreenManager: " + ScreenManager.NumScreens);
                Console.Out.WriteLine("Num Hidden Slides in ScreenManager: " + ScreenManager.NumScreensHidden);
            }
            //Press 'r' to start recording. If you're recording, it will stop recording
            if (input.IsNewKeyPress(Keys.R, null, out requesteeIndex))
            {
                beginRecording();
            }
            //Press 'p' to play recording. If already playing, will stop it.
            if (input.IsNewKeyPress(Keys.P, null, out requesteeIndex))
            {

                playAudio();
            }
            if (input.IsNewKeyPress(Keys.W, null, out requesteeIndex))
            {
                // DEBUGGING FOR PLAY ALL FUNCTIONALITY
                parentSlideMenu.PlayAll(NarrationLength);
            }
            #endregion
        }
Beispiel #14
0
        // END DEBUG
        /// <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.
            //for(int playerIndex = 0; playerIndex < Math.Min(players.Count, InputState.MaxInputs);  ++playerIndex) {
            foreach(Player cP in players) {

                KeyboardState keyboardState = input.CurrentKeyboardStates[(int)cP.PI];
                GamePadState gamePadState = input.CurrentGamePadStates[(int)cP.PI];

                // 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[(int)cP.PI];

                if (input.IsPauseGame(cP.PI) || gamePadDisconnected)
                {
                    ScreenManager.AddScreen(new PauseMenuScreen(), cP.PI);
                }
                else if (curGameState == GameState.Placement)
                {
                    HandlePlacementInputButtons(input, cP);
                }
                else if (curGameState == GameState.Playing)
                {
                    HandleGameplayInputButtons(input, cP);
                }

                // Otherwise move the player position.
                if (true)
                {
                    Vector2 movement = Vector2.Zero;
                    if (true)//cP.PI == PlayerIndex.One)
                    {
                        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();

                    cP.pos += movement * 10;
                    //if (cP.pos.X < offset.X)
                    //    cP.pos.X = offset.X;
                    //if (cP.pos.Y < offset.Y)
                    //    cP.pos.Y = offset.Y;
                    //if (cP.pos.X > COLS * country.Width + offset.X - 1)
                    //    cP.pos.X = COLS * country.Width + offset.X - 1;
                    //if (cP.pos.Y > ROWS * country.Height + offset.Y - 1)
                    //    cP.pos.Y = ROWS * country.Height + offset.Y - 1;
                    if (cP.pos.X < 0)
                    {
                        if (OptionsMenuScreen.currentMap == OptionsMenuScreen.Map.World)
                            cP.pos.X = screenWidth;
                        else
                            cP.pos.X = 0;
                    }
                    if (cP.pos.Y < 0)
                        cP.pos.Y = 0;
                    if (cP.pos.X > screenWidth)
                    {
                        if (OptionsMenuScreen.currentMap == OptionsMenuScreen.Map.World)
                            cP.pos.X = 0;
                        else
                            cP.pos.X = screenWidth;
                    }
                    if (cP.pos.Y > screenHeight)
                        cP.pos.Y = screenHeight;

                    cP.hover = closestCountry(cP.pos);

                    // debug code for organizing world map
                    if (OptionsMenuScreen.currentMap == OptionsMenuScreen.Map.World)// && cP.PI == PlayerIndex.Two)
                    {
                        if (keyboardState.IsKeyDown(Keys.LeftControl))
                        {
                            offset += movement * 10;
                        }
                        else if (cP.selected == true)
                        {
                            if (keyboardState.IsKeyDown(Keys.LeftShift))
                                movement *= 10 / scale;

                            if (mode == 1)
                            {
                                Vector2 pos = cP.origin.getLocation() + 0.2f*movement;
                                cP.origin.setLocation(pos);
                            }
                            else if(mode == 2)
                            {
                                Vector2 pos = cP.origin.getLabelOffset() + movement;
                                cP.origin.setLabelOffset(pos);
                            }
                        }

                        PlayerIndex output;
                        if (input.IsNewKeyPress(Keys.P, cP.PI, out output))
                        {
                            Console.Out.WriteLine("\n\nTerr. Locations:\n");
                            float tempRescale = 1;
                            foreach (KeyValuePair<string, Country> c in territories)
                            {

                                //Country c = new Country(new Vector2(320.448f, 500.0194f), new Vector2(0, 0), content.Load<Texture2D>("territories/alaska"), noone, 4);
                                //territories.Add("alaska", c);
                                Vector2 loc = c.Value.getLocation() * tempRescale + offset / scale;
                                Vector2 label = c.Value.getLabelOffset() * tempRescale;
                                Console.Out.WriteLine("c = new Country(new Vector2(" + loc.X + "f, " + loc.Y + "f), new Vector2(" + label.X + "f, " + label.Y + "f), content.Load<Texture2D>(\"territories/"+c.Key+"\"), noone, 4);");
                                Console.Out.WriteLine("territories.Add(\""+c.Key+"\", c);");
                                //Console.Out.WriteLine(c.Key+": "+(loc));
                            }
                            foreach (Doodad d in doodads)
                            {
                                Vector2 loc = d.location * tempRescale + offset / scale;
                                string name = d.image.Name;
                                Console.Out.WriteLine("doodads.Add(new Doodad(new Vector2(" + loc.X + "f, " + loc.Y + "f), content.Load<Texture2D>(\"doodads/" + name + "\"), \""+name+"\", Color.White));");
                            }
                        }
                        if (input.IsNewKeyPress(Keys.S, cP.PI, out output))
                            mode = (mode + 1) % 3;
                        if (input.IsNewKeyPress(Keys.Add, cP.PI, out output))
                            scale *= 2f;
                        if (input.IsNewKeyPress(Keys.Subtract, cP.PI, out output))
                            scale *= 0.5f;
                        if (input.IsNewKeyPress(Keys.R, cP.PI, out output))
                            offset = new Vector2(0,0);

                    }
                }
            }
        }
		public override void HandleInput (InputState input)
		{
			if (isLoading == true)
            {
#if ANDROID || IPHONE || 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 MONOMAC
				// 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 || IPHONE	|| 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);
		}
Beispiel #16
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(GameTime gameTime, InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            var playerIndex = (int) ControllingPlayer.Value;

            var keyboardState = input.CurrentKeyboardStates[playerIndex];

            playerIndex = input.CurrentGamePadStates[playerIndex + 4].IsConnected ? playerIndex + 4 : playerIndex;
            var 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!
            var gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[playerIndex];

            PlayerIndex player;
            if (_pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
            else
            {
                // Otherwise handle input.
                #region temporary keybord controls

                if (keyboardState.IsKeyDown(Keys.Home))
                    _camera.Pitch += .01f;
                if (keyboardState.IsKeyDown(Keys.End))
                    _camera.Pitch -= .01f;

                if (keyboardState.IsKeyDown(Keys.PageDown))
                    _camera.Translate(new Vector3(0, -.02f, 0));
                if (keyboardState.IsKeyDown(Keys.PageUp))
                    _camera.Translate(new Vector3(0, .02f, 0));

                // temporary camera controls
                if (input.IsKeyPressed(Keys.I, null, out player))
                    _camera.Translate(Vector3.UnitZ*-0.1f);
                if (input.IsKeyPressed(Keys.K, null, out player))
                    _camera.Translate(Vector3.UnitZ*0.1f);
                if (input.IsKeyPressed(Keys.J, null, out player))
                    _camera.Translate(Vector3.UnitX*-0.1f);
                if (input.IsKeyPressed(Keys.L, null, out player))
                    _camera.Translate(Vector3.UnitX*0.1f);

                // player 1 temporary controls)););)
                if (input.IsNewKeyPress(Keys.W, null, out player))
                    _puzzleBoard1.Up();
                if (input.IsNewKeyPress(Keys.S, null, out player))
                    _puzzleBoard1.Down();
                if (input.IsNewKeyPress(Keys.A, null, out player))
                    _puzzleBoard1.Left();
                if (input.IsNewKeyPress(Keys.D, null, out player))
                    _puzzleBoard1.Right();

                if (input.IsNewKeyPress(Keys.Q, null, out player))
                    _puzzleBoard1.Select();
                if (input.IsNewKeyPress(Keys.E, null, out player))
                    _puzzleBoard1.Accept();
                if (input.IsNewKeyPress(Keys.R, null, out player))
                    _puzzleBoard1.Randomize();

                // player 2 temporary controls
                if (input.IsNewKeyPress(Keys.Up, null, out player))
                    _puzzleBoard2.Up();
                if (input.IsNewKeyPress(Keys.Down, null, out player))
                    _puzzleBoard2.Down();
                if (input.IsNewKeyPress(Keys.Left, null, out player))
                    _puzzleBoard2.Left();
                if (input.IsNewKeyPress(Keys.Right, null, out player))
                    _puzzleBoard2.Right();
                if (input.IsNewKeyPress(Keys.RightControl, null, out player))
                    _puzzleBoard2.Select();
                if (input.IsNewKeyPress(Keys.Enter, null, out player))
                    _puzzleBoard2.Accept();
                if (input.IsNewKeyPress(Keys.Back, null, out player))
                    _puzzleBoard2.Randomize();

                if (keyboardState.IsKeyDown(Keys.Z))
                    _camera.Yaw += .01f;
                if (keyboardState.IsKeyDown(Keys.X))
                    _camera.Yaw -= .01f;

                // DEBUG, remove ASAP
                if (input.IsNewKeyPress(Keys.D1, null, out player))
                {
                    SpawnUnit("menele_ranged", _player1, Vector3.Zero);
                }
                if (input.IsNewKeyPress(Keys.D2, null, out player))
                {
                    SpawnUnit("menel_ram", _player1, Vector3.Zero);
                }
                if (input.IsNewKeyPress(Keys.D3, null, out player))
                {
                    SpawnUnit("menele_ranged", _player2, Vector3.Zero);
                }
                if (input.IsNewKeyPress(Keys.D4, null, out player))
                {
                    SpawnUnit("menel_infantry", _player2, Vector3.Zero);
                }
                if (input.IsNewKeyPress(Keys.D5, null, out player))
                {
                    SpawnUnit("menel_boar", _player1, 6*Vector3.UnitY);
                }
                if (input.IsNewKeyPress(Keys.D6, null, out player))
                {
                    SpawnUnit("menel_boar", _player2, 6*Vector3.UnitY);
                }
                if (input.IsNewKeyPress(Keys.D7, null, out player))
                {
                    SpawnUnit("menel_infantry", _player2, Vector3.Zero);
                }
                if (input.IsNewKeyPress(Keys.D8, null, out player))
                {
                    SpawnUnit("menel_ram", _player2, Vector3.Zero);
                }
                // END OF DEBUG

                if (keyboardState.IsKeyDown(Keys.Delete))
                    _sceneRenderer.RenderShadows = !_sceneRenderer.RenderShadows;

                #endregion
                #region Gamepad controls

                Vector2 tsPos = gamePadState.ThumbSticks.Left;

                if (Math.Abs(tsPos.X) > 0.1f || Math.Abs(tsPos.Y) > 0.1f)
                    _camera.Translate(new Vector3(tsPos, 0.0f));

                if (gamePadState.IsButtonDown(Buttons.DPadUp))
                    _puzzleBoard1.Up();
                if (gamePadState.IsButtonDown(Buttons.DPadDown))
                    _puzzleBoard1.Down();
                if (gamePadState.IsButtonDown(Buttons.DPadLeft))
                    _puzzleBoard1.Left();
                if (gamePadState.IsButtonDown(Buttons.DPadRight))
                    _puzzleBoard1.Right();

                if (gamePadState.IsButtonDown(Buttons.X))
                    _puzzleBoard1.Select();
                if (gamePadState.IsButtonDown(Buttons.Y))
                    _puzzleBoard1.Accept();
                if (gamePadState.IsButtonDown(Buttons.A))
                    _puzzleBoard1.Randomize();

                #endregion
                _simulation.Tick(gameTime);
            }
        }