Ejemplo n.º 1
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

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

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[playerIndex];

            if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
            if (gameover == true)
            {
                ScreenManager.AddScreen(new GameOverMenuScreen(), ControllingPlayer);
                MediaPlayer.Stop();
            }
            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 * 5;
                movement.Y -= thumbstick.Y * 5;
                if (thumbstick.X > 0)
                {

                }
                /*if (movement.Length() > 1)
                    movement.Normalize();*/

                playerPosition += movement * 1;
            }
        }
Ejemplo n.º 2
0
        /// <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))
            {
                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);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(InputState input)
 {
 }
Ejemplo n.º 4
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)
        {
            //we will need a loop to handle input for each player

                Players[1].HandleInput(input.CurrentGamePadStates[1]);
                Players[0].HandleInput(input.CurrentGamePadStates[0]);
                Players[2].HandleInput(input.CurrentGamePadStates[2]);
                Players[3].HandleInput(input.CurrentGamePadStates[3]);

            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 (gameover == true)
               {
                   ScreenManager.AddScreen(new GameOverMenuScreen(), ControllingPlayer);
                   MediaPlayer.Stop();
               }*/

                }
        }
Ejemplo n.º 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(InputState input)
        {
            //we will need a loop to handle input for each player

            //for(int p=0;p<2;p++)

            if (input.hasenteredthegame[1] && hellomessage == 0.0 )
            {//when another player enters the game
                //we should display a hello message to let them know they have entered
                hellomessage = 5;//5 seconds
            }
            //if (input.hasenteredthegame[1])
            {//player2  Has entered so let him play
                Players[1].HandleInput(input.CurrentGamePadStates[1]);
            }
            int p = 0;//player 1
            {
              if (input.CurrentKeyboardStates[p].IsKeyDown(Keys.Up) == true | GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
                {
                    mRotateTime += elapsed;
                    if (mRotateTime > 0.1F)
                    {
                        mRotateTime = 0F;

                        mCurrentShape.Rotation += 1;
                        if ((mCurrentShape.Rotation > 3))
                        {
                            mCurrentShape.Rotation = 0;
                        }
                        if (mPlayfield.CheckCollision(mCurrentShape) == true)
                        {
                            mCurrentShape.Rotation -= 1;
                            if ((mCurrentShape.Rotation < 0))
                            {
                                mCurrentShape.Rotation = 3;
                            }
                        }
                        else
                        {
                            mSound.Play(Sound.SoundFX.Rotate);
                        }
                    }
                }
                else
                {
                    mRotateTime = 0.3F;
                }

            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( input.CurrentGamePadStates[0].IsButtonUp(Buttons.DPadLeft))
                   mLeftTime = 0.1F;
               else
               // if (keyboardState.IsKeyDown(Keys.Left))
                {

                                    mLeftTime += elapsed;
                        if (mLeftTime > 0.1F)
                        {
                            mLeftTime = 0F;
                            mCurrentShape.DrawPositionX -= 24;
                            if (mPlayfield.CheckCollision(mCurrentShape) == true) mCurrentShape.DrawPositionX += 24;
                            // mCurrentShape.PositionX -= 1;
                            //   if (mPlayfield.CheckCollision(mCurrentShape) == true)
                            //  {
                            //      mCurrentShape.PositionX += 1;
                            //  }
                        }

                }

               if (gameover == true)
               {
                   ScreenManager.AddScreen(new GameOverMenuScreen(), ControllingPlayer);
                   MediaPlayer.Stop();
               }

               if (input.CurrentGamePadStates[0].IsButtonUp(Buttons.DPadRight)) mRightTime = .1f;
                else
                //if (keyboardState.IsKeyDown(Keys.Right))
                {
                                           mRightTime += elapsed;
                                           if (mRightTime > 0.1F)
                                           {
                                               mRightTime = 0F;
                                               mCurrentShape.DrawPositionX += 24;
                                               movement.X++;
                                               //    mCurrentShape.DrawPositionX += 2;
                                               if (mPlayfield.CheckCollision(mCurrentShape) == true) mCurrentShape.DrawPositionX -= 24;
                                           }
                }

                if (input.CurrentGamePadStates[0].IsButtonUp(Buttons.DPadDown)) mDownTime = .2f;
                //Move the current piece down
                else
                {
                    mDownTime += elapsed;
                    if (mDownTime > 0.1F)
                    {
                        mDownTime = 0;
                        mCurrentShape.DrawPositionY += 24;
                        if (mPlayfield.CheckCollision(mCurrentShape) == true)
                        {
                            mCurrentShape.DrawPositionY -= 24;
                            if (mCurrentShape.PositionY <= 0)
                            {
                                gameover = true;
                                mSound.Pause(Sound.Music.Background);
                                mSound.Play(Sound.SoundFX.GameOver);
                                // return -1;
                            }//end if (mCurrentShape.PositionY <= 0)

                            //Add the shape to the playfield
                            mPlayfield.AddShape(mCurrentShape);

                            //Create a new shape
                            CreateNewShape();
                            // return 1;//a new peice has been created
                        }

                    }
                }
            }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState 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();
            }
        }