Time for action – detecting hits
To detect hits, perform the following steps:
1. To the
TankBattlesGame
class' declarations area, add the following fields:float gameOverTimer = 0.0f; float gameOverDelay = 8.0f; float impactDistance = 2.5f;
2. In the
CreateUIElements()
method of theTankBattlesGame
class, create a new text block to hold the Game Over message when it should be displayed by adding the following to the end of the method:uiElements.Add("gameOverText", UIHelper.CreateTextblock("gameOverText", "", 220, 100));
3. Replace the current
case
GameState.GameOver
section of theUpdate()
method with:case GameState.GameOver: gameOverTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (gameOverTimer > gameOverDelay) { UIHelper.SetElementVisibility( "gameOverText", false, uiElements); gameState = GameState.TitleScreen; } break;
4. To the
CheckForShotImpacts()
method inside theif
statement and just before...