/// <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 (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()); } } break; } base.Update(gameTime); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } switch (gameState) { case GameStates.TitleScreen: if (Keyboard.GetState().IsKeyDown(Keys.Space)) { gameBoard.ClearBoard(); gameBoard.GenerateNewPieces(false); playerScore = 0; currentLevel = 0; StartNewLevel(); floodIncreaseAmount = 2.0f; gameState = GameStates.Playing; } break; case GameStates.Playing: timeSinceLastFloodIncrease += (float)gameTime.ElapsedGameTime.TotalSeconds; if (timeSinceLastFloodIncrease >= timeBetweenFloodIncreases) { floodCount += floodIncreaseAmount; timeSinceLastFloodIncrease = 0.0f; if (floodCount >= MaxFloodCounter || currentLevel == 5) { if (floodCount >= MaxFloodCounter) { complete = false; } else { complete = true; } gameOverTimer = 3.0f; gameState = GameStates.GameEnd; } } timeSinceLastInput += (float)gameTime.ElapsedGameTime.TotalSeconds; if (gameBoard.ArePiecesAnimating()) { gameBoard.UpdateAnimatedPieces(); } else { gameBoard.ResetWater(); gameBoard.ResetWater(); for (int y = 0; y < GameBoard.GameBoardHeight; y++) { CheckScoringChain(gameBoard.GetWaterChain(y)); } gameBoard.GenerateNewPieces(true); if (timeSinceLastInput >= MinTimeSinceLastInput) { HandleMouseInput(Mouse.GetState()); } } UpdateScoreZooms(); break; case GameStates.GameEnd: gameOverTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (gameOverTimer <= 0) { gameState = GameStates.TitleScreen; } break; } base.Update(gameTime); }
/// <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 switch (gameState) { case GameStates.TitleScreen: if (Keyboard.GetState().IsKeyDown(Keys.Space)) { gameBoard.ClearBoard(); gameBoard.GenerateNewPieces(false); playerScore = 0; currentLevel = 0; floodIncreaseAmount = 0.0f; StartNewLevel(); gameState = GameStates.Playing; } 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()); } } UpdateScoreZooms(); break; case GameStates.GameOver: gameOverTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (gameOverTimer <= 0) { gameState = GameStates.TitleScreen; } break; } base.Update(gameTime); }