示例#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);

            // TODO: use this.Content to load your game content here

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

            gameOverScene = new GameOverScene(this, spriteBatch);
            this.Components.Add(gameOverScene);

            actionScene = new ActionScene(this, spriteBatch, gameOverScene);
            this.Components.Add(actionScene);

            howToPlayScene = new HowToPlayScene(this, spriteBatch);
            this.Components.Add(howToPlayScene);

            aboutScene = new AboutScene(this, spriteBatch);
            this.Components.Add(aboutScene);

            highestScoreScene = new HighestScoreScene(this, spriteBatch, actionScene.score);
            this.Components.Add(highestScoreScene);

            startScene.ShowScene();
        }
示例#2
0
 private void ResetGame()
 {
     gameOverScene.HideScene();
     gameOverScene.Enabled = false;
     this.Components.Remove(gameOverScene);
     this.Components.Remove(actionScene);
     gameOverScene = new GameOverScene(this, spriteBatch);
     actionScene   = new ActionScene(this, spriteBatch, gameOverScene);
     this.Components.Add(gameOverScene);
     this.Components.Add(actionScene);
     isGameOverPlaying = false;
 }
示例#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)
        {
            //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            //    Exit();

            // TODO: Add your update logic here

            int selectedIndex = 0;
            int gameOverIndex = 0;

            KeyboardState ks = Keyboard.GetState();


            if (startScene.Enabled)
            {
                if (!isGameThemePlaying)
                {
                    MediaPlayer.IsRepeating = true;
                    MediaPlayer.Play(gameTheme);
                    isGameThemePlaying = true;
                }
                selectedIndex = startScene.Menu.SelectedIndex;
                if (selectedIndex == 0 && ks.IsKeyDown(Keys.Enter))
                {
                    DisplayActionScene(gameTime);
                }
                if (selectedIndex == 1 && ks.IsKeyDown(Keys.Enter))
                {
                    startScene.HideScene();
                    howToPlayScene.ShowScene();
                }
                if (selectedIndex == 2 && ks.IsKeyDown(Keys.Enter))
                {
                    DisplayHighestScoreScene();
                }
                if (selectedIndex == 3 && ks.IsKeyDown(Keys.Enter))
                {
                    aboutScene.HideScene();
                    aboutScene.ShowScene();
                }
                if (selectedIndex == 4 && ks.IsKeyDown(Keys.Enter))
                {
                    Exit();
                }
            }
            if (actionScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    this.Components.Remove(actionScene);
                    actionScene = new ActionScene(this, spriteBatch, gameOverScene);
                    this.Components.Add(actionScene);

                    startScene.ShowScene();
                    MediaPlayer.Play(gameTheme);
                }
            }
            if (gameOverScene.Enabled)
            {
                gameOverIndex = gameOverScene.Menu.SelectedIndex;
                if (!isGameOverPlaying)
                {
                    gameOverScene.GameOverSound.Play();
                    isGameOverPlaying = true;
                }
                if (gameOverIndex == 0 && ks.IsKeyDown(Keys.Enter))
                {
                    ResetGame();
                    actionScene.HideScene();
                    startScene.Enabled = true;
                    startScene.ShowScene();
                    Thread.Sleep(200);
                }
                if (gameOverIndex == 1 && ks.IsKeyDown(Keys.Enter))
                {
                    ResetGame();
                    DisplayActionScene(gameTime);
                }
            }

            if (howToPlayScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    howToPlayScene.HideScene();
                    startScene.ShowScene();
                }
            }
            if (aboutScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    aboutScene.HideScene();
                    startScene.ShowScene();
                }
            }
            if (highestScoreScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    highestScoreScene.HideScene();
                    startScene.ShowScene();
                }
            }

            base.Update(gameTime);
        }