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(); } } }
/// <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); } }
/// <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) { 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(null), ControllingPlayer); } }
/// <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 KeyboardState keyboardState = input.CurrentKeyboardStates; // Check if the game was paused (esc) if (input.IsPauseGame()) { // Overlay the pause screen ScreenManager.AddScreen(new PauseMenuScreen()); } // Check if the start button was hit (enter) if (input.IsStartButton()) { // Move onto the match screen LoadingScreen.Load(ScreenManager, false, new GameplayScreen()); } }
/// <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; // get the keyboard state /** TODO - Kelner - Do gamepad shits **/ 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("pause"), ControllingPlayer); } // let the hero noodle on the input as well theHero.handleInput(keyboardState, _oldKeyState); // Kelner - store to know old state _oldKeyState = keyboardState; 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"); // Mouse handle var curMouseState = Mouse.GetState(); if (curMouseState.LeftButton == ButtonState.Pressed) { _mousePoint = _chessBoard.GetMatrixPosition(new Point(curMouseState.X, curMouseState.Y), 30); } // Look up inputs for the active player profile. if (ControllingPlayer != null) { var playerIndex = (int) ControllingPlayer.Value; var keyboardState = input.CurrentKeyboardStates[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! if (input.IsPauseGame(ControllingPlayer)) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Otherwise move the player position. var 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++; if (movement.Length() > 1) movement.Normalize(); _playerPosition += movement*2; } // Mouse } }
/// <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 void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); if (gameOver) { if (input.IsPauseGame(null)) { FinishCurrentGame(); } foreach (GestureSample gestureSample in input.Gestures) { if (gestureSample.GestureType == GestureType.Tap) { FinishCurrentGame(); } } return; } if (input.IsPauseGame(null)) { PauseCurrentGame(); } else if (!isTwoHumanPlayers && isFirstPlayerTurn && (playerOne.Catapult.CurrentState == CatapultState.Idle || playerOne.Catapult.CurrentState == CatapultState.Aiming)) { // Read all available gestures foreach (GestureSample gestureSample in input.Gestures) { if (gestureSample.GestureType == GestureType.FreeDrag) isDragging = true; else if (gestureSample.GestureType == GestureType.DragComplete) isDragging = false; playerOne.HandleInput(gestureSample); } } else if (!isPaused&&isTwoHumanPlayers && isFirstPlayerTurn && GlobalContext.PlayerIsFirstOnAppWarp &&(GlobalContext.joinedUsers.Length == 2)&& (playerOne.Catapult.CurrentState == CatapultState.Idle || playerOne.Catapult.CurrentState == CatapultState.Aiming)) { // Read all available gestures foreach (GestureSample gestureSample in input.Gestures) { if (gestureSample.GestureType == GestureType.FreeDrag) isDragging = true; else if (gestureSample.GestureType == GestureType.DragComplete) isDragging = false; playerOne.HandleInput(gestureSample); } } else if (!isPaused&&isTwoHumanPlayers && !isFirstPlayerTurn && !GlobalContext.PlayerIsFirstOnAppWarp && (GlobalContext.joinedUsers.Length == 2) && (playerTwo.Catapult.CurrentState == CatapultState.Idle || playerTwo.Catapult.CurrentState == CatapultState.Aiming)) { // Read all available gestures foreach (GestureSample gestureSample in input.Gestures) { if (gestureSample.GestureType == GestureType.FreeDrag) isDragging = true; else if (gestureSample.GestureType == GestureType.DragComplete) isDragging = false; (playerTwo as Human).HandleInput(gestureSample); } } }
public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); if (input.IsPauseGame(null)) { if (!gameOver) PauseCurrentGame(); else FinishCurrentGame(); } if (IsActive && !startScreen) { if (input.Gestures.Count > 0) { GestureSample sample = input.Gestures[0]; if (sample.GestureType == GestureType.Tap) { if (gameOver) FinishCurrentGame(); } } if (!gameOver) { // Rotate the maze according to accelerometer data Vector3 currentAccelerometerState = Accelerometer.GetState().Acceleration; if (Microsoft.Devices.Environment.DeviceType == DeviceType.Device) { //Change the velocity according to acceleration reading maze.Rotation.Z = (float)Math.Round(MathHelper.ToRadians( currentAccelerometerState.Y * 30), 2); maze.Rotation.X = -(float)Math.Round(MathHelper.ToRadians( currentAccelerometerState.X * 30), 2); } else if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator) { Vector3 Rotation = Vector3.Zero; if (currentAccelerometerState.X != 0) { if (currentAccelerometerState.X > 0) Rotation += new Vector3(0, 0, -angularVelocity); else Rotation += new Vector3(0, 0, angularVelocity); } if (currentAccelerometerState.Y != 0) { if (currentAccelerometerState.Y > 0) Rotation += new Vector3(-angularVelocity, 0, 0); else Rotation += new Vector3(angularVelocity, 0, 0); } // Limit the rotation of the maze to 30 degrees maze.Rotation.X = MathHelper.Clamp(maze.Rotation.X + Rotation.X, MathHelper.ToRadians(-30), MathHelper.ToRadians(30)); maze.Rotation.Z = MathHelper.Clamp(maze.Rotation.Z + Rotation.Z, MathHelper.ToRadians(-30), MathHelper.ToRadians(30)); } } } }
/// <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 { // 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> /// 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) { if (input == null) throw new ArgumentNullException ("input"); if (gameOver) { if (input.IsPauseGame (null)) { FinishCurrentGame (); } if (input.MouseGesture.HasFlag(MouseGestureType.LeftClick)) FinishCurrentGame(); foreach (GestureSample gestureSample in input.Gestures) { if (gestureSample.GestureType == GestureType.Tap) { FinishCurrentGame (); } } return; } if (NetworkSession != null) { if ((isFirstPlayerTurn && !NetworkSession.IsHost) || (!isFirstPlayerTurn && NetworkSession.IsHost)) return; } if (input.IsPauseGame (null)) { PauseCurrentGame (); } else if (isFirstPlayerTurn && (playerOne.Catapult.CurrentState == CatapultState.Idle || playerOne.Catapult.CurrentState == CatapultState.Aiming)) { // First we try with mouse input playerOne.HandleInput (input); isDragging = playerOne.isDragging; // Read all available gestures foreach (GestureSample gestureSample in input.Gestures) { if (gestureSample.GestureType == GestureType.FreeDrag) isDragging = true; else if (gestureSample.GestureType == GestureType.DragComplete) isDragging = false; playerOne.HandleInput (gestureSample); } } else if (!isFirstPlayerTurn && (playerTwo.Catapult.CurrentState == CatapultState.Idle || playerTwo.Catapult.CurrentState == CatapultState.Aiming)) { // First we try with mouse input playerTwo.HandleInput (input); isDragging = playerTwo.isDragging; // Read all available gestures foreach (GestureSample gestureSample in input.Gestures) { if (gestureSample.GestureType == GestureType.FreeDrag) isDragging = true; else if (gestureSample.GestureType == GestureType.DragComplete) isDragging = false; playerTwo.HandleInput (gestureSample); } } }
/// <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; } }
/* void NextLevel(PlayerIndexEventArgs e) { LoadingScreen.Load(ScreenManager, true, e.PlayerIndex, new GameplayScreen()); } */ /* * Lets the game respond to player input. Unlike the Update method, * this will only be called when the gameplay screen is active. */ public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; if (input.IsPauseGame(ControllingPlayer)) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } }
/// <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"); } // Mouse handle var curMouseState = Mouse.GetState(); if (curMouseState.LeftButton == ButtonState.Pressed) { _mousePoint = _chessBoard.GetMatrixPosition(new Point(curMouseState.X, curMouseState.Y), 30); } // Look up inputs for the active player profile. if (ControllingPlayer != null) { var playerIndex = (int)ControllingPlayer.Value; var keyboardState = input.CurrentKeyboardStates[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! if (input.IsPauseGame(ControllingPlayer)) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Otherwise move the player position. var 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++; } if (movement.Length() > 1) { movement.Normalize(); } _playerPosition += movement * 2; } // Mouse } }
//Handles touch input on the game play screen public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); if (input.IsPauseGame(null)) { ScreenManager.AddMenuScreen(this); } //Only handle input when the game is not over if (!GameOver) { // see if we have a new primary point down. when the first touch // goes down, we do hit detection to try and select one of our sprites. if (input.TouchState.Count > 0 && input.TouchState[0].State == TouchLocationState.Pressed) { // convert the touch position into a Point for hit testing Point touchPoint = new Point((int)input.TouchState[0].Position.X, (int)input.TouchState[0].Position.Y); //If the pause button has been pressed, invoke the pause button event handler if (PauseButton.ButtonRect.Contains(touchPoint)) { PauseButton.OnSelectEntry(); } // iterate our sprites to find which sprite is being touched. we iterate backwards // since that will cause sprites that are drawn on top to be selected before // sprites drawn on the bottom. selectedItem = null; for (int i = ItemBatch.Count - 1; i >= 0; i--) { Item currentItem = ItemBatch[i]; if (currentItem.ItemRectangle.Contains(touchPoint)) { selectedItem = currentItem; break; } } if (selectedItem != null) { selectedItem.IsDragged = true; // we also move the sprite to the end of the list so it // draws on top of the other sprites ItemBatch.Remove(selectedItem); ItemBatch.Add(selectedItem); } } foreach (GestureSample gestureSample in input.Gestures) { switch (gestureSample.GestureType) { case GestureType.FreeDrag: if (selectedItem != null) { if (!IsPaused) { //Move the position of the item along with the gesture selectedItem.Position += gestureSample.Delta; } } break; case GestureType.DragComplete: if (prevSelectedItem != null) { Point selectedItemPoint = new Point((int)selectedItem.Position.X, (int)selectedItem.Position.Y); prevSelectedItem.IsDragged = false; //The item lands in cage1 if(cage1.CageRectangle.Contains(selectedItemPoint)) { //The item was placed in the correct cage if (prevSelectedItem.GameItemNumber == Item.ItemNumber.ItemOne) { ItemImplode(prevSelectedItem); } //The item was not placed in the correct cage else { ItemExplode(prevSelectedItem); } } //The item lands in cage2 else if(cage2.CageRectangle.Contains(selectedItemPoint)) { //The item was placed in the correct cage if (prevSelectedItem.GameItemNumber == Item.ItemNumber.ItemTwo) { ItemImplode(prevSelectedItem); } //The item was not placed in the correct cage else { ItemExplode(prevSelectedItem); } } } break; case GestureType.Tap: //Even though GestureType.Tap is not a gesture used in this game, //for some reason if it is not used, the selected items will lose its state //and become frozen. Will fix this in future. if (selectedItem != null) { selectedItem.IsDragged = false; } break; } //Keep a copy of the previous item to be used for //acting on the drag complete state prevSelectedItem = selectedItem; } } }
public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); if (input.IsPauseGame(null)) { Exit(); } // Return to main menu when tap on the phone if (input.Gestures.Count > 0) { GestureSample sample = input.Gestures[0]; if (sample.GestureType == GestureType.Tap) { Exit(); input.Gestures.Clear(); } } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// Overriding to allow start,back,esc to unpause game /// </summary> public override void HandleInput(InputState input) { if (input.IsPauseGame(ControllingPlayer)) { OnCancel(ControllingPlayer ?? PlayerIndex.One); return; } base.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; } }
/// <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 { if (input.IsTankFire(ControllingPlayer)) { if (isPlayer1Turn) { double missileAngle = ((player1.shotAngle /** (Math.PI / 180)*/)); Console.WriteLine("The missile angle is: "+missileAngle); Projectile missile; if (missileAngle < 0) { missile = new Projectile(ScreenManager.Game, new Vector2(player1.cannonLocation.X - (float)(Math.Cos(missileAngle) * player1.cannonTexture.Height), (float)(Math.Sin(missileAngle) * player1.cannonTexture.Height) + player1.cannonLocation.Y - player1.texture.Height), new Vector2(-player1.force, player1.force)); } else { missile = new Projectile(ScreenManager.Game, new Vector2(player1.cannonLocation.X + (float)(Math.Cos(missileAngle) * player1.cannonTexture.Height), (float)(Math.Sin(missileAngle) * player1.cannonTexture.Height) + player1.cannonLocation.Y - player1.texture.Height), new Vector2(player1.force, player1.force)); } player1.fireMissile(missile); ScreenManager.Game.Components.Add(missile); } else { double missileAngle = ((player2.shotAngle /** (Math.PI / 180)*/)); Console.WriteLine("The missile angle is: " + missileAngle); Projectile missile; if (missileAngle < 0) { missile = new Projectile(ScreenManager.Game, new Vector2(player2.cannonLocation.X - (float)(Math.Cos(missileAngle) * player2.cannonTexture.Height), (float)(Math.Sin(missileAngle) * player2.cannonTexture.Height) + player2.cannonLocation.Y - player2.texture.Height), new Vector2(player2.force, player2.force)); } else { missile = new Projectile(ScreenManager.Game, new Vector2(player2.cannonLocation.X + (float)(Math.Cos(missileAngle) * player2.cannonTexture.Height), (float)(Math.Sin(missileAngle) * player2.cannonTexture.Height) + player2.cannonLocation.Y - player2.texture.Height), new Vector2(-player2.force, player2.force)); } player2.fireMissile(missile); ScreenManager.Game.Components.Add(missile); } } if (input.IsTankMovingLeft(ControllingPlayer)) { if (isPlayer1Turn) { player1.moveTank("Left"); } else { player2.moveTank("Left"); } } if (input.IsTankMovingRight(ControllingPlayer)) { if (isPlayer1Turn) { player1.moveTank("Right"); } else { player2.moveTank("Right"); } } if (input.IsAimUp(ControllingPlayer)) { if (isPlayer1Turn) { player1.changeAim("Up"); } else { player2.changeAim("Up"); } } if (input.IsAimDown(ControllingPlayer)) { if (isPlayer1Turn) { player1.changeAim("Down"); } else { player2.changeAim("Down"); } } if (input.IsAimChanged(ControllingPlayer) != -1) { if (isPlayer1Turn) { player1.shotAngle = input.IsAimChanged(ControllingPlayer); } else { player2.shotAngle = input.IsAimChanged(ControllingPlayer); } } } }
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; // get all of our input states keyboardState = Keyboard.GetState(); gamePadState_1 = GamePad.GetState(PlayerIndex.One); gamePadState_2 = GamePad.GetState(PlayerIndex.Two); gamePadStates[0] = gamePadState_1; gamePadStates[1] = gamePadState_2; touchState = TouchPanel.GetState(); accelerometerState = Accelerometer.GetState(); // Exit the game when back is pressed. //if (gamePadState_1.Buttons.Back == ButtonState.Pressed) // Exit(); if (input.IsPauseGame(null)) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { foreach (Player player in PlatformerGame.Players) { bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadStates[PlatformerGame.Players.IndexOf(player)].IsButtonDown(Buttons.A) || touchState.AnyTouch(); if (!player.IsAlive) { level.StartNewLife(player); } if (level.ReachedExit) { LoadNextLevel(); } } //check if both player is in the "no-man lands" if (players[0].Position.X == -999.9f && players[1].Position.X == -999.9f) { //players[attacker_id].Reset(Vector2.Zero); level.StartNewLife(players[attacker_id]); } } }
/// <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 KeyboardState keyboardState = input.CurrentKeyboardStates; // Check to see if the game is paused (esc) if (input.IsPauseGame()) { // Add the pause screen ScreenManager.AddScreen(new PauseMenuScreen()); } // Check to see if a menu element was selected and ensure that the match is not over if (input.IsMenuSelect() && !matchOver) { // Swap the turn state playerTurn = !playerTurn; // Check if it is the player's turn if (playerTurn) { // Let the player select a move player.SelectMove(enemy, PlayerInfo.Moves[selectedMove], playerSpriteManager); } else { // Select the move after the player has selected their move (Z pressed a second time) enemy.SelectMove(player, enemySpriteManager); } // Check to see if the enemy is dead if (enemy.CurrentHP <= 0) { // Increment the player wins and set the match to over PlayerInfo.Wins += 1; matchOver = true; // Play the downed animation enemySpriteManager.CurrentAnimation = "Down"; } // Check to see if the player is dead else if (player.CurrentHP <= 0) { // Increment the palyer losses and set the match to over PlayerInfo.Losses += 1; matchOver = true; // Play the downed animation playerSpriteManager.CurrentAnimation = "Down"; // Load enemy win anim } } // Check to see if the start button was pressed and ensure that the match is over if (input.IsStartButton() && matchOver) { // Load the training screen if there are still enemies to face if (PlayerInfo.Wins < 4) { LoadingScreen.Load(ScreenManager, false, new TrainingScreen()); } // Otherwise, wipe the save data and go back to the main menu else { SaveAndLoadGame.WipeSave(); LoadingScreen.Load(ScreenManager, false, new MainMenuScreen()); } } // Check if the player is navigating the menu to the left if (input.IsMenuLeft()) { // Decrement the selected move selectedMove--; // Wrap the selected move back around to end if it passes behind the start if (selectedMove < 0) { selectedMove = maxMoves - 1; } } // Check if the player is nagivating the menu to the right if (input.IsMenuRight()) { // Increment the selected move selectedMove++; // Wrap the selected move back to the beginning if it goes beyond the end if (selectedMove >= maxMoves) { selectedMove = 0; } } }
public override void HandleInput(InputState input) { bool buttonTouched = false; // User presses the back button if (input.IsPauseGame(null)) { if (!gamePaused) { gamePaused = true; } else { gamePaused = false; } } if (player.FinishedTransition) { if (input.TouchState.Count > 0 && input.TouchState[0].State == TouchLocationState.Pressed) { if (gamePaused) { //Resume game gamePaused = false; return; } if (pauseButton.ButtonRect.Contains((int)input.TouchState[0].Position.X, (int)input.TouchState[0].Position.Y)) { //Pause game buttonTouched = true; pauseButton.OnSelectEntry(); } if (!buttonTouched && !gamePaused) { // Check if the ninja is not currently jumping, falling, and using a power up if (player.PlayerState != Player.State.Jump && player.PlayerState != Player.State.Hit && player.PlayerState != Player.State.NinjaStarPowerUp && player.PlayerState != Player.State.Idle && player.PlayerState != Player.State.HorizontalEnemyPowerUp) { player.StartMotionPosition = player.Position; // Save the previous state to know where the ninja should jump (left/right) player.PreviousState = player.PlayerState; // Make the current state of the ninja to jump player.PlayerState = Player.State.Jump; AudioManager.PlaySound("PlayerJump"); } } } } }
// 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); } } } }
/// <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 (gameObjectManager.isLevelCompleted()) { ScreenManager.AddScreen(new LevelCompleteScreen(), ControllingPlayer); } else if(gameObjectManager.isGameOver()) { ScreenManager.AddScreen(new GameOverScreen(), ControllingPlayer); } else if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Otherwise move the player position. Vector2 movement = Vector2.Zero; if (keyboardState.IsKeyDown(Keys.Left)) { movement.X--; lastMove = 1; } if (keyboardState.IsKeyDown(Keys.Right)) { movement.X++; lastMove = 3; } if (keyboardState.IsKeyDown(Keys.Up)) { movement.Y--; lastMove = 0; } if (keyboardState.IsKeyDown(Keys.Down)) { movement.Y++; lastMove = 2; } #region codes if (keyboardState.IsKeyDown(Keys.D0)) { if (code.Count == 4) code.RemoveAt(0); if(code[code.Count-1] != 0) code.Add(0); } if (keyboardState.IsKeyDown(Keys.D1)) { if (code.Count == 4) code.RemoveAt(0); if (code[code.Count - 1] != 1) code.Add(1); } if (keyboardState.IsKeyDown(Keys.D2)) { if (code.Count == 4) code.RemoveAt(0); if (code[code.Count - 1] != 2) code.Add(2); } if (keyboardState.IsKeyDown(Keys.D3)) { if (code.Count == 4) code.RemoveAt(0); if (code[code.Count - 1] != 3) code.Add(3); } if (keyboardState.IsKeyDown(Keys.D4)) { if (code.Count == 4) code.RemoveAt(0); if (code[code.Count - 1] != 4) code.Add(4); } if (keyboardState.IsKeyDown(Keys.D5)) { if (code.Count == 4) code.RemoveAt(0); if (code[code.Count - 1] != 5) code.Add(5); } if (keyboardState.IsKeyDown(Keys.D6)) { if (code.Count == 4) code.RemoveAt(0); if (code[code.Count - 1] != 6) code.Add(6); } if (keyboardState.IsKeyDown(Keys.D7)) { if (code.Count == 4) code.RemoveAt(0); if (code[code.Count - 1] != 7) code.Add(7); } if (keyboardState.IsKeyDown(Keys.D8)) { if (code.Count == 4) code.RemoveAt(0); if (code[code.Count - 1] != 8) code.Add(8); } if (keyboardState.IsKeyDown(Keys.D9)) { if (code.Count == 4) code.RemoveAt(0); if (code[code.Count - 1] != 9) code.Add(9); } string strCode = string.Empty; foreach(int i in code) strCode += i.ToString(); switch (strCode) { case "4242": ScreenManager.AddScreen(new LevelCompleteScreen(), ControllingPlayer); break; case "1290": ScreenManager.AddScreen(new GameOverScreen(), ControllingPlayer); break; case "1212": MonsterGameObject.Ghost = true; break; } #endregion Vector2 thumbstick = gamePadState.ThumbSticks.Left; movement.X += thumbstick.X; movement.Y -= thumbstick.Y; if (movement.Length() > 1) movement.Normalize(); playerPosition += movement * 2; gameObjectManager.HandleInput(keyboardState); } }
/// <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 { 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)) { movement.X--; //add for scroll background newBackground.BackgroundOffset -= 1; newBackground.ParallaxOffset -= 2; } if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right)) { movement.X++; //add for scroll backgorund newBackground.BackgroundOffset += 1; newBackground.ParallaxOffset += 2; } if (keyboardState.IsKeyDown(Keys.W) || keyboardState.IsKeyDown(Keys.Up)) { movement.Y--; } if (keyboardState.IsKeyDown(Keys.S) || keyboardState.IsKeyDown(Keys.Down)) { movement.Y++; } Vector2 thumbstick = gamePadState.ThumbSticks.Left; 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; } }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); if (input.IsPauseGame(ControllingPlayer)) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { } }
/// <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 { // Otherwise move the player position. Vector2 movement = Vector2.Zero; #if WINDOWS if (keyboardState.IsKeyDown(Keys.Left)) playerRotDeg -= 1f; if (keyboardState.IsKeyDown(Keys.Right)) playerRotDeg += 1f; if (keyboardState.IsKeyDown(Keys.Up)) playerSpeed += 0.1f; if (keyboardState.IsKeyDown(Keys.Down)) playerSpeed -= 0.1f; #endif #if XBOX360 Vector2 thumbstick = gamePadState.ThumbSticks.Left; playerRotDeg += thumbstick.X * 2; playerSpeed += gamePadState.Triggers.Right / 2; playerSpeed -= gamePadState.Triggers.Left / 5; #endif setRotationAngle(playerRotDeg); movePlayer(playerSpeed); } }
/// <summary> /// Handle user input. /// </summary> /// <param name="input">The input to handle.</param> public override void HandleInput(InputState input) { if (IsActive) { if (input == null) throw new ArgumentNullException("input"); if (input.IsPauseGame(null)) { PauseCurrentGame(); } if (input.TouchState.Count > 0) { // We are about to handle touch input switch (inputState) { case TouchInputState.Idle: // We have yet to receive input, start grace period inputTimeMeasure = TimeSpan.Zero; inputState = TouchInputState.GracePeriod; lastPressInput = new List<TouchLocation>(); foreach (var touch in input.TouchState) { if (touch.State == TouchLocationState.Pressed) { lastPressInput.Add(touch); } } break; case TouchInputState.GracePeriod: // Do nothing during the grace period other than remembering // additional presses foreach (var touch in input.TouchState) { if (touch.State == TouchLocationState.Pressed) { lastPressInput.Add(touch); } } break; default: 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; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; MouseState mouseState = Mouse.GetState(); float scal = 1200f / 3200f; Vector2 mPos = new Vector2(mouseState.X / 100.0f / scal, mouseState.Y / 100.0f/scal); mPos.X = (int)mPos.X; mPos.Y = (int)mPos.Y; if (postIt == null) { circlePosition = null; marked.SetPosition(mPos); if (gameManager.IsThereAPath(new Vector2(mouseState.X / scal, mouseState.Y / scal))) marked.NotOk(); else marked.Ok(); } else { Vector2 textureVector = new Vector2(postItTexture.Width * postItTextureScal, postItTexture.Height * postItTextureScal); Rectangle postItRectangle = new Rectangle(((int)postIt.Value.X) - (((int)textureVector.X) / 2), ((int)postIt.Value.Y) - (((int)textureVector.Y) / 2), ((int)textureVector.X), ((int)textureVector.Y)); bool isClickedATower = gameManager.IsThereATower((Vector2)postIt / scal); bool upgradeAvailable = false; int tower = -1; int count; if (!isClickedATower) count = towers.Count; else if (gameManager.getTower((Vector2)postIt / scal).UpgradeAvailable()) { count = 2; upgradeAvailable = true; } else count = 1; for (int i = 0; i < count; i++) { Rectangle r = postItRectangle; int x; if (postItRichtungRechts) x = 50 + i * (int)textureVector.X; else x = -50 - i * (int)textureVector.X; r.X = r.X + x; if (r.Contains(mouseState.Position)) { tower = i; break; } } if (tower != -1) { if (!isClickedATower) { Tower t = towers[tower]; if (circlePosition == null || !circlePosition.Equals(((Vector2)postIt) / (1200f / 3200f) / 100)) { circlePosition = ((Vector2)postIt) / (1200f / 3200f); Vector2 setPos = ((Vector2)circlePosition) / 100.0f; setPos.X = (int)setPos.X *100 + 50; setPos.Y = (int)setPos.Y*100 + 50; circlePosition = setPos; circle = CreateCircle((int)(t.GetRange() * scal)); } } /*else if (upgradeAvailable && tower == 0) gameManager.upgradeTower(gameManager.getTower((Vector2)postIt / scal)); else gameManager.RemoveTower(gameManager.getTower((Vector2)postIt / scal));*/ } else circlePosition = null; } // 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(leveli), ControllingPlayer); } 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 * 5; if(mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton != ButtonState.Pressed &&!gameManager.IsGameOver()&&!gameManager.IsLevelFinished()) { marked.Mark(); circle = null; //gameManager.BuyTower(TowerCreator.GetTower(0, content, mouseState.Position.ToVector2() / (1200f / 3200f))); if (postIt == null) { if (marked.IsOk()) { postIt = mouseState.Position.ToVector2(); berechnePostItsRichtung(); } } else { Vector2 textureVector = new Vector2(postItTexture.Width * postItTextureScal, postItTexture.Height * postItTextureScal); Rectangle postItRectangle = new Rectangle(((int)postIt.Value.X) - (((int)textureVector.X) / 2), ((int)postIt.Value.Y) - (((int)textureVector.Y) / 2), ((int)textureVector.X), ((int)textureVector.Y)); bool isClickedATower = gameManager.IsThereATower((Vector2)postIt / scal); bool upgradeAvailable = false; int tower = -1; int count; if (!isClickedATower) count = towers.Count; else if (gameManager.getTower((Vector2)postIt / scal).UpgradeAvailable()) { count = 2; upgradeAvailable = true; } else count = 1; for (int i = 0; i < count; i++) { Rectangle r = postItRectangle; int x; if (postItRichtungRechts) x = 50 + i * (int)textureVector.X; else x = -50 - i * (int)textureVector.X; r.X = r.X + x; if (r.Contains(mouseState.Position)) { tower = i; break; } else { marked.SetPosition(mPos); marked.Mark(); } } if (tower != -1) { if (!isClickedATower) gameManager.BuyTower(TowerCreator.GetTower(tower, content, ((Vector2)postIt) / (1200f / 3200f))); else if (upgradeAvailable && tower == 0) gameManager.upgradeTower(gameManager.getTower((Vector2)postIt / scal)); else gameManager.RemoveTower(gameManager.getTower((Vector2)postIt / scal)); postIt = null; marked.DeMark(); } else { marked.SetPosition(mPos); if (gameManager.IsThereAPath(new Vector2(mouseState.X / scal, mouseState.Y / scal))) { marked.NotOk(); postIt = null; marked.DeMark(); } else { marked.Ok(); postIt = mouseState.Position.ToVector2(); berechnePostItsRichtung(); } } } } if (mouseState.RightButton == ButtonState.Pressed && oldMouseState.LeftButton != ButtonState.Pressed) { //gameManager.BuyTower(TowerCreator.GetTower(0, content, mouseState.Position.ToVector2() / (1200f / 3200f))); postIt = null; marked.DeMark(); } } oldMouseState = mouseState; }
/// <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 { // 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> /// 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 (gameObjectManager.isLevelCompleted()) { ScreenManager.AddScreen(new LevelCompleteScreen(), ControllingPlayer); } else if (gameObjectManager.isGameOver()) { ScreenManager.AddScreen(new GameOverScreen(), ControllingPlayer); } else if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Otherwise move the player position. Vector2 movement = Vector2.Zero; if (keyboardState.IsKeyDown(Keys.Left)) { movement.X--; lastMove = 1; } if (keyboardState.IsKeyDown(Keys.Right)) { movement.X++; lastMove = 3; } if (keyboardState.IsKeyDown(Keys.Up)) { movement.Y--; lastMove = 0; } if (keyboardState.IsKeyDown(Keys.Down)) { movement.Y++; lastMove = 2; } #region codes if (keyboardState.IsKeyDown(Keys.D0)) { if (code.Count == 4) { code.RemoveAt(0); } if (code[code.Count - 1] != 0) { code.Add(0); } } if (keyboardState.IsKeyDown(Keys.D1)) { if (code.Count == 4) { code.RemoveAt(0); } if (code[code.Count - 1] != 1) { code.Add(1); } } if (keyboardState.IsKeyDown(Keys.D2)) { if (code.Count == 4) { code.RemoveAt(0); } if (code[code.Count - 1] != 2) { code.Add(2); } } if (keyboardState.IsKeyDown(Keys.D3)) { if (code.Count == 4) { code.RemoveAt(0); } if (code[code.Count - 1] != 3) { code.Add(3); } } if (keyboardState.IsKeyDown(Keys.D4)) { if (code.Count == 4) { code.RemoveAt(0); } if (code[code.Count - 1] != 4) { code.Add(4); } } if (keyboardState.IsKeyDown(Keys.D5)) { if (code.Count == 4) { code.RemoveAt(0); } if (code[code.Count - 1] != 5) { code.Add(5); } } if (keyboardState.IsKeyDown(Keys.D6)) { if (code.Count == 4) { code.RemoveAt(0); } if (code[code.Count - 1] != 6) { code.Add(6); } } if (keyboardState.IsKeyDown(Keys.D7)) { if (code.Count == 4) { code.RemoveAt(0); } if (code[code.Count - 1] != 7) { code.Add(7); } } if (keyboardState.IsKeyDown(Keys.D8)) { if (code.Count == 4) { code.RemoveAt(0); } if (code[code.Count - 1] != 8) { code.Add(8); } } if (keyboardState.IsKeyDown(Keys.D9)) { if (code.Count == 4) { code.RemoveAt(0); } if (code[code.Count - 1] != 9) { code.Add(9); } } string strCode = string.Empty; foreach (int i in code) { strCode += i.ToString(); } switch (strCode) { case "4242": ScreenManager.AddScreen(new LevelCompleteScreen(), ControllingPlayer); break; case "1290": ScreenManager.AddScreen(new GameOverScreen(), ControllingPlayer); break; case "1212": MonsterGameObject.Ghost = true; break; } #endregion Vector2 thumbstick = gamePadState.ThumbSticks.Left; movement.X += thumbstick.X; movement.Y -= thumbstick.Y; if (movement.Length() > 1) { movement.Normalize(); } playerPosition += movement * 2; gameObjectManager.HandleInput(keyboardState); } }
/// <summary> /// Добавим реакцию игры на действия пользователя. В отличии от метода Апдейт, /// этот метод будет вызван, когда экран Геймплей будет активным. /// </summary> public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); ///Проверка действий для действий пользователя int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; //Игра будет в режиме паузы, если пользователь нажал на паузу, или если /// он отключил активный геймпад. Это требуется для того, чтобы мы следили /// когда геймпад включен, потому что мы не хотим ставить на паузу игру /// на ПК, если они играют на клаве и у них нету геймпада!!!!!!!!!! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Иначе передвигаем позицию игрока 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> /// 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) { if (input == null) throw new ArgumentNullException("input"); if (gameOver) { if (input.IsPauseGame(null)) { FinishCurrentGame(); } foreach (GestureSample gestureSample in input.Gestures) { if (gestureSample.GestureType == GestureType.Tap) { FinishCurrentGame(); } } return; } if (input.IsPauseGame(null)) { PauseCurrentGame(); } else if (isHumanTurn && (player.Catapult.CurrentState == CatapultState.Idle || player.Catapult.CurrentState == CatapultState.Aiming)) { // First we try with mouse input player.HandleInput(input); if (input.MouseGesture == MouseGestureType.FreeDrag) isDragging = true; else if (input.MouseGesture == MouseGestureType.DragComplete) isDragging = false; // Read all available gestures foreach (GestureSample gestureSample in input.Gestures) { if (gestureSample.GestureType == GestureType.FreeDrag) isDragging = true; else if (gestureSample.GestureType == GestureType.DragComplete) isDragging = false; player.HandleInput(gestureSample); } } }
/// <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) { // Check if the user's input is null and throw an exception if it is if (input == null) { throw new ArgumentNullException("input"); } // Look up inputs for the active player profile KeyboardState keyboardState = input.CurrentKeyboardStates; // Checks to see if the user hit the pause button (esc) if (input.IsPauseGame()) { // Add a new screen on top of our current screen to display the pause menu ScreenManager.AddScreen(new PauseMenuScreen()); } // Check to see if our menu selection key was hit (Z) if (input.IsMenuSelect()) { // Check to see if the player already has the move they are on in the selection screen equipped if (PlayerInfo.Moves.Contains(selectedMove)) { // Get the index of this move and remove it from the player's currently equipped moves int index = Array.IndexOf(PlayerInfo.Moves, selectedMove); PlayerInfo.Moves[index] = -1; } // Otherwise, if there is an open slot for equipping a new move else if (PlayerInfo.Moves.Contains(-1)) { // Get the index of the open slot and fill it with the new selected index int index = Array.IndexOf(PlayerInfo.Moves, -1); PlayerInfo.Moves[index] = selectedMove; } } // Check to see if the start button (enter) was pressed and if the player has any moves equipped (I.E anything with an index greater than -1) if (input.IsStartButton() && Array.Exists(PlayerInfo.Moves, selectedMove => selectedMove > -1)) { // Load the next match LoadingScreen.Load(ScreenManager, false, new MatchupInfoScreen()); } // Check to see if the up arrow key was hit if (input.IsMenuUp()) { // Decrement the selected move selectedMove--; // Wrap the selected move around if the user goes beyond the minimum moves if (selectedMove < 0) { selectedMove = maxMoves - 1; } } // Check to see if the down arrow key was hit if (input.IsMenuDown()) { // Increment the selected move selectedMove++; // Wrap back around if the player goes beyond the maximum amount of moves if (selectedMove >= maxMoves) { selectedMove = 0; } } }