//Constructor
        public GameManager(GameData gameData, GameScreen gameScreen)
        {
            GameConfig.MoveKeys = MoveKeys.WASD;

            this.gameData              = gameData;
            this.gameScreen            = gameScreen;
            this.previousKeyboardState = Keyboard.GetState();

            //Initialize and set screen to start
            screenManager = new ScreenManager(gameData, this);
            screenManager.SetScreen(ScreenView.MENU);

            //Set current game state and initalize menu and managers
            this.currentGameState   = GameState.MENU;        //initial screen
            this.menuOption         = MenuOption.PLAY_GAME;  // initial menu option
            this.settingsMenuOption = MenuOption.DIFFICULTY; // initial settings menu option

            this.difficultySettingsMenuOption = DifficultyMenuOption.EASY;
            this.GameOverMenuOption           = MenuOption.MENU;

            this.bulletManager = new BulletManager(gameData);
            this.inputManager  = new InputManager(bulletManager); //give bullet manager to input manager to handle player shooting
        }
Exemple #2
0
        public DifficultyMenuOption DifficultySettingsMenuMove(GameManager controller, KeyboardState state, KeyboardState previousState, DifficultyMenuOption menuStateIn, out GameState newGameState)
        {
            if (state.IsKeyDown(upKey) && previousState.IsKeyUp(upKey))
            {
                PlayCursorSoundEffect();
                newGameState = GameState.MENU;
                switch (menuStateIn)
                {
                case DifficultyMenuOption.EASY:
                    return(DifficultyMenuOption.EASY);

                case DifficultyMenuOption.MEDIUM:
                    return(DifficultyMenuOption.EASY);

                case DifficultyMenuOption.HARD:
                    return(DifficultyMenuOption.MEDIUM);

                case DifficultyMenuOption.INSANE:
                    return(DifficultyMenuOption.HARD);

                case DifficultyMenuOption.MENU:
                    return(DifficultyMenuOption.INSANE);
                }
            }
            else if (state.IsKeyDown(downKey) && previousState.IsKeyUp(downKey))
            {
                PlayCursorSoundEffect();
                newGameState = GameState.MENU;
                switch (menuStateIn)
                {
                case DifficultyMenuOption.EASY:
                    return(DifficultyMenuOption.MEDIUM);

                case DifficultyMenuOption.MEDIUM:
                    return(DifficultyMenuOption.HARD);

                case DifficultyMenuOption.HARD:
                    return(DifficultyMenuOption.INSANE);

                case DifficultyMenuOption.INSANE:
                    return(DifficultyMenuOption.MENU);

                case DifficultyMenuOption.MENU:
                    return(DifficultyMenuOption.MENU);
                }
            }
            else if (state.IsKeyDown(Keys.Enter) && previousState.IsKeyUp(Keys.Enter))
            {
                PlayEnterSoundEffect();
                newGameState = GameState.MENU;
                controller.ScreenManager.SetScreen(ScreenView.MENU);
            }
            newGameState = GameState.MENU;
            return(menuStateIn);
        }
        //Update
        public void Update(GameTime gameTime)
        {
            this.timeElapsed = gameTime;
            // Gets the state of the keyboard and checks the combos as follows.
            KeyboardState keyboardState = Keyboard.GetState();

            switch (this.CurrentGameState)
            {
            case GameState.PAUSE:
                if (timePaused + 3 < timeElapsed.TotalGameTime.TotalSeconds)
                {
                    this.CurrentGameState = GameState.PLAY;
                }
                break;

            case GameState.PLAY:
                GameState newGameState1;
                this.inputManager.HandlePlayerInput(keyboardState);
                //this.collisionDetection(gameTime);
                this.inputManager.InGamePauseMenu(this, keyboardState, previousKeyboardState, menuOption, out newGameState1);
                this.CurrentGameState = newGameState1;
                this.gameData.Update(gameTime); //xxx
                this.stageManager.Update(gameTime);
                if (Player.Instance.IsDead)     //For real dead - all lives gone
                {
                    //Change screen to game over
                    this.gameOver         = GameOver.LOSE;
                    this.CurrentGameState = GameState.GAMEOVER;
                }
                else if (this.stageManager.isGameOver())     //Player won
                {
                    this.gameOver         = GameOver.WIN;
                    this.CurrentGameState = GameState.GAMEOVER;
                }
                break;

            case GameState.MENU:
                GameState newGameState = GameState.MENU;
                if (screenManager.Current == ScreenView.SETTINGS)     //In the settings menu
                {
                    this.settingsMenuOption = inputManager.SettingsMenuMove(this, keyboardState, previousKeyboardState, settingsMenuOption, out newGameState);
                }
                else if (screenManager.Current == ScreenView.DIFFICULTY_SETTINGS)    //In the difficulty settings menu
                {
                    this.difficultySettingsMenuOption = inputManager.DifficultySettingsMenuMove(this, keyboardState, previousKeyboardState, difficultySettingsMenuOption, out newGameState);
                    switch (difficultySettingsMenuOption)
                    {
                    case DifficultyMenuOption.EASY:
                        gameData.Difficulty = Difficulty.Easy;
                        break;

                    case DifficultyMenuOption.MEDIUM:
                        gameData.Difficulty = Difficulty.Medium;
                        break;

                    case DifficultyMenuOption.HARD:
                        gameData.Difficulty = Difficulty.Hard;
                        break;

                    case DifficultyMenuOption.INSANE:
                        gameData.Difficulty = Difficulty.Insane;
                        break;
                    }
                }
                else if (screenManager.Current == ScreenView.MENU)    //In the main menu
                {
                    this.menuOption = inputManager.MenuMove(this, keyboardState, previousKeyboardState, menuOption, out newGameState);
                    if (currentGameState != GameState.PLAY && newGameState == GameState.PLAY)
                    {
                        ResetGame();
                        InitManagers();
                        this.stageManager.initStages();
                    }
                }
                this.CurrentGameState = newGameState;
                break;

            case GameState.PAUSEDMENU:
                GameState newGameState3;
                if (screenManager.Current == ScreenView.SETTINGS)
                {
                    inputManager.PausedSettingsMenuMove(this, keyboardState, previousKeyboardState);
                    newGameState3 = GameState.PAUSEDMENU;
                }
                else     //PAUSED_MENU
                {
                    this.menuOption = inputManager.PausedMenuMove(this, keyboardState, previousKeyboardState, menuOption, out newGameState3);
                    if (currentGameState != GameState.PLAY && newGameState3 == GameState.PLAY)
                    {
                        //this.stageManager.ConfigureNextStage(gameData);
                    }
                }
                this.CurrentGameState = newGameState3;
                break;

            case GameState.GAMEOVER:     //Win or Lose
                GameState newGameState4;
                this.gameOverMenuOption = inputManager.GameOverMenuMove(this, keyboardState, previousKeyboardState, gameOverMenuOption, out newGameState4);
                this.CurrentGameState   = newGameState4;
                break;

            case GameState.EXIT:
                System.Environment.Exit(0);
                break;
            }
            previousKeyboardState = keyboardState;
        }