Пример #1
0
		public void Update(MenuInput input, PlayerIndex? controllingPlayer)
		{            
			Vector2 cameraMovement = Vector2.Zero;
			int playerIndex = (int)controllingPlayer;

            if (input.GamePadWasConnected[playerIndex])
            {
                cameraMovement.X = input.CurrentGamePadStates[playerIndex].ThumbSticks.Left.X;
                cameraMovement.Y = -input.CurrentGamePadStates[playerIndex].ThumbSticks.Left.Y;
            }
            else
            {
            /*    if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Left))
                {
                    cameraMovement.X = -1;
                }
                else if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Right))
                {
                    cameraMovement.X = 1;
                }
                if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Up))
                {
                    cameraMovement.Y = -1;
                }
                else if (input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Down))
                {
                    cameraMovement.Y = 1;
                }

                if (cameraMovement != Vector2.Zero)
                {
                    cameraMovement.Normalize();
                }*/
            }            
            
			if (Focus == null)
			{
				Position += Speed * cameraMovement;
			}
			else
			{
				CenterOnFocus();
			}
            Vector2 cameraMax = new Vector2(MapSize.X * TileSize.X - ViewSize.X, MapSize.Y * TileSize.Y - ViewSize.Y);
            Position = Vector2.Clamp(Position, Vector2.Zero, cameraMax);            
		}
Пример #2
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(MenuInput input)
        {
            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

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

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

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

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

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
Пример #3
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(MenuInput input)
        {
            PlayerIndex playerIndex;

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

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

                ExitScreen();
            }
        }
Пример #4
0
        public void HandleInput(MenuInput input, PlayerIndex? ControllingPlayer)
        {
            Vector2 playerMovement = Vector2.Zero;
            int playerIndex = (int)ControllingPlayer;
            //Xbox controls
            if (input.GamePadWasConnected[playerIndex])
            {
                playerMovement.X = input.CurrentGamePadStates[playerIndex].ThumbSticks.Left.X;
                playerMovement.Y = -input.CurrentGamePadStates[playerIndex].ThumbSticks.Left.Y;
            }
            //Keyboard Controls WASD or Arrow Keys  
            //Also Prevents Diagonal Movement
            else
            {
                if ((input.CurrentKeyboardStates[playerIndex].GetPressedKeys().Length == 1)&&((input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.A)))|| input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Left))
                {
                    playerMovement.X = -1;
                }
                else if ((input.CurrentKeyboardStates[playerIndex].GetPressedKeys().Length == 1) && ((input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.D))) || input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Right))
                {
                    playerMovement.X = 1;
                }
                if ((input.CurrentKeyboardStates[playerIndex].GetPressedKeys().Length == 1) && ((input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.W))) || input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Up))
                {
                    playerMovement.Y = -1;
                }
                else if ((input.CurrentKeyboardStates[playerIndex].GetPressedKeys().Length == 1) && ((input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.S)))|| input.CurrentKeyboardStates[playerIndex].IsKeyDown(Keys.Down))
                {
                    playerMovement.Y = 1;
                }

               
            }
            //Control Animation 
			if (playerMovement == Vector2.Zero)
				IsAnimating = false;
			
            
            //Adjust Player direction
            if (playerMovement.X > 0 && playerMovement.Y == 0) Direction = Enums.Direction.East;
            if (playerMovement.X < 0 && playerMovement.Y == 0) Direction = Enums.Direction.West;
            if (playerMovement.X == 0 && playerMovement.Y > 0) Direction = Enums.Direction.South;
            if (playerMovement.X == 0 && playerMovement.Y < 0) Direction = Enums.Direction.North;
			
            Position += Speed * playerMovement;

			LastMovement = Speed * playerMovement;
        }
Пример #5
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(MenuInput 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
            {
                switch (Statics.Realm)
                {
                    case Enums.Realm.WorldMap:
                        Statics.WorldPlayer.HandleInput(input, ControllingPlayer);
                        Statics.WorldMap.CheckCollisions();
                        Statics.WorldMap.camera.Update(input, ControllingPlayer);
                        break;
                    case Enums.Realm.Level:
                        break;
                }
            }
        }
Пример #6
0
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(MenuInput input) { }