This repository was archived by the owner on Sep 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameOverScreen.cpp
More file actions
85 lines (64 loc) · 2.26 KB
/
Copy pathGameOverScreen.cpp
File metadata and controls
85 lines (64 loc) · 2.26 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// Created by joseph on 4/17/17.
//
#include <iostream>
#include "GameOverScreen.h"
#include "Screens.h"
GameOverScreen::GameOverScreen() {
}
bool GameOverScreen::elapsedFrames(int frames) {
frameCounter++;
if (frameCounter >= frames) {
frameCounter = 0;
return true;
}
return false;
}
int GameOverScreen::run(sf::RenderWindow &window, sf::Texture &Texture, Options* gameOptions) {
if (!classicFont.loadFromFile("Resources/menu/8bit.ttf")) {
std::cerr << "Error loading 8bit.ttf" << std::endl;
return (-1);
}
sf::Text gameOverLabel;
gameOverLabel.setFont(classicFont);
gameOverLabel.setCharacterSize(200);
gameOverLabel.setString("GAME OVER");
sf::FloatRect textRect = gameOverLabel.getLocalBounds();
gameOverLabel.setOrigin(textRect.left + textRect.width/2.0f,
textRect.top + textRect.height/2.0f);
gameOverLabel.setPosition({window.getSize().x/2.f, window.getSize().y/2.f});
sf::Text continueLabel;
continueLabel.setFont(classicFont);
continueLabel.setCharacterSize(40);
continueLabel.setString("Presiona cualquier tecla para continuar");
sf::FloatRect continueLabelRect = continueLabel.getLocalBounds();
continueLabel.setOrigin(continueLabelRect.left + continueLabelRect.width/2.0f,
continueLabelRect.top + continueLabelRect.height/2.0f);
continueLabel.setPosition(window.getSize().x/2.f, window.getSize().y - 40.f);
while (running) {
while (window.pollEvent(event)) {
// Window closed
if (event.type == sf::Event::Closed) {
return (-1);
}
if (event.type == sf::Event::KeyPressed) {
return 0;
}
}
window.clear(bg);
if (elapsedFrames(55)) {
if (isWhite) {
continueLabel.setColor(bg);
isWhite = false;
} else {
continueLabel.setColor(sf::Color(255,255,255));
isWhite = true;
}
}
window.draw(gameOverLabel);
window.draw(continueLabel);
window.display();
}
//Never reaching this point normally, but just in case, exit the application
return (-1);
}