-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeaderBoard.cpp
More file actions
76 lines (58 loc) · 2.32 KB
/
LeaderBoard.cpp
File metadata and controls
76 lines (58 loc) · 2.32 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
//
// Created by viviane on 28/11/2021.
//
#include "LeaderBoard.h"
namespace menus{
LeaderBoard::LeaderBoard(){ }
LeaderBoard::~LeaderBoard(){ }
void LeaderBoard::run(){
renderMenu(LEADERBOARD_ITEMS);
showAllScores();
if (menu_counter > menu_speed) {
if (inputs->isKeyPressed(controls.enter)) {
switch (selectedItem) {
case 1:
setMenuState(st_global_menu, 0);
break;
}
menu_counter = 0;
}
}
menu_counter++;
}
void LeaderBoard::initialize(){
setBackground(assets->operator[]("menu"));
loadFont();
selectedItem = 1;
text[0].setFont(*assets->getFont("fontOne"));
text[0].setFillColor(sf::Color::White);
text[0].setString("Leaderboard");
text[0].setCharacterSize(150);
text[0].setPosition((WINDOW_WIDTH/2 - text[0].getGlobalBounds().width/2 ), -20);
text[1].setFont(*assets->getFont("fontThree"));
text[1].setFillColor(sf::Color::Red);
text[1].setString("Go to main menu");
text[1].setCharacterSize(40);
text[1].setPosition((WINDOW_WIDTH/2 - text[1].getGlobalBounds().width/2 ), WINDOW_HEIGHT - 70 - text[1].getGlobalBounds().height);
}
void LeaderBoard::showAllScores() {
int i;
int y_height = 170;
scoreBoard.readScores();
for (i = 0, scoreBoard.first(); !scoreBoard.ended() && i < 8; scoreBoard.next(), i++){
names[i].setFont(*assets->getFont("fontThree"));
names[i].setFillColor(sf::Color::White);
names[i].setString(scoreBoard.getCurrent().name);
names[i].setCharacterSize(40);
names[i].setPosition((WINDOW_WIDTH/6 ) - 60, y_height);
window->draw(names[i]);
scores[i].setFont(*assets->getFont("fontThree"));
scores[i].setFillColor(sf::Color::White);
scores[i].setString(std::to_string(scoreBoard.getCurrent().score));
scores[i].setCharacterSize(40);
scores[i].setPosition(WINDOW_WIDTH - (WINDOW_WIDTH/6) - scores[i].getGlobalBounds().width,y_height);
y_height += 20 + names[i].getGlobalBounds().height;
window->draw(scores[i]);
}
}
}