Added basic game over screen
This commit is contained in:
parent
a9d194c90c
commit
fb672c7ddb
@ -26,9 +26,13 @@ namespace snakeplusplus
|
|||||||
|
|
||||||
void GameEngine::GameLoop(void)
|
void GameEngine::GameLoop(void)
|
||||||
{
|
{
|
||||||
sf::Vector2f newHeadPosition;
|
|
||||||
while (graphics.IsOpen())
|
while (graphics.IsOpen())
|
||||||
{
|
{
|
||||||
|
if (isGameOver)
|
||||||
|
{
|
||||||
|
graphics.CheckContinue();
|
||||||
|
isGameOver = 0;
|
||||||
|
}
|
||||||
UpdatePlayerSpeed();
|
UpdatePlayerSpeed();
|
||||||
PlaceNewSnakePart(MovePlayer());
|
PlaceNewSnakePart(MovePlayer());
|
||||||
RegenerateFood();
|
RegenerateFood();
|
||||||
@ -36,6 +40,7 @@ namespace snakeplusplus
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Vector2f GameEngine::MovePlayer(void)
|
sf::Vector2f GameEngine::MovePlayer(void)
|
||||||
{
|
{
|
||||||
sf::Vector2f newHeadPosition;
|
sf::Vector2f newHeadPosition;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "playerinterface.hpp"
|
#include "playerinterface.hpp"
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace snakeplusplus
|
namespace snakeplusplus
|
||||||
@ -42,17 +43,17 @@ namespace snakeplusplus
|
|||||||
void PlayerOutput::CheckContinue(void)
|
void PlayerOutput::CheckContinue(void)
|
||||||
{
|
{
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
|
DisplayEndScreen();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
while (gameWindow.pollEvent(event))
|
gameWindow.pollEvent(event);
|
||||||
{
|
|
||||||
if ((event.type == sf::Event::Closed) ||
|
if ((event.type == sf::Event::Closed) ||
|
||||||
(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
|
(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
|
||||||
|
{
|
||||||
gameWindow.close();
|
gameWindow.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)) { return; }
|
||||||
return;
|
|
||||||
sf::sleep(delay);
|
sf::sleep(delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,17 +64,12 @@ namespace snakeplusplus
|
|||||||
sf::Vector2f textPosition(gameBoundaries);
|
sf::Vector2f textPosition(gameBoundaries);
|
||||||
textPosition.x = textPosition.x / 2;
|
textPosition.x = textPosition.x / 2;
|
||||||
textPosition.y = textPosition.y / 2;
|
textPosition.y = textPosition.y / 2;
|
||||||
sf::Text gameOverText;
|
sf::Font font;
|
||||||
gameOverText.setString("Game Over");
|
font.loadFromFile("Arial.ttf");
|
||||||
gameOverText.setCharacterSize(30);
|
sf::Text gameOverText("Game Over", font);
|
||||||
gameOverText.setPosition(textPosition);
|
gameOverText.setPosition(textPosition);
|
||||||
gameWindow.draw(gameOverText);
|
gameWindow.draw(gameOverText);
|
||||||
gameWindow.display();
|
gameWindow.display();
|
||||||
// if (!PlayerWantsToContinue())
|
|
||||||
// return;
|
|
||||||
// player = Snake();
|
|
||||||
// playerFood.GenerateNewFood(GetGameBoundaries());
|
|
||||||
// gameWindow.clear();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ namespace snakeplusplus
|
|||||||
int Food::GenerateRandomNumber(int generationLimit)
|
int Food::GenerateRandomNumber(int generationLimit)
|
||||||
{
|
{
|
||||||
int generatedNumber;
|
int generatedNumber;
|
||||||
std::uniform_int_distribution<> distribution(0, generationLimit);
|
std::uniform_int_distribution<> distribution(0, generationLimit - 1);
|
||||||
generatedNumber = distribution(generator);
|
generatedNumber = distribution(generator);
|
||||||
return generatedNumber;
|
return generatedNumber;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user