Added basic game over screen

This commit is contained in:
TriantaTV 2023-05-17 20:20:01 -05:00
parent a9d194c90c
commit fb672c7ddb
4 changed files with 17 additions and 16 deletions

BIN
Arial.ttf Normal file

Binary file not shown.

View File

@ -26,9 +26,13 @@ namespace snakeplusplus
void GameEngine::GameLoop(void)
{
sf::Vector2f newHeadPosition;
while (graphics.IsOpen())
{
if (isGameOver)
{
graphics.CheckContinue();
isGameOver = 0;
}
UpdatePlayerSpeed();
PlaceNewSnakePart(MovePlayer());
RegenerateFood();
@ -36,6 +40,7 @@ namespace snakeplusplus
}
return;
}
sf::Vector2f GameEngine::MovePlayer(void)
{
sf::Vector2f newHeadPosition;

View File

@ -1,5 +1,6 @@
#include "playerinterface.hpp"
#include <SFML/System/Vector2.hpp>
#include <cstdlib>
#include <iostream>
namespace snakeplusplus
@ -42,17 +43,17 @@ namespace snakeplusplus
void PlayerOutput::CheckContinue(void)
{
sf::Event event;
DisplayEndScreen();
while (true)
{
while (gameWindow.pollEvent(event))
gameWindow.pollEvent(event);
if ((event.type == sf::Event::Closed) ||
(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
{
if ((event.type == sf::Event::Closed) ||
(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
gameWindow.close();
gameWindow.close();
return;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter))
return;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)) { return; }
sf::sleep(delay);
}
}
@ -63,17 +64,12 @@ namespace snakeplusplus
sf::Vector2f textPosition(gameBoundaries);
textPosition.x = textPosition.x / 2;
textPosition.y = textPosition.y / 2;
sf::Text gameOverText;
gameOverText.setString("Game Over");
gameOverText.setCharacterSize(30);
sf::Font font;
font.loadFromFile("Arial.ttf");
sf::Text gameOverText("Game Over", font);
gameOverText.setPosition(textPosition);
gameWindow.draw(gameOverText);
gameWindow.display();
// if (!PlayerWantsToContinue())
// return;
// player = Snake();
// playerFood.GenerateNewFood(GetGameBoundaries());
// gameWindow.clear();
return;
}

View File

@ -30,7 +30,7 @@ namespace snakeplusplus
int Food::GenerateRandomNumber(int generationLimit)
{
int generatedNumber;
std::uniform_int_distribution<> distribution(0, generationLimit);
std::uniform_int_distribution<> distribution(0, generationLimit - 1);
generatedNumber = distribution(generator);
return generatedNumber;
}