-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameOverScreen.cpp
55 lines (45 loc) · 1.34 KB
/
GameOverScreen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <SFML/Graphics.hpp>
#include <iostream>
#include <memory>
#include "Game.h"
#include "GameScreen.h"
#include "GameOverScreen.h"
#include "SettingScreen.h"
#include "stopwatch.h"
using namespace sfSnake;
extern Stopwatch sw;
GameOverScreen::GameOverScreen(std::size_t score) : score_(score)
{
float time = sw.getMicroseconds() / 1e6;
font_.loadFromFile("Fonts/game_over.ttf");
text_.setFont(font_);
text_.setString("Your score: " + std::to_string(score) + "!"
"\n\nUsing Time: " + std::to_string(time) + " s!"
"\n\nPress [SPACE] to retry"
"\n\nPress [ESC] to quit"
"\n\nPress [TAB] to setup");
text_.setFillColor(sf::Color::Red);
sf::FloatRect textBounds = text_.getLocalBounds();
text_.setOrigin(textBounds.left + textBounds.width / 2,
textBounds.top + textBounds.height / 2);
text_.setPosition(Game::Width / 2, Game::Height / 2);
}
void GameOverScreen::handleInput(sf::RenderWindow& window)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
sw.start();
Game::Screen = std::make_shared<GameScreen>();
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
window.close();
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Tab)) {
Game::Screen = std::make_shared<SettingScreen>();
}
}
void GameOverScreen::update(sf::Time delta)
{
}
void GameOverScreen::render(sf::RenderWindow& window)
{
window.draw(text_);
}