Example #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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here

            switch (gameState)
            {
            case GameStates.TitleScreen:
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    gameBoard.ClearBoard();
                    gameBoard.GenerateNewPieces(false);
                    playerScore = 0;
                    gameState   = GameStates.Playing;
                }
                break;

            case GameStates.Playing:
                timeSinceLastInput +=
                    (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (timeSinceLastInput >= MinTimeSinceLastInput)
                {
                    HandleMouseInput(Mouse.GetState());
                }

                gameBoard.ResetWater();

                for (int y = 0; y < GameBoard.GameBoardHeight; y++)
                {
                    CheckScoringChain(gameBoard.GetWaterChain(y));
                }

                gameBoard.GenerateNewPieces(true);

                break;
            }


            base.Update(gameTime);
        }
Example #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

            switch (gameState)
            {
            case GameStates.titleScreen:
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    gameBoard.ClearBoard();
                    gameBoard.GenerateNewPieces(false);
                    playerScore         = 0;
                    gameState           = GameStates.Playing;
                    currentLevel        = 0;
                    floodIncreaseAmount = 0.0f;
                    StartNewLevel();
                }
                break;

            case GameStates.Playing:
                timeSinceLastInput         += (float)gameTime.ElapsedGameTime.TotalSeconds;
                timeSinceLastFloodIncrease += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (timeSinceLastFloodIncrease >= timeBetweenFloodIncreases)
                {
                    floodCount += floodIncreaseAmount;
                    timeSinceLastFloodIncrease = 0.0f;
                    if (floodCount >= MaxFloodCounter)
                    {
                        gameOverTimer = 8.0f;
                        gameState     = GameStates.GameOver;
                    }
                }
                if (gameBoard.ArePiecesAnimating())
                {
                    gameBoard.UpdateAnimatedPieces();
                }
                else
                {
                    gameBoard.ResetWater();
                    for (int y = 0; y < GameBoard.GameBoardHeight; y++)
                    {
                        CheckScoringChain(gameBoard.GetWaterChain(y));
                    }
                    gameBoard.GenerateNewPieces(true);

                    if (timeSinceLastInput >= MinTimeSinceLastInput)
                    {
                        HandleMouseInput(Mouse.GetState());
                    }
                }
                UpdateScoreZoom();
                break;

            case GameStates.GameOver:
                gameOverTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (gameOverTimer <= 0)
                {
                    gameState = GameStates.titleScreen;
                }
                break;
            }

            base.Update(gameTime);
        }