コード例 #1
0
ファイル: UfoLander.cs プロジェクト: donvi-bz/Prog2370-Final
        /// <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);
        }
コード例 #2
0
ファイル: UfoLander.cs プロジェクト: donvi-bz/Prog2370-Final
        /// <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);
        }