-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreState.cpp
More file actions
92 lines (81 loc) · 2.47 KB
/
ScoreState.cpp
File metadata and controls
92 lines (81 loc) · 2.47 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
#include "ScoreState.hpp"
//Private functions
void ScoreState::initFonts(){
if(!this->font.loadFromFile("../Fonts/shangri-la.ttf"))
std::cout<<"ERROR: FAILED TO LOAD FONT IN Score STATE!\n";
if(!this->scoreFont.loadFromFile("../Fonts/CaviarDreams.ttf"))
std::cout<<"ERROR: FAILED TO LOAD FONT IN ScorE STATE!\n";
if(!this->titleFont.loadFromFile("../Fonts/FFF_Tusj.ttf"))
std::cout<<"ERROR: FAILED TO LOAD FONT IN ScoRE STATE!\n";
}
void ScoreState::initButtons(){
this->exit= new Button(540, 650, 150, 50,
&this->font, "Main Menu",
sf::Color(100,100,100,200), sf::Color(150, 150, 150, 255), sf::Color(20, 20, 20, 200));
}
void ScoreState::initBackground(){
this->background.setSize(sf::Vector2f((float)this->window->getSize().x, (float)this->window->getSize().x));
if(!this->backgroundTexture.loadFromFile("Resources/Backgrounds/scores.jpg")){
std::cout<<"ERROR: FAILED TO LOAD BACKGROUND TEXTURE IN Gameover\n";
}
this->backgroundTexture.setSmooth(true);
this->background.setTexture(&this->backgroundTexture);
}
void ScoreState::initScoreTexts(){
std::ifstream input("highscores.txt");
int temp;
if(input.is_open()){
while(input >> temp){
sf::Text tempText;
tempText.setString(std::to_string(temp));
tempText.setFont(this->scoreFont);
tempText.setCharacterSize(56);
tempText.setPosition(600-tempText.getGlobalBounds().width/4, 250+this->counter);
this->counter+=80;
this->scoreTexts.push_back(tempText);
}
}
input.close();
}
void ScoreState::initTitle(){
this->title.setString("HIGH SCORES: ");
this->title.setFont(this->titleFont);
this->title.setCharacterSize(84);
this->title.setPosition(330,80);
}
//Constructors
ScoreState::ScoreState(sf::RenderWindow* window, std::stack<State*>* states) : State(window, states){
this->counter = 0;
this->initFonts();
this->initBackground();
this->initButtons();
this->initScoreTexts();
this->initTitle();
}
ScoreState::~ScoreState(){
delete this->exit;
}
//Accessors
//Functions
void ScoreState::renderScores(sf::RenderTarget* target){
for(auto i: this->scoreTexts){
target->draw(i);
}
}
void ScoreState::updateButtons(){
this->exit->update(this->mousePosView);
if(this->exit->isPressed())
this->endState();
}
void ScoreState::updateInput(){
}
void ScoreState::update(){
this->updateMousePositions();
this->updateButtons();
}
void ScoreState::render(sf::RenderTarget* target){
target->draw(this->background);
target->draw(this->title);
this->renderScores(target);
this->exit->render(target);
}