-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResultScreen.cpp
97 lines (85 loc) · 3.11 KB
/
ResultScreen.cpp
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
#include "ResultScreen.h"
#include "Menu.h"
#include "GameBase.h"
ResultScreen::ResultScreen(StateManager& stateManager, std::string songName, int accuracyBeatCount[3], int rawScore, int combo) : StateScreen(stateManager), songName(songName)
{
text.setFont(assetManager->getFont("game font"));
text.setFillColor(sf::Color::White);
if (2 * (accuracyBeatCount[0] + accuracyBeatCount[1] + accuracyBeatCount[2]) != 0)
accuracy = ((float)accuracyBeatCount[1] + 2.0 * (float)accuracyBeatCount[2]) * 100.0 / (2.0 * ((float)accuracyBeatCount[0] + (float)accuracyBeatCount[1] + (float)accuracyBeatCount[2])) ;
this->accuracyBeatCount[0] = accuracyBeatCount[0];
this->accuracyBeatCount[1] = accuracyBeatCount[1];
this->accuracyBeatCount[2] = accuracyBeatCount[2];
this->combo = combo;
this->rawScore = rawScore;
this->rawScore = rawScore;
this->adjustedScore = rawScore;
std::map<std::string, int> thresholds = GameSettings::getInstance()->getHighscores()->dropToBeatThreshold;
int threshold = thresholds.find(songName) != thresholds.end() ? thresholds.at(songName) : 1;
this->letterRanked = getRank(rawScore, threshold);
}
ResultScreen::~ResultScreen()
{
}
void ResultScreen::tick(const float & dt, sf::RenderWindow& window)
{
}
void ResultScreen::render(sf::RenderWindow& window)
{
using namespace std;
text.setFillColor(sf::Color::White);
text.setCharacterSize(60);
text.setPosition(200, 200);
text.setString("Accuracy: " + to_string(accuracy) + "%");
window.draw(text);
text.setPosition(200, 300);
text.setString("Miss/Too late: " + to_string(accuracyBeatCount[0]));
window.draw(text);
text.setPosition(200, 400);
text.setString("Almost: " + to_string(accuracyBeatCount[1]));
window.draw(text);
text.setPosition(200, 500);
text.setString("Hit: " + to_string(accuracyBeatCount[2]));
window.draw(text);
text.setPosition(200, 600);
text.setString("Combo: " + to_string(combo));
window.draw(text);
text.setCharacterSize(500);
text.setPosition(1200, 200);
text.setString(letterRanked);
window.draw(text);
text.setPosition(1000, 700);
text.setString("Score: " + to_string(adjustedScore));
text.setCharacterSize(150);
window.draw(text);
if (mouseInBox(window, 20, 20, 40, 40)) // back button
{
window.draw(assetManager->getDrawable("back button hl"));
}
else
{
window.draw(assetManager->getDrawable("back button"));
}
}
void ResultScreen::keyEvent(const float & dt, sf::Event event)
{
using namespace sf;
if (event.type != Event::KeyPressed) return;
switch (event.key.code)
{
case Keyboard::Key::Escape:
stateManager.addState(std::unique_ptr<StateScreen>(new Menu(stateManager)));
break;
case Keyboard::Key::R:
stateManager.addState(std::unique_ptr<StateScreen>(new DropToTheBeatGame(stateManager, fs::current_path().append("BeatMaps").append(songName).string())));
break;
}
}
void ResultScreen::mouseEvent(const float & dt, sf::RenderWindow& window, sf::Event event)
{
using namespace sf;
if (event.type == Event::MouseButtonPressed && event.mouseButton.button == Mouse::Left && mouseInBox(window, 20, 20, 40, 40)) // back button
{
stateManager.addState(std::unique_ptr<StateScreen>(new Menu(stateManager)));
}
}