finish score

This commit is contained in:
thatscringebro 2023-10-11 12:54:42 -04:00
parent 6948896d9f
commit 19d0b0e8e0
3 changed files with 34 additions and 1521284 deletions

View File

@ -166,7 +166,8 @@ void Game::run() {
window.draw(mapText); window.draw(mapText);
window.draw(racecar.getDrawable()); window.draw(racecar.getDrawable());
window.draw(speedText); window.draw(speedText);
displaySavedTimes();
if (lapPoints.size() == 3) { if (lapPoints.size() == 3) {
displayEndGame(); displayEndGame();
@ -174,9 +175,24 @@ void Game::run() {
else { else {
window.draw(timerText); window.draw(timerText);
} }
displaySavedTimes();
window.display(); window.display();
if (lapPoints.size() == 3) {
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
backgroundMusic.stop();
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter))
break;
}
break;
}
sf::sleep(sf::microseconds(DELAY)); sf::sleep(sf::microseconds(DELAY));
} }
} }
@ -187,9 +203,13 @@ bool Game::isTrackCollision(float x, float y) {
} else if (y <= 0) { } else if (y <= 0) {
return true; return true;
} else { } else {
int currX = (x / 13.85) - 1; int currX = (x / 13.85) - 1;
int currY = (y / 27.88) - 1; int currY = (y / 27.88) - 1;
char currentChar = asciiMap[currY * 194 + currX]; char currentChar;
if (currY * 194 + currX < 6478)
currentChar = asciiMap[currY * 194 + currX];
else
return true;
//std::cout << x << ", " << y << std::endl; //std::cout << x << ", " << y << std::endl;
if (currentChar == '\\' || currentChar == '|' || currentChar == '/' || currentChar == '-' || currentChar == '_') { if (currentChar == '\\' || currentChar == '|' || currentChar == '/' || currentChar == '-' || currentChar == '_') {
return true; return true;
@ -317,15 +337,15 @@ void Game::displayEndGame() {
} }
void Game::loadHighScores() { void Game::loadHighScores() {
std::ifstream file(highScoresFile); std::ifstream file(highScoresFile);
if (file.is_open()) { if (file.is_open()) {
int score; int score;
while (file >> score) { while (file >> score) {
highScores.push_back(score); highScores.push_back(score);
}
file.close();
} }
file.close();
} }
}
// Function to write high scores to a file // Function to write high scores to a file
void Game::writeHighScores() { void Game::writeHighScores() {

1521274
high_scores.txt

File diff suppressed because it is too large Load Diff

Binary file not shown.