Game Development Reference
In-Depth Information
This first method handles resetting the game to the original state. It clears out the
renderer and replaces all of the sprites while ensuring all bullets are in the available
pool for spawning when required. All enemies are destroyed as well to ensure they
spawn properly and the player can start from scratch. We reset the player to ensure
their his or her health is back to normal, and finally reset the score to zero using our
helper function that ensures the text display is up-to-date.
The counterpart to this method is the EndGame method, which handles clearing the
screen and displaying our simple Game Over screen.
void Game::EndGame()
{
auto renderer = Renderer::GetInstance();
renderer->ClearSprites();
renderer->ClearText();
if (_gameOverText == nullptr)
_gameOverText =
Renderer::GetInstance()->CreateText();
else
renderer->AddText(_gameOverText);
_gameOverText->Text = std::wstring(
L"Game Over\nTap anywhere to try
again\nFinal Score: ")
+ std::to_wstring(_playerScore);
auto size =
renderer->MeasureText(_gameOverText);
_gameOverText->Position.x =
(m_renderTargetSize.Width / 2) - (size.x /
2);
_gameOverText->Position.y =
(m_renderTargetSize.Height / 2) - (size.y /
2);
}
Here we clear everything from the renderer and create a new TextBlock that will
hold the message we want to display to the player. In this case we're simply inform-
Search WWH ::




Custom Search