-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighScoreDisplayLoop.cpp
More file actions
103 lines (80 loc) · 2.41 KB
/
HighScoreDisplayLoop.cpp
File metadata and controls
103 lines (80 loc) · 2.41 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <SFML/Graphics.hpp>
#include "MainGameFunctions.h"
#include "fileManager.h"
#include <iostream>
#include <string>
int highScoreDisplayLoop(sf::RenderWindow& window)
{
bool loopIsRunning = true;
float windowLength = 700;
int choice = 0;
setWindowView(window, windowLength);
HighScore hscore;
//changing background
/*sf::Texture texture;
texture.loadFromFile("images/back.png");
sf::Sprite sprite(texture);*/
sf::Texture texture;
texture.loadFromFile("images/BG_blurry.jpg");
sf::Sprite sprite(texture);
sf::Font font;
font.loadFromFile("text.otf");
// First text
sf::Text text1;
text1.setFont(font);
text1.setString("High score");
text1.setPosition(140, 90);
text1.setCharacterSize(55);
text1.setColor(sf::Color::White);
// Second text (centered)
sf::Text text2;
text2.setFont(font);
text2.setString(hscore.StringValue());
std::cout << hscore.StringValue() << std::endl;
// center the text
sf::FloatRect text2Bounds = text2.getLocalBounds();
text2.setPosition((windowLength - text2Bounds.width) / 2.0f, (windowLength - text2Bounds.height) / 2.0f);
text2.setCharacterSize(35);
text2.setColor(sf::Color::Black);
while (window.isOpen() && loopIsRunning)
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type==sf::Event::Closed)
{
window.close();
}
else if(event.type==sf::Event::Resized)
{
setWindowView(window, windowLength);
}
else if (event.type == sf::Event::KeyPressed)
{
int code = event.key.code;
resizeEvent(code, window, windowLength);
if(code == sf::Keyboard::Enter)
{
loopIsRunning = false;
}
if(code == sf::Keyboard::Down)
{
//choice++;
//if(choice==4) choice = 0;
}
if(code == sf::Keyboard::Up)
{
//choice--;
//if(choice==-1) choice = 3;
}
}
}
window.clear(sf::Color::White);
window.draw(sprite);
window.draw(text1);
window.draw(text2);
window.display();
}
return 0;
//having fun
}