Exemple #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            _resources = new Resources(this);

            // Add startScene
            startScene = new StartScene(this, spriteBatch);
            Components.Add(startScene);
            startScene.Show(true);

            // Add playScene
            playScene = new GameScene(this, spriteBatch);
            Components.Add(playScene);
            playScene.Show(false);

            // Add creditsScene
            creditsScene = new CreditsScene(this, spriteBatch);
            Components.Add(creditsScene);
            creditsScene.Show(false);

            // Add helpScene
            helpScene = new HelpScene(this, spriteBatch);
            Components.Add(helpScene);
            helpScene.Show(false);

            // Add highScoreScene
            highScoreScene = new HighScoreScene(this, spriteBatch);
            Components.Add(highScoreScene);
            highScoreScene.Show(false);

            // Create enterSound
            enterSoundIns = this.Content.Load <SoundEffect>("Sounds/enterSound").CreateInstance();

            // Create and play music
            menuMusic = this.Content.Load <Song>("Sounds/pauseMenu");
            MediaPlayer.Play(menuMusic);
        }
Exemple #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // TODO: Add your update logic here
            int           selectedIdx = 0;
            KeyboardState ks          = Keyboard.GetState();

            // manage menus & scenes
            if (startScene.Enabled)
            {
                if (oldState.IsKeyDown(Keys.Enter) && ks.IsKeyUp(Keys.Enter))
                {
                    selectedIdx = startScene.Menu.SelectedIdx;
                    startScene.Hide();
                    if (selectedIdx == (int)MainMenu.Start)
                    {
                        actionScene.Show();
                    }
                    else if (selectedIdx == (int)MainMenu.Help)
                    {
                        helpScene.Show();
                    }
                    else if (selectedIdx == (int)MainMenu.HighScore)
                    {
                        RebootHighScoreScene();
                        highScoreScene.Show();
                    }
                    else if (selectedIdx == (int)MainMenu.About)
                    {
                        aboutScene.Show();
                    }
                    else if (selectedIdx == (int)MainMenu.Quit)
                    {
                        Exit();
                    }
                }
            }
            if (actionScene.Enabled)
            {
                if (actionScene.ShowGameOver)
                {
                    actionScene.Enabled = false;
                    gameOverScene.Score = (int)actionScene.Score;
                    highScorePlayers    = ReadScores(); // read scores

                    // if there are players saved and the current score is lower compared to the highest one,
                    // set highscore to this max one;
                    // otherwise set to the current score
                    if (highScorePlayers.Any() && gameOverScene.Score < highScorePlayers[0].Score)
                    {
                        gameOverScene.HighScore = highScorePlayers[0].Score;
                    }
                    else
                    {
                        gameOverScene.HighScore = (int)actionScene.Score;
                    }
                    gameOverScene.Show();
                }
            }
            if (helpScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    helpScene.Hide();
                    startScene.Show();
                }
            }
            if (highScoreScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    highScoreScene.Hide();
                    startScene.Show();
                }
            }
            if (aboutScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    aboutScene.Hide();
                    startScene.Show();
                }
            }
            if (gameOverScene.Enabled && !gameOverScene.IsEditNameMode)
            {
                if (oldState.IsKeyDown(Keys.Enter) && ks.IsKeyUp(Keys.Enter))
                {
                    selectedIdx = gameOverScene.Menu.SelectedIdx;

                    gameOverScene.Hide();

                    Player player = new Player(gameOverScene.Name, gameOverScene.Score);
                    UpdateScores(player); // update the 'scores' file

                    if (selectedIdx == (int)GameOverMenu.PlayAgain)
                    {
                        actionScene.Hide();
                        RebootActionScene();
                        actionScene.Show();
                    }
                    else if (selectedIdx == (int)GameOverMenu.MainMenu)
                    {
                        gameOverScene.Menu.SelectedIdx = 0;
                        actionScene.Hide();
                        //RebootGameOverScene();
                        RebootActionScene();
                        startScene.Show();
                    }
                }
            }
            oldState = ks;

            base.Update(gameTime);
        }
Exemple #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Whether to exit the game or not upon the press of Esc
            if (Keyboard.GetState().IsKeyDown(Keys.Escape) && oldState.IsKeyUp(Keys.Escape))
            {
                if (playScene.Enabled || creditsScene.Enabled || helpScene.Enabled || highScoreScene.Enabled)
                {
                    HideAllScenes();
                    startScene.Show(true);
                }
                else
                {
                    Exit();
                }
            }

            // TODO: Add your update logic here


            var ks = Keyboard.GetState();

            //Changing to a Scene depending on menu choice
            if (startScene.Enabled || ForcefulSceneChange != 0)
            {
                var selectedIndex = startScene.Menu.SelectedIndex;
                if (ks.IsKeyDown(Keys.Enter) && oldState.IsKeyUp(Keys.Enter) || ForcefulSceneChange != 0)
                {
                    if (ForcefulSceneChange != 0)
                    {
                        selectedIndex       = ForcefulSceneChange;
                        ForcefulSceneChange = 0;
                    }
                    switch (selectedIndex)
                    {
                    case 0:
                        HideAllScenes();
                        playScene.Show(true);
                        enterSoundIns.Play();
                        break;

                    case 1:
                        HideAllScenes();
                        Components.Remove(playScene);
                        Components.Add(playScene = new GameScene(this, spriteBatch));
                        playScene.Show(true);
                        enterSoundIns.Play();

                        MediaPlayer.Play(menuMusic);
                        break;

                    case 2:
                        HideAllScenes();
                        helpScene.Show(true);
                        enterSoundIns.Play();
                        break;

                    case 3:
                        HideAllScenes();
                        highScoreScene.Show(true);
                        enterSoundIns.Play();
                        highScoreScene.ReadFromFile();
                        break;

                    case 4:
                        HideAllScenes();
                        creditsScene.Show(true);
                        enterSoundIns.Play();
                        break;

                    case 5:
                        Exit();
                        break;
                    }
                }
            }
            oldState = ks;

            base.Update(gameTime);
        }
Exemple #4
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            int           selectedIndex = 0;
            KeyboardState ks            = Keyboard.GetState();

            if (startScene.Enabled)
            {
                selectedIndex = startScene.Menu.SelectedIndex;
                if (selectedIndex == 0 && ks.IsKeyDown(Keys.Enter))
                {
                    HideAllScenes();
                    actionScene.Show();
                    MediaPlayer.Stop();
                }
                else if (selectedIndex == 1 && ks.IsKeyDown(Keys.Enter))
                {
                    HideAllScenes();
                    howToPlay.Show();
                }
                else if (selectedIndex == 2 && ks.IsKeyDown(Keys.Enter))
                {
                    HideAllScenes();
                    highScoreScene.Show();
                }
                else if (selectedIndex == 3 && ks.IsKeyDown(Keys.Enter))
                {
                    HideAllScenes();
                    helpScene.Show();
                }
                else if (selectedIndex == 4 && ks.IsKeyDown(Keys.Enter))
                {
                    HideAllScenes();
                    creditScene.Show();
                }
                else if (selectedIndex == 5 && ks.IsKeyDown(Keys.Enter))
                {
                    Exit();
                }
            }

            if (actionScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    HideAllScenes();
                    startScene.Show();
                    MediaPlayer.Play(song);
                }
            }

            if (helpScene.Enabled || creditScene.Enabled || highScoreScene.Enabled || howToPlay.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    HideAllScenes();
                    startScene.Show();
                }
            }
            if (endGameScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    Shared.score = 0;
                    HideAllScenes();
                    highScoreScene.Show();
                }
            }

            if (Shared.gameIsOver)
            {
                highScoreScene.SaveHighScore();
                highScoreScene.LoadHighScore();
                HideAllScenes();
                endGameScene.Show();
                Shared.gameIsOver = false;
                actionScene.Restart();
            }



            base.Update(gameTime);
        }