Пример #1
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)
        {
            // Handle ESC to exit and pop state
            if (core.Input.KeyPressed(Keys.Escape))
            {
                if (gameManager.State == titleScreen)
                {
                    this.Exit();
                }
                else if (gameManager.State == playground2)
                {
                    this.Exit();
                }
                else if (gameManager.State == playground1)
                {
                    gameManager.PushState(gameOptionsMenu);
                }
                else
                {
                    gameManager.PopState();
                }
            }

            // Update core
            core.Update(gameTime.ElapsedGameTime);

            base.Update(gameTime);
        }
Пример #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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here

            if (playerInput != null)
            {
                playerInput.Update(
                    gameTime.ElapsedGameTime.Seconds,
                    core.Input.PreviousKeyboardState,
                    core.Input.KeyboardState,
                    core.Input.PreviousGamePadState,
                    core.Input.GamePadState);
            }

            core.Update(gameTime.ElapsedGameTime);

            KeyboardState ks = Keyboard.GetState();

            if (ks.IsKeyDown(Keys.F) && stopwatch.ElapsedMilliseconds > nextBallTime)
            {
                FireSphere();
                nextBallTime = stopwatch.ElapsedMilliseconds + minBallTime;
            }

            if (ks.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // Next sound
            if (core.Input.KeyboardState.IsKeyDown(Keys.Right) && !core.Input.PreviousKeyboardState.IsKeyDown(Keys.Right))
            {
                if (++soundIndex >= core.SoundManager.Count)
                {
                    soundIndex = core.SoundManager.Count - 1;
                }

                LoadSound();
                PlaySound();
            }

            // Next sound
            if (core.Input.KeyboardState.IsKeyDown(Keys.Left) && !core.Input.PreviousKeyboardState.IsKeyDown(Keys.Left))
            {
                if (--soundIndex < 0)
                {
                    soundIndex = 0;
                }

                LoadSound();
                PlaySound();
            }

            // Play sound
            if (core.Input.KeyboardState.IsKeyDown(Keys.Enter) && !core.Input.PreviousKeyboardState.IsKeyDown(Keys.Enter))
            {
                PlaySound();
            }

            base.Update(gameTime);
        }