Пример #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)
        {
            // Allow the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                runGame = false;
            }

            // We need to load the game data
            if (GameLoadRequested)
            {
                if ((result != null) && result.IsCompleted)
                {
                    device = Guide.EndShowStorageDeviceSelector(result);
                    result = null;
                    if ((device == null) || !device.IsConnected)
                    {
                        // Reset the request flag
                        GameLoadRequested = false;
                    }
                }
                if ((device != null) && device.IsConnected)
                {
                    // Load game data
                    GetSavedData();
                    // Reset the request flag
                    GameLoadRequested = false;
                }
            }

            // Update sounds
            audioEngine.Update();

            // Update input
            lastGamePadState     = currentGamePadState;
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);
            lastKeyboardState    = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();


            // Wait 3 seconds until we start playing
            if (gameTime.TotalGameTime.Seconds > 3 && playingGame == false)
            {
                playingGame = true;
                // Get the storage device
                result = Guide.BeginShowStorageDeviceSelector(PlayerIndex.One,
                                                              null, null);
            }

            // After 3 seconds play the game
            if (playingGame)
            {
                // Update the players Catapult
                playerCatapult.Update(gameTime);

                if (playerCatapult.CurrentState == CatapultState.Reset)
                {
                    // reset background and log
                    screenPosition = Vector2.Zero;

                    endObjectPos.X = 1000;
                    endObjectPos.Y = 500;
                }

                // Move background
                if (playerCatapult.CurrentState == CatapultState.ProjectileFlying)
                {
                    screenPosition.X = (playerCatapult.PumpkinPosition.X -
                                        playerCatapult.PumpkinLaunchPosition) * -1.0f;
                    endObjectPos.X = (playerCatapult.PumpkinPosition.X -
                                      playerCatapult.PumpkinLaunchPosition) *
                                     -1.0f + 1000;
                }

                // Calculate the pumpkin flying distance
                if (playerCatapult.CurrentState == CatapultState.ProjectileFlying ||
                    playerCatapult.CurrentState == CatapultState.ProjectileHit)
                {
                    pumpkinDistance = playerCatapult.PumpkinPosition.X -
                                      playerCatapult.PumpkinLaunchPosition;
                    pumpkinDistance /= 15.0f;
                }

                // Is this a high score
                if (highScore < pumpkinDistance)
                {
                    highScore = (int)pumpkinDistance;
                }
            }

            // Exit game
            if (!runGame)
            {
                Exit();
            }

            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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                runGame = false;
            }

            // We need to load the gamedata
            // Implement later
            //TODO: Implement Storage

            //Update sounds
            audioEngine.Update();



            // Update input
            LastGamePadState     = CurrentGamePadState;
            CurrentGamePadState  = GamePad.GetState(PlayerIndex.One);
            LastKeyboardState    = CurrentKeyboardState;
            CurrentKeyboardState = Keyboard.GetState();

            if (CurrentKeyboardState.IsKeyDown(Keys.F) && LastKeyboardState.IsKeyUp(Keys.F))
            {
                graphics.ToggleFullScreen();
            }

            //we have to wait 3 seconds until we start playing
            if (gameTime.TotalGameTime.Seconds > 3 && playingGame == false)
            {
                playingGame = true;
            }

            //after 3 seconds start the game
            if (playingGame)
            {
                //Update players Catapult
                playerCatapult.Update(gameTime);



                if (playerCatapult.CurrentState == CatapultState.Reset)
                {
                    // reset background and log
                    screenPosition = Vector2.Zero;

                    endObjectPos.X = 1000;
                    endObjectPos.Y = 500;
                }

                // Move the background
                if (playerCatapult.CurrentState == CatapultState.ProjectileFlying)
                {
                    screenPosition.X = (playerCatapult.PumpkinPosition.X -
                                        playerCatapult.PumpkinLaunchPosition) * -1.0f;
                    endObjectPos.X = (playerCatapult.PumpkinPosition.X -
                                      playerCatapult.PumpkinLaunchPosition) * -1.0f + 1000;
                }

                //Calculate the pumpkin flying distance
                if (playerCatapult.CurrentState == CatapultState.ProjectileFlying ||
                    playerCatapult.CurrentState == CatapultState.ProjectileHit)
                {
                    PumpkinDistance = playerCatapult.PumpkinPosition.X -
                                      playerCatapult.PumpkinLaunchPosition;
                    PumpkinDistance /= 15.0f;
                }

                //Is this a highscore?
                if (HighScore < PumpkinDistance)
                {
                    HighScore = (int)PumpkinDistance;
                }
            }

            // Exit game
            if (!runGame)
            {
                Exit();
            }

            base.Update(gameTime);
        }