Implementing a switch statement based on user input

Posted by Dave Voyles on Game Development See other posts from Game Development or by Dave Voyles
Published on 2012-06-01T20:43:13Z Indexed on 2012/06/01 22:51 UTC
Read the original article Hit count: 265

Filed under:
|

I'm trying to delay the time it takes for the main menu screen to pop up after a user has won / lost a match. As it stands, the game immediately displays a message stating "you won / lost" and waits for 6 seconds before loading the menu screen.

I would also like players to have the ability to press a key to advance to the menu screen immediately but thus far my switch statement doesn't seem to do the trick. I've included the switch statement, along with my (theoretical) inputs. What could I be doing wrong here?

if (gamestate == GameStates.End)
                    switch (input.IsMenuDown(ControllingPlayer))
                    {
                        case true:
                            ScreenManager.AddScreen(new MainMenuScreen(), null); // Draws the MainMenuScreen 
                            break;

                        case false:
                            if (screenLoadDelay > 0)
                            {
                                screenLoadDelay -= gameTime.ElapsedGameTime.TotalSeconds;
                            }
                            ScreenManager.AddScreen(new MainMenuScreen(), null); // Draws the MainMenuScreen 
                            break;
                    }

     /// <summary>
    /// Checks for a "menu down" input action.
    /// The controllingPlayer parameter specifies which player to read
    /// input for. If this is null, it will accept input from any player.
    /// </summary>
    public bool IsMenuDown(PlayerIndex? controllingPlayer)
    {
        PlayerIndex playerIndex;

        return IsNewKeyPress(Keys.Down, controllingPlayer, out playerIndex)
               || IsNewButtonPress(Buttons.DPadDown, controllingPlayer, out playerIndex)
               || IsNewButtonPress(Buttons.LeftThumbstickDown, controllingPlayer, out playerIndex);
    }

© Game Development or respective owner

Related posts about XNA

Related posts about c#