コード例 #1
0
ファイル: Game1.cs プロジェクト: ezat-rafie/Space-Survival
        /// <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 selectedIndex = 0;

            ks = Keyboard.GetState();

            if (startScene.Enabled)
            {
                selectedIndex = startScene.Menu.SelectedIndex; //* StartScene.cs > MenuComponent > SelectedIndex
                if (ks.IsKeyDown(Keys.Enter))
                {
                    HideAllScenes();
                    switch (selectedIndex)
                    {
                    case 0:
                        levelScene.Show();
                        break;

                    case 1:
                        helpScene.Show();
                        break;

                    case 2:
                        highScoreScene.Show();
                        break;

                    case 3:
                        aboutScene.Show();
                        break;

                    case 4:
                        this.Exit();
                        break;

                    default:
                        //* ERROR CATCH
                        break;
                    }
                }
            }
            else if (levelScene.Enabled && oldState.IsKeyUp(Keys.Enter))
            {
                selectedIndex = levelScene.Menu.SelectedIndex;
                if (selectedIndex == 0 && ks.IsKeyDown(Keys.Enter))
                {
                    HideAllScenes();
                    playScene1.Show();
                    SwitchMusic(backgroundMusic);
                }
                if (selectedIndex == 1 && ks.IsKeyDown(Keys.Enter))
                {
                    HideAllScenes();
                    playScene2.Show();
                    SwitchMusic(backgroundMusic);
                }
            }

            if (levelScene.Enabled || playScene1.Enabled || playScene2.Enabled ||
                helpScene.Enabled || highScoreScene.Enabled || aboutScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    HideAllScenes();
                    startScene.Show();
                    LoadContent();
                    SwitchMusic(startMusic);
                    //ScoreManager.Compare(Shared.scoreArr[5], Shared.playerArr[5]);
                }
            }

            oldState = ks;
            base.Update(gameTime);
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: kkimkkom/Space-Survival
        /// <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           selectedIndex = 0;
            KeyboardState ks            = Keyboard.GetState();

            if (startScene.Enabled)
            {
                selectedIndex = startScene.Menu.SelectedIndex; //* StartScene.cs > MenuComponent > SelectedIndex
                if (ks.IsKeyDown(Keys.Enter))
                {
                    HideAllScenes();
                    // sound effect when selecting menu
                    click.Play();
                    switch (selectedIndex)
                    {
                    case 0:
                        playScene.Show();
                        SwitchMusic(backgroundMusic);
                        break;

                    case 1:
                        helpScene.Show();
                        break;

                    case 2:
                        highScoreScene.Show();
                        break;

                    case 3:
                        aboutScene.Show();
                        break;

                    case 4:
                        this.Exit();
                        break;

                    default:
                        //* ERROR CATCH
                        break;
                    }
                }
                //* changed this if block to switch
                //if (selectedIndex == 0 && ks.IsKeyDown(Keys.Enter))
                //{
                //    HideAllScenes();
                //    playScene.Show();
                //}
                //if (selectedIndex == 1 && ks.IsKeyDown(Keys.Enter))
                //{
                //    HideAllScenes();
                //    helpScene.Show();
                //}
                //if (selectedIndex == 4 && ks.IsKeyDown(Keys.Enter)) // QUIT
                //{
                //    this.Exit();
                //}
            }

            if (playScene.Enabled || helpScene.Enabled || highScoreScene.Enabled || aboutScene.Enabled)
            {
                if (ks.IsKeyDown(Keys.Escape))
                {
                    HideAllScenes();
                    startScene.Show();
                    SwitchMusic(startMusic);
                }
            }

            base.Update(gameTime);
        }