예제 #1
0
        /// <summary>
        /// Runs one frame of update for the game.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime,
                                    bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            //Update Managers
            particles.Update(elapsed);
            powerups.Update(elapsed);

            //Update paddles and balls
            UpdateBottomPaddle(elapsed);
            UpdateTopPaddle(elapsed);
            if (0 == ballManager.Update(elapsed))
            {
                foreach (GameScreen screen in ScreenManager.GetScreens())
                {
                    screen.ExitScreen();
                }

                //TODO: add game over screen
                CollisionManager.ClearAll();
                ScreenManager.AddScreen(new BackgroundScreen());
                ScreenManager.AddScreen(new MainMenuScreen());
            }
            CheckHits();

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
예제 #2
0
        /// <summary>
        /// Input helper method provided by GameScreen.  Packages up the various input
        /// values for ease of use
        /// </summary>
        /// <param name="input">The state of the gamepads</param>
        public override void HandleInput(InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }


            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                foreach (GameScreen screen in ScreenManager.GetScreens())
                {
                    screen.ExitScreen();
                }

                CollisionManager.ClearAll();
                ScreenManager.AddScreen(new BackgroundScreen());
                ScreenManager.AddScreen(new MainMenuScreen());
            }
        }
예제 #3
0
        /// <summary>
        /// Input helper method provided by GameScreen.  Packages up the various input
        /// values for ease of use
        /// </summary>
        /// <param name="input">The state of the gamepads</param>
        public override void HandleInput(InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }


            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                foreach (GameScreen screen in ScreenManager.GetScreens())
                {
                    screen.ExitScreen();
                }

                CollisionManager.ClearAll();
                ScreenManager.AddScreen(new BackgroundScreen());
                ScreenManager.AddScreen(new MainMenuScreen());
            }

            //if (input.IsPauseGame(null))
            //{
            //    PauseCurrentGame();
            //}

            /// Read Touchscreen input
            /// For now, add all "Pressed" and "Moved" events to lastTouchInput
            if (input.TouchState.Count > 0)
            {
                lastTouchInput = new List <TouchLocation>();
                foreach (var touch in input.TouchState)
                {
                    switch (touch.State)
                    {
                    case TouchLocationState.Pressed:
                        if (bottomPaddleTouchId == -1 &&
                            touch.Position.Y > bottomPaddle.Position.Y &&
                            touch.Position.X > bottomPaddle.Position.X - 20 &&
                            touch.Position.X < bottomPaddle.Position.X + bottomPaddle.Width + 20)
                        {
                            bottomPaddleTouch   = touch;
                            bottomPaddleTouchId = touch.Id;
                        }
                        else
                        {
                            lastTouchInput.Add(touch);
                        }
                        break;

                    case TouchLocationState.Moved:
                        if (touch.Id == bottomPaddleTouchId)
                        {
                            bottomPaddleTouch = touch;
                        }
                        else
                        {
                            lastTouchInput.Add(touch);
                        }
                        break;

                    case TouchLocationState.Released:
                        if (touch.Id == bottomPaddleTouchId)
                        {
                            bottomPaddleTouchId = -1;
                        }
                        else
                        {
                            lastTouchInput.Add(touch);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            /// Read Accelerometer input
            /// (use it to update powerups)
            float movement = 0.0f;

            if (accelState != null)
            {
                if (Math.Abs(accelState.X) > 0.10f)
                {
                    if (accelState.X > 0.0f)
                    {
                        movement = 10.0f;
                    }
                    else
                    {
                        movement = -10.0f;
                    }
                }
            }
            // TODO: use this movement to update powerups

            /// Read keyboard input
            /// (use it for debugging)
            KeyboardState keyState = Keyboard.GetState();

            lastKeyInput = new List <Keys>();

            //For default, bottom paddle movement
            if (keyState.IsKeyDown(Keys.Left))
            {
                lastKeyInput.Add(Keys.Left);
            }
            if (keyState.IsKeyDown(Keys.Right))
            {
                lastKeyInput.Add(Keys.Right);
            }

            //For multitouch, top paddle movement
            if (keyState.IsKeyDown(Keys.F))
            {
                lastKeyInput.Add(Keys.F);
            }
            if (keyState.IsKeyDown(Keys.D))
            {
                lastKeyInput.Add(Keys.D);
            }
        }