-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScores.cpp
More file actions
executable file
·76 lines (66 loc) · 1.69 KB
/
Copy pathScores.cpp
File metadata and controls
executable file
·76 lines (66 loc) · 1.69 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
#include "Scores.h"
#include <SFML/Window/Mouse.hpp>
#include "Menu.h"
#include "Game.h"
#include <fstream>
#include <SFML/Window/Keyboard.hpp>
using namespace std;
Scores::Scores() {
t_music.openFromFile("Music/score.ogg");
t_music.setLoop(true);
t_music.play();
tex1.loadFromFile("Textures/backgroundscores.jpeg");
background.setTexture(tex1);
background.setScale(0.8,0.8);
background.setPosition(-250,1);
texbb.loadFromFile("Textures/buttonback.png");
buttonback.setTexture(texbb);
buttonback.setPosition(20,20);
buttonback.setScale(0.1,0.1);
f1.loadFromFile("Fonts/neuropolxrg.ttf");
tx1.setFont(f1);
tx1.setFillColor({255,255,255});
tx1.setCharacterSize(30);
tx2.setFont(f1);
tx2.setFillColor({255,255,255});
tx2.setCharacterSize(40);
tx2.setPosition(100,50);
tx2.setString("High scores");
loadscores();
}
void Scores::Update (Game & g, RenderWindow & win) {
Vector2f mouse = win.mapPixelToCoords(Mouse::getPosition(win));
FloatRect boundsback = buttonback.getGlobalBounds();
if(boundsback.contains(mouse)){
if(Mouse::isButtonPressed(Mouse::Left)){
t_music.stop();
g.SetScene(new Menu());
}
}
}
void Scores::Draw (RenderWindow & win) {
win.clear({0,0,0});
win.draw(background);
win.draw(tx2);
for(size_t i=0; i<v.size(); ++i){
win.draw(v[i]);}
win.draw(buttonback);
win.display();
}
void Scores::loadscores ( ) {
ifstream f("scoretxt.txt");
int aux;
vector<int> auxvect;
while(f>>aux){
auxvect.push_back(aux);
}
sort(auxvect.begin(),auxvect.end());
reverse(auxvect.begin(),auxvect.end());
for(size_t i=0;i<5;++i){
string auxs=to_string(auxvect[i]);
tx1.setString(auxs);
v.push_back(tx1);
v[i].setPosition(100,posinit);
posinit=posinit+30;
}
}