/// <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; } }
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); }
/// <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); } // 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); } } } } }
public override void HandleInput(InputState input) { // Test for the menuCancel action PlayerIndex player; if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player)) { OnCancel(player); } // Read in our gestures foreach (GestureSample gesture in input.Gestures) { // If we have a tap if (gesture.GestureType == GestureType.Tap) { // Test the tap against the buttons until one of the buttons handles the tap foreach (Button b in menuButtons) { if (b.HandleTap(gesture.Position)) { break; } } } } }
/// <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; // 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 BackgroundScreen(), new MainMenuScreen()); } else { // Otherwise move the player position. Vector2 movement = Vector2.Zero; if (movement.Length() > 1) { movement.Normalize(); } playerPosition += movement * 2; } ////My stuff var mouseState = Mouse.GetState(); if (mouseState.LeftButton == ButtonState.Pressed) { ///MathHelper.Clamp(player1.position.Y, 0, 10f); if (mouseState.Y < 400) { player1.isFlip = true; player1.position.Y = 5; player1.position.X = mouseState.X - player1.texture.Width / 2; } else { player1.position.X = mouseState.X - player1.texture.Width / 2; player1.position.Y = 770f; player1.isFlip = false; } } }
/// <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)) { LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new MenuBackgroundScreen("mainMenubackground"), new MainMenuScreen()); } // 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 < levelEntries.Count; i++) { LevelEntry lvlEntry = levelEntries[i]; if (GetMenuEntryHitBounds(lvlEntry).Contains(tapLocation)) { if (lvlEntry.starsDisplayed != Stars.LOCKED) { // 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 { Debug.WriteLine("Level locked"); } } } } if (gesture.GestureType == GestureType.HorizontalDrag) { TransitionPosition = -(float)gesture.Delta.X * 0.1f; if (gesture.Delta.X >= 10) { IsExiting = true; } else if (gesture.Delta.X <= -10) { IsExiting = true; } Debug.WriteLine(gesture.Delta.X); } } }
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) { // 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) { //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)); } }
/// <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)) { LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new MenuBackgroundScreen("mainMenubackground"), new MainMenuScreen()); } // 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 < levelEntries.Count; i++) { LevelEntry lvlEntry = levelEntries[i]; if (GetMenuEntryHitBounds(lvlEntry).Contains(tapLocation)) { if (lvlEntry.starsDisplayed != Stars.LOCKED) { // 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 { Debug.WriteLine("Level locked"); } } } } if (gesture.GestureType == GestureType.HorizontalDrag) { TransitionPosition = -(float)gesture.Delta.X*0.1f; if (gesture.Delta.X >= 10) { IsExiting = true; } else if (gesture.Delta.X <= -10) { IsExiting = true; } Debug.WriteLine(gesture.Delta.X); } } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(GameTime gameTime, InputState input) { // For input tests 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. #if WINDOWS || XBOX360 PlayerIndex playerIndex; // Move to the previous menu entry? if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry--; if (selectedEntry < 0) selectedEntry = menuEntries.Count - 1; } // Move to the next menu entry? if (menuDown.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry++; if (selectedEntry >= menuEntries.Count) selectedEntry = 0; } if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex)) { OnSelectEntry(selectedEntry, playerIndex); } else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); } #endif #if WINDOWS_PHONE //selectedEntry = 1; PlayerIndex player; if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player)) { OnCancel(player); } // look for any taps that occurred and select any entries that were tapped foreach (GestureSample gesture in input.Gestures) { //System.Diagnostics.Debugger.Break(); 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); } } } } #endif }
/// <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); }
/// <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(), new MainMenuScreen()); ScreenManager.AddScreen(new GameOptionsMenuScreen(), player); } //Input that affects the gameplay CheckForMovement(input); CheckForCharacterSwitch(input); CheckForAbilitiesUse(input); }
/// <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]; List<GestureSample> gestures = input.Gestures; foreach (GestureSample gs in input.Gestures) { if (gs.GestureType == GestureType.Tap) { if (p1s.destinationBox.Contains((int)gs.Position.X, (int)gs.Position.Y)) { currentPlayerIndex = 0; } else if (p2s.destinationBox.Contains((int)gs.Position.X, (int)gs.Position.Y)) { currentPlayerIndex = 1; } else if (p3s.destinationBox.Contains((int)gs.Position.X, (int)gs.Position.Y)) { currentPlayerIndex = 2; } } } if (input.TouchState.Count == 0) { players[currentPlayerIndex].velocity = new Vector2(0, 0); } foreach (TouchLocation touch in input.TouchState) { //Vector2 position = gs.Position; if ((touch.State == TouchLocationState.Pressed || touch.State == TouchLocationState.Moved)) { CheckForMovement(touch.Position); break; } } // 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 BackgroundScreen(), new MainMenuScreen()); } }
/// <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)) { keyPos.Y--; if (keyPos.Y < 0) { keyPos.Y = keys.Length - 1; } } // Move to the next menu entry? if (input.IsMenuDown(ControllingPlayer)) { keyPos.Y++; if (keyPos.Y > keys.Length-1) { keyPos.Y = 0; } } PlayerIndex playerIndex; if (input.IsMenuRight(ControllingPlayer)) { keyPos.X++; if (keyPos.X > keys[(int)keyPos.Y].Length - 1) { keyPos.X = 0; } } if (input.IsMenuLeft(ControllingPlayer)) { keyPos.X--; if (keyPos.X < 0) { keyPos.X = keys[(int)keyPos.Y].Length - 1; } } // Move to the next menu entry? // public bool IsNewButtonPress(Buttons button, PlayerIndex? controllingPlayer, // out PlayerIndex playerIndex) if ( input.IsNewButtonPress(Buttons.Y,ControllingPlayer, out playerIndex) ) { playerNameChars[selectedEntry] = ' '; selectedEntry = Math.Min(selectedEntry + 1, numNameChars - 1); playerNameMenuEntry.Text = (new string(playerNameChars, 0, playerNameChars.Length)); } // 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. if (input.IsNewButtonPress(Buttons.A, ControllingPlayer, out playerIndex) ) { OnSelectEntry(selectedEntry, playerIndex); } else if (input.IsNewButtonPress(Buttons.B, ControllingPlayer, out playerIndex) || input.IsNewButtonPress(Buttons.X, ControllingPlayer, out playerIndex) ) { OnCancel(playerIndex); } else if (input.IsNewButtonPress(Buttons.Start, ControllingPlayer, out playerIndex)) { CompleteEntry(); } }
/// <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) { PlayerIndex pindex; if (input.IsNewButtonPress(Buttons.Back, PlayerIndex.One, out pindex)) { //SEND A BACK MESSAGE OnBackButton(); } }
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; } } }
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); }
public virtual void HandleCursor(InputState input) { PlayerIndex player; Vector2 position = Camera.ConvertScreenToWorld(input.Cursor); if ((input.IsNewButtonPress(Buttons.A, PlayerIndex.One, out player) || input.IsNewMouseButtonPress(MouseButtons.LeftButton)) && _fixedMouseJoint == null) { Fixture savedFixture = World.TestPoint(position); if (savedFixture != null && savedFixture.UserData is SimpleAxiosGameObject && ((SimpleAxiosGameObject)(savedFixture.UserData)).AllowAutomaticMouseJoint) { Body body = savedFixture.Body; _fixedMouseJoint = new FixedMouseJoint(body, position); _fixedMouseJoint.MaxForce = 1000.0f * body.Mass; World.AddJoint(_fixedMouseJoint); body.Awake = true; } } if ((input.IsNewButtonRelease(Buttons.A, ControllingPlayer.Value, out player) || input.IsNewMouseButtonRelease(MouseButtons.LeftButton)) && _fixedMouseJoint != null) { World.RemoveJoint(_fixedMouseJoint); _fixedMouseJoint = null; } if (_fixedMouseJoint != null) { _fixedMouseJoint.WorldAnchorB = position; } }
/// <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; } }
/// <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 }
/// <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; // 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 BackgroundScreen(), new MainMenuScreen()); } else { // Otherwise move the player position. Vector2 movement = Vector2.Zero; if (movement.Length() > 1) movement.Normalize(); playerPosition += movement * 2; } ////My stuff var mouseState = Mouse.GetState(); if (mouseState.LeftButton == ButtonState.Pressed) { ///MathHelper.Clamp(player1.position.Y, 0, 10f); if (mouseState.Y < 400) { player1.isFlip = true; player1.position.Y = 5; player1.position.X = mouseState.X - player1.texture.Width / 2; } else { player1.position.X = mouseState.X - player1.texture.Width / 2; player1.position.Y = 770f; player1.isFlip = false; } } }
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); }